[PATCH] D158920: Delete CloudABI support

2023-08-25 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

Also..

  # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-cloudabi %s -o %t.o
  ./lld/test/ELF/aarch64-got-relocations.s
  // RUN: llvm-mc -filetype=obj -triple=i686-unknown-cloudabi %s -o %t.o
  ./lld/test/ELF/static-with-export-dynamic.s
  # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-cloudabi %s -o %t1.o
  ./lld/test/ELF/x86-64-tls-pie.s

The only run lines in these tests are CloudABI targets and that triple is going 
away.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158920

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


[PATCH] D158920: Delete CloudABI support

2023-08-25 Thread Brad Smith via Phabricator via cfe-commits
brad updated this revision to Diff 553705.
brad added a comment.

Missed BUILD.gn, a unit test and one or two other files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158920

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CloudABI.cpp
  clang/lib/Driver/ToolChains/CloudABI.h
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Lex/InitHeaderSearch.cpp
  clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
  clang/test/Analysis/security-syntax-checks.m
  clang/test/Driver/cloudabi.c
  clang/test/Driver/cloudabi.cpp
  clang/test/Driver/frame-pointer-elim.c
  clang/test/Driver/fsanitize.c
  clang/test/Frontend/gnu-mcount.c
  clang/test/Preprocessor/init-arm.c
  clang/test/Preprocessor/init-x86.c
  clang/test/Preprocessor/predefined-macros-no-warnings.c
  llvm/include/llvm/MC/MCELFObjectWriter.h
  llvm/include/llvm/TargetParser/Triple.h
  llvm/lib/TargetParser/Triple.cpp
  llvm/unittests/TargetParser/TripleTest.cpp
  llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn
@@ -64,7 +64,6 @@
 "ToolChains/BareMetal.cpp",
 "ToolChains/CSKYToolChain.cpp",
 "ToolChains/Clang.cpp",
-"ToolChains/CloudABI.cpp",
 "ToolChains/CommonArgs.cpp",
 "ToolChains/CrossWindows.cpp",
 "ToolChains/Cuda.cpp",
Index: llvm/unittests/TargetParser/TripleTest.cpp
===
--- llvm/unittests/TargetParser/TripleTest.cpp
+++ llvm/unittests/TargetParser/TripleTest.cpp
@@ -325,12 +325,6 @@
   EXPECT_EQ(Triple::Ananas, T.getOS());
   EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
 
-  T = Triple("x86_64-unknown-cloudabi");
-  EXPECT_EQ(Triple::x86_64, T.getArch());
-  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
-  EXPECT_EQ(Triple::CloudABI, T.getOS());
-  EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
-
   T = Triple("x86_64-unknown-fuchsia");
   EXPECT_EQ(Triple::x86_64, T.getArch());
   EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
Index: llvm/lib/TargetParser/Triple.cpp
===
--- llvm/lib/TargetParser/Triple.cpp
+++ llvm/lib/TargetParser/Triple.cpp
@@ -209,7 +209,6 @@
   case AMDPAL: return "amdpal";
   case Ananas: return "ananas";
   case CUDA: return "cuda";
-  case CloudABI: return "cloudabi";
   case Darwin: return "darwin";
   case DragonFly: return "dragonfly";
   case DriverKit: return "driverkit";
@@ -572,7 +571,6 @@
 static Triple::OSType parseOS(StringRef OSName) {
   return StringSwitch(OSName)
 .StartsWith("ananas", Triple::Ananas)
-.StartsWith("cloudabi", Triple::CloudABI)
 .StartsWith("darwin", Triple::Darwin)
 .StartsWith("dragonfly", Triple::DragonFly)
 .StartsWith("freebsd", Triple::FreeBSD)
Index: llvm/include/llvm/TargetParser/Triple.h
===
--- llvm/include/llvm/TargetParser/Triple.h
+++ llvm/include/llvm/TargetParser/Triple.h
@@ -185,7 +185,6 @@
 UnknownOS,
 
 Ananas,
-CloudABI,
 Darwin,
 DragonFly,
 FreeBSD,
Index: llvm/include/llvm/MC/MCELFObjectWriter.h
===
--- llvm/include/llvm/MC/MCELFObjectWriter.h
+++ llvm/include/llvm/MC/MCELFObjectWriter.h
@@ -71,8 +71,6 @@
 
   static uint8_t getOSABI(Triple::OSType OSType) {
 switch (OSType) {
-  case Triple::CloudABI:
-return ELF::ELFOSABI_CLOUDABI;
   case Triple::HermitCore:
 return ELF::ELFOSABI_STANDALONE;
   case Triple::PS4:
Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- clang/test/Preprocessor/predefined-macros-no-warnings.c
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -10,7 +10,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_32-darwin
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-darwin
-// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-cloudabi
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-freebsd
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-fuchsia
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-linux
@@ -26,7 +25,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-netbsd
 // RUN: %clang_cc1 %s -Eonly -Wsystem-heade

[PATCH] D158858: [analyzer] MPIChecker: add defensive checking (check against nullptr)

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

Thanks. Feel free to merge this (before any of the others).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158858

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


[PATCH] D158562: [clang][Sema] Add truncation warning on fortified snprintf

2023-08-25 Thread Takuya Shimizu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0c9c9dd9a24f: [clang][Sema] Add truncation warning on 
fortified snprintf (authored by hazohelet).

Changed prior to commit:
  https://reviews.llvm.org/D158562?vs=553246&id=553702#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158562

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Analysis/taint-generic.c
  clang/test/Sema/format-strings.c
  clang/test/Sema/warn-fortify-source.c

Index: clang/test/Sema/warn-fortify-source.c
===
--- clang/test/Sema/warn-fortify-source.c
+++ clang/test/Sema/warn-fortify-source.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_BUILTINS
 // RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify
 // RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_BUILTINS
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -Wno-fortify-source %s -verify=nofortify
+// RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 -Wno-fortify-source %s -verify=nofortify
 
 typedef unsigned long size_t;
 
@@ -83,10 +85,17 @@
   __builtin_memset(buf, 0xff, 11); // expected-warning {{'memset' will always overflow; destination buffer has size 10, but size argument is 11}}
 }
 
-void call_snprintf(void) {
+void call_snprintf(double d) {
   char buf[10];
   __builtin_snprintf(buf, 10, "merp");
   __builtin_snprintf(buf, 11, "merp"); // expected-warning {{'snprintf' size argument is too large; destination buffer has size 10, but size argument is 11}}
+  __builtin_snprintf(buf, 0, "merp");
+  __builtin_snprintf(buf, 3, "merp"); // expected-warning {{'snprintf' will always be truncated; specified size is 3, but format string expands to at least 5}}
+  __builtin_snprintf(buf, 4, "merp"); // expected-warning {{'snprintf' will always be truncated; specified size is 4, but format string expands to at least 5}}
+  __builtin_snprintf(buf, 5, "merp");
+  __builtin_snprintf(buf, 1, "%.1000g", d); // expected-warning {{'snprintf' will always be truncated; specified size is 1, but format string expands to at least 2}}
+  __builtin_snprintf(buf, 5, "%.1000g", d);
+  __builtin_snprintf(buf, 5, "%.1000G", d);
 }
 
 void call_vsnprintf(void) {
@@ -94,14 +103,23 @@
   __builtin_va_list list;
   __builtin_vsnprintf(buf, 10, "merp", list);
   __builtin_vsnprintf(buf, 11, "merp", list); // expected-warning {{'vsnprintf' size argument is too large; destination buffer has size 10, but size argument is 11}}
+  __builtin_vsnprintf(buf, 0, "merp", list);
+  __builtin_vsnprintf(buf, 3, "merp", list); // expected-warning {{'vsnprintf' will always be truncated; specified size is 3, but format string expands to at least 5}}
+  __builtin_vsnprintf(buf, 4, "merp", list); // expected-warning {{'vsnprintf' will always be truncated; specified size is 4, but format string expands to at least 5}}
+  __builtin_vsnprintf(buf, 5, "merp", list);
+  __builtin_vsnprintf(buf, 1, "%.1000g", list); // expected-warning {{'vsnprintf' will always be truncated; specified size is 1, but format string expands to at least 2}}
+  __builtin_vsnprintf(buf, 5, "%.1000g", list);
+  __builtin_vsnprintf(buf, 5, "%.1000G", list);
 }
 
 void call_sprintf_chk(char *buf) {
   __builtin___sprintf_chk(buf, 1, 6, "hell\n");
   __builtin___sprintf_chk(buf, 1, 5, "hell\n"); // expected-warning {{'sprintf' will always overflow; destination buffer has size 5, but format string expands to at least 6}}
-  __builtin___sprintf_chk(buf, 1, 6, "hell\0 boy"); // expected-warning {{format string contains '\0' within the string body}}
-  __builtin___sprintf_chk(buf, 1, 2, "hell\0 boy"); // expected-warning {{format string contains '\0' within the string body}}
-  // expected-warning@-1 {{'sprintf' will always overflow; destination buffer has size 2, but format string expands to at least 5}}
+  __builtin___sprintf_chk(buf, 1, 6, "hell\0 boy"); // expected-warning {{format string contains '\0' within the string body}} \
+// nofortify-warning {{format string contains '\0' within the string body}}
+  __builtin___sprintf_chk(buf, 1, 2, "hell\0 boy"); // expected-warning {{format string contains '\0' within the string body}} \
+// nofortify-warning {{format string contains '\0' within the string body}}
+  // expected-warning@-2 {{'sprintf' will always overflow; destination buffer has size 2, but format string expands to at least 5}}
   __builtin___sprintf_chk(buf, 1, 6, "hello");
   __builtin___sprintf_chk(buf, 1, 5, "hello"); // expected-warning {{'sprintf' will always overflow; destination buffer has size 5, but format string expands to at least 6}}
   __builtin___sprintf_ch

[clang] 0c9c9dd - [clang][Sema] Add truncation warning on fortified snprintf

2023-08-25 Thread Takuya Shimizu via cfe-commits

Author: Takuya Shimizu
Date: 2023-08-26T14:41:05+09:00
New Revision: 0c9c9dd9a24f9d715d950fef0ac7aae01437af96

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

LOG: [clang][Sema] Add truncation warning on fortified snprintf

This patch warns on snprintf calls whose n argument is known to be smaller than 
the size of the formatted string like

```
char buf[5];
snprintf(buf, 5, "Hello");
```
This is a counterpart of gcc's Wformat-truncation
Fixes https://github.com/llvm/llvm-project/issues/64871

Reviewed By: aaron.ballman, nickdesaulniers
Differential Revision: https://reviews.llvm.org/D158562

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
clang/test/Analysis/taint-generic.c
clang/test/Sema/format-strings.c
clang/test/Sema/warn-fortify-source.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0fff49c2c5108a..1ba4215e603349 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -150,6 +150,11 @@ Improvements to Clang's diagnostics
 - Clang constexpr evaluator now diagnoses compound assignment operators against
   uninitialized variables as a read of uninitialized object.
   (`#51536 _`)
+- Clang's ``-Wfortify-source`` now diagnoses ``snprintf`` call that is known to
+  result in string truncation.
+  (`#64871: `_).
+  Also clang no longer emits false positive warnings about the output length of
+  ``%g`` format specifier.
 
 Bug Fixes in This Version
 -

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index cf6f422ee47167..7f0cfb29cddeac 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -857,6 +857,11 @@ def warn_fortify_source_format_overflow : Warning<
   " but format string expands to at least %2">,
   InGroup;
 
+def warn_fortify_source_format_truncation: Warning<
+  "'%0' will always be truncated; specified size is %1,"
+  " but format string expands to at least %2">,
+  InGroup;
+
 def warn_fortify_scanf_overflow : Warning<
   "'%0' may overflow; destination buffer in argument %1 has size "
   "%2, but the corresponding specifier may require size %3">,

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index e3b4d151536528..c78a6b9c510767 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -888,9 +888,12 @@ class EstimateSizeFormatHandler
   break;
 
 // %g style conversion switches between %f or %e style dynamically.
-// %f always takes less space, so default to it.
+// %g removes trailing zeros, and does not print decimal point if there are
+// no digits that follow it. Thus %g can print a single digit.
 case analyze_format_string::ConversionSpecifier::gArg:
 case analyze_format_string::ConversionSpecifier::GArg:
+  Size += 1;
+  break;
 
 // Floating point number in the form '[+]ddd.ddd'.
 case analyze_format_string::ConversionSpecifier::fArg:
@@ -1032,6 +1035,23 @@ class EstimateSizeFormatHandler
 
 } // namespace
 
+static bool ProcessFormatStringLiteral(const Expr *FormatExpr,
+   StringRef &FormatStrRef, size_t &StrLen,
+   ASTContext &Context) {
+  if (const auto *Format = dyn_cast(FormatExpr);
+  Format && (Format->isOrdinary() || Format->isUTF8())) {
+FormatStrRef = Format->getString();
+const ConstantArrayType *T =
+Context.getAsConstantArrayType(Format->getType());
+assert(T && "String literal not of constant array type!");
+size_t TypeSize = T->getSize().getZExtValue();
+// In case there's a null byte somewhere.
+StrLen = std::min(std::max(TypeSize, size_t(1)) - 1, FormatStrRef.find(0));
+return true;
+  }
+  return false;
+}
+
 void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
CallExpr *TheCall) {
   if (TheCall->isValueDependent() || TheCall->isTypeDependent() ||
@@ -1183,11 +1203,9 @@ void 
Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
 const auto *FormatExpr =
 TheCall->getArg(FormatIndex)->IgnoreParenImpCasts();
 
-const auto *Format = dyn_cast(FormatExpr);
-if (!Format)
-  return;
-
-if (!Format->isOrdinary() && !Format->isUTF8())
+StringRef FormatStrRef;
+size_t StrLen;
+if (!ProcessFormatStringLiteral(FormatExpr, FormatStrRef, StrLen, Context))
   return;
 
 auto Diagnose = [&](unsigned Ar

[PATCH] D157572: [clang] Add `[[clang::library_extension]]` attribute

2023-08-25 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

In D157572#4617504 , @aaron.ballman 
wrote:

> In D157572#4614561 , @cjdb wrote:
>
>> In D157572#4613622 , 
>> @aaron.ballman wrote:
>>
>>> In D157572#4612141 , @cjdb wrote:
>>>
 I don't dislike it, but I am a bit concerned about misuse being noisy.
>>>
>>> So you're concerned that a library author uses `diagnose_if` to add a 
>>> diagnostic to a warning group that makes the diagnostic seem too chatty, so 
>>> the user disables the group and loses the compiler's diagnostics? Or are 
>>> there other kinds of misuse you're worried about?
>>
>> More or less the former. I don't know if it'll actually manifest in practice 
>> though, I don't see many `diagnose_if` diagnostics to begin with.
>
> I think the former is sort of a "doctor, doctor, it hurts" situation; the 
> issue isn't really with `diagnose_if`, it's with the library author's use of 
> it. But at the same time, I can see why it would be beneficial to be able to 
> work around it if needed.
>
 As much as I hate suppressing diagnostics, I think there needs to be a way 
 to suppress the `diagnose_if` forms of warning without suppressing 
 something that the compiler would otherwise generate. Something like:

 - `-Wno-deprecated`: suppresses anything that `-Wdeprecated` would turn on.
 - `-Wno-deprecated=diagnose_if`: just the ones flagged by `diagnose_if`.
 - `-Wno-deprecated=non-diagnose_if`: complement to #2.

 (and similarly for `-Wno-error=`.)

 I'm not sure about the system header knob though: `[[deprecated]]` and 
 `[[nodiscard]]` still show up even when the declaration is in a system 
 header?
>>>
>>> Correct, those will still show up when the declaration is in a system 
>>> header but not when the use is in a system header: 
>>> https://godbolt.org/z/PjqKbGsrr
>>
>> Right, my question was more "what is this knob doing?"
>
> Ah! We have various knobs on our diagnostics, like:
> `ShowInSystemHeader` -- 
> https://github.com/llvm/llvm-project/blob/2dc6281b98d07f43a64d0ef34405d9a12d59e8b6/clang/include/clang/Basic/DiagnosticSemaKinds.td#L7818
>  (if used, the diagnostic will be shown in a system header)
> `SFINAEFailure` -- 
> https://github.com/llvm/llvm-project/blob/2dc6281b98d07f43a64d0ef34405d9a12d59e8b6/clang/include/clang/Basic/DiagnosticSemaKinds.td#L93
>  (if used, the diagnostic causes SFINAE to fail in a SFINAE context)
> `DefaultIgnore` -- 
> https://github.com/llvm/llvm-project/blob/2dc6281b98d07f43a64d0ef34405d9a12d59e8b6/clang/include/clang/Basic/DiagnosticSemaKinds.td#L141
>  (if used, the warning is off by default and must be explicitly enabled via 
> its group)
> `DefaultError` -- 
> https://github.com/llvm/llvm-project/blob/2dc6281b98d07f43a64d0ef34405d9a12d59e8b6/clang/include/clang/Basic/DiagnosticSemaKinds.td#L262
>  (if used, the warning defaults to being an error but users can disable the 
> error with `-Wno`)
> (etc)
>
> All of these have been of use to us as implementers, so it seems likely that 
> these same knobs would be of use to library authors adding their own compiler 
> diagnostics, so perhaps we should consider that as part of the design?
>
>>> We currently have `-Wuser-defined-warnings` as the warning group for 
>>> `diagnose_if` warning diagnostics, so I wonder if it would make sense to 
>>> allow `-Wno-deprecated` suppresses anything that `-Wdeprecated` would turn 
>>> on, while `-Wdeprecated -Wno-user-defined-warnings` would turn on only the 
>>> compiler-generated deprecation warnings and not the diagnose_if-generated 
>>> ones?
>>
>> Oh neat, this simplifies things a lot!
>
> I think it could make for a reasonable user experience.
>
> I'm curious what @erichkeane thinks as attributes code owner, but personally, 
> I like the idea of extending `diagnose_if` over the idea of adding 
> `clang::library_extension` because it's a more general solution that I think 
> will give more utility to our users. However, I also want to know if @philnik 
> @Mordante @ldionne (and others) share that preference because I think they're 
> going to be the guinea pigs^W^Wearly adopters of this functionality.

I think this approach makes a lot of sense. I'm not sure all the knobs make 
sense to expose (e.g. `SFINAEFailure` could just be implemented with a normal 
`enable_if` IIUC), but at least `ShowInSystemHeader` and `DefaultIgnore` are 
ones where I already have use-cases in mind. As said before, we could also move 
our `atomic` ordering warnings from `-Wuser-defined-warnings` to 
`-Watomic-memory-ordering`, which seems like a huge usability improvement. I'm 
sure there will be more use-cases in the future for extending warning flags and 
having the ability to tune how and when warnings are emitted.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://review

[PATCH] D158811: [X86] __builtin_cpu_supports: support x86-64{,-v2,-v3,-v4}

2023-08-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: llvm/lib/TargetParser/X86TargetParser.cpp:718
 ;
-FeaturesMask |= (1ULL << Feature);
+FeatureMask[Feature / 32] |= 1U << (Feature % 32);
   }

pengfei wrote:
> Should we use vector for future expansion, or add an assert to make sure it 
> won't exceed current limitation?
A resizable vector does not simplify code here. I've added an assert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158811

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


[PATCH] D158811: [X86] __builtin_cpu_supports: support x86-64{,-v2,-v3,-v4}

2023-08-25 Thread Fangrui Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG27da15381cbe: [X86] __builtin_cpu_supports: support 
x86-64{,-v2,-v3,-v4} (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158811

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/builtin-cpu-supports.c
  clang/test/Sema/builtin-cpu-supports.c
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/TargetParser/X86TargetParser.cpp

Index: llvm/lib/TargetParser/X86TargetParser.cpp
===
--- llvm/lib/TargetParser/X86TargetParser.cpp
+++ llvm/lib/TargetParser/X86TargetParser.cpp
@@ -703,18 +703,22 @@
   return I != std::end(Processors);
 }
 
-uint64_t llvm::X86::getCpuSupportsMask(ArrayRef FeatureStrs) {
+std::array
+llvm::X86::getCpuSupportsMask(ArrayRef FeatureStrs) {
   // Processor features and mapping to processor feature value.
-  uint64_t FeaturesMask = 0;
-  for (const StringRef &FeatureStr : FeatureStrs) {
+  std::array FeatureMask{};
+  for (StringRef FeatureStr : FeatureStrs) {
 unsigned Feature = StringSwitch(FeatureStr)
 #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY)\
   .Case(STR, llvm::X86::FEATURE_##ENUM)
+#define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY)   \
+  .Case(STR, llvm::X86::FEATURE_##ENUM)
 #include "llvm/TargetParser/X86TargetParser.def"
 ;
-FeaturesMask |= (1ULL << Feature);
+assert(Feature / 32 < FeatureMask.size());
+FeatureMask[Feature / 32] |= 1U << (Feature % 32);
   }
-  return FeaturesMask;
+  return FeatureMask;
 }
 
 unsigned llvm::X86::getFeaturePriority(ProcessorFeatures Feat) {
Index: llvm/include/llvm/TargetParser/X86TargetParser.h
===
--- llvm/include/llvm/TargetParser/X86TargetParser.h
+++ llvm/include/llvm/TargetParser/X86TargetParser.h
@@ -15,6 +15,7 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringMap.h"
+#include 
 
 namespace llvm {
 template  class SmallVectorImpl;
@@ -57,7 +58,10 @@
 enum ProcessorFeatures {
 #define X86_FEATURE(ENUM, STRING) FEATURE_##ENUM,
 #include "llvm/TargetParser/X86TargetParser.def"
-  CPU_FEATURE_MAX
+  CPU_FEATURE_MAX,
+
+#define X86_MICROARCH_LEVEL(ENUM, STRING, PRIORITY) FEATURE_##ENUM = PRIORITY,
+#include "llvm/TargetParser/X86TargetParser.def"
 };
 
 enum CPUKind {
@@ -171,7 +175,7 @@
 
 char getCPUDispatchMangling(StringRef Name);
 bool validateCPUSpecificCPUDispatch(StringRef Name);
-uint64_t getCpuSupportsMask(ArrayRef FeatureStrs);
+std::array getCpuSupportsMask(ArrayRef FeatureStrs);
 unsigned getFeaturePriority(ProcessorFeatures Feat);
 
 } // namespace X86
Index: llvm/include/llvm/TargetParser/X86TargetParser.def
===
--- llvm/include/llvm/TargetParser/X86TargetParser.def
+++ llvm/include/llvm/TargetParser/X86TargetParser.def
@@ -128,6 +128,10 @@
 #define X86_FEATURE(ENUM, STR)
 #endif
 
+#ifndef X86_MICROARCH_LEVEL
+#define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY)
+#endif
+
 X86_FEATURE_COMPAT(CMOV,"cmov",  0)
 X86_FEATURE_COMPAT(MMX, "mmx",   1)
 X86_FEATURE_COMPAT(POPCNT,  "popcnt",9)
@@ -242,5 +246,11 @@
 X86_FEATURE   (RETPOLINE_INDIRECT_CALLS,"retpoline-indirect-calls")
 X86_FEATURE   (LVI_CFI, "lvi-cfi")
 X86_FEATURE   (LVI_LOAD_HARDENING,  "lvi-load-hardening")
+
+X86_MICROARCH_LEVEL(X86_64_BASELINE,"x86-64",   95)
+X86_MICROARCH_LEVEL(X86_64_V2,  "x86-64-v2",96)
+X86_MICROARCH_LEVEL(X86_64_V3,  "x86-64-v3",97)
+X86_MICROARCH_LEVEL(X86_64_V4,  "x86-64-v4",98)
 #undef X86_FEATURE_COMPAT
 #undef X86_FEATURE
+#undef X86_MICROARCH_LEVEL
Index: clang/test/Sema/builtin-cpu-supports.c
===
--- clang/test/Sema/builtin-cpu-supports.c
+++ clang/test/Sema/builtin-cpu-supports.c
@@ -20,6 +20,12 @@
   (void)__builtin_cpu_is("x86-64-v2"); // expected-error {{invalid cpu name for builtin}}
   (void)__builtin_cpu_is("x86-64-v3"); // expected-error {{invalid cpu name for builtin}}
   (void)__builtin_cpu_is("x86-64-v4"); // expected-error {{invalid cpu name for builtin}}
+
+  (void)__builtin_cpu_supports("x86-64");
+  (void)__builtin_cpu_supports("x86-64-v2");
+  (void)__builtin_cpu_supports("x86-64-v3");
+  (void)__builtin_cpu_supports("x86-64-v4");
+  (void)__builtin_cpu_supports("x86-64-v5"); // expected-error {{invalid cpu feature string for builtin}}
 #else
   if (__built

[clang] 27da153 - [X86] __builtin_cpu_supports: support x86-64{, -v2, -v3, -v4}

2023-08-25 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-08-25T20:56:25-07:00
New Revision: 27da15381cbe2ac6fd1319f6409dbbab9a857b7b

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

LOG: [X86] __builtin_cpu_supports: support x86-64{,-v2,-v3,-v4}

GCC 12 (https://gcc.gnu.org/PR101696) allows
__builtin_cpu_supports("x86-64") (and -v2 -v3 -v4).
This patch ports the feature.

* Add `FEATURE_X86_64_{BASELINE,V2,V3,V4}` to enum ProcessorFeatures,
  but keep CPU_FEATURE_MAX unchanged to make
  FeatureInfos/FeatureInfos_WithPLUS happy.
* Change validateCpuSupports to allow `x86-64{,-v2,-v3,-v4}`
* Change getCpuSupportsMask to return `std::array` where
  `x86-64{,-v2,-v3,-v4}` set bits `FEATURE_X86_64_{BASELINE,V2,V3,V4}`.
* `target("x86-64")` and `cpu_dispatch(x86_64)` are invalid. Tested by commit 
9de3b35ac9159d5bae6e6796cb91e4f877a07189

Close https://github.com/llvm/llvm-project/issues/59961

Reviewed By: pengfei

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

Added: 


Modified: 
clang/lib/Basic/Targets/X86.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/builtin-cpu-supports.c
clang/test/Sema/builtin-cpu-supports.c
llvm/include/llvm/TargetParser/X86TargetParser.def
llvm/include/llvm/TargetParser/X86TargetParser.h
llvm/lib/TargetParser/X86TargetParser.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index e18b459c0f51eb..9c464a3afdf767 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -1170,6 +1170,7 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
 bool X86TargetInfo::validateCpuSupports(StringRef FeatureStr) const {
   return llvm::StringSwitch(FeatureStr)
 #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) .Case(STR, true)
+#define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY) .Case(STR, true)
 #include "llvm/TargetParser/X86TargetParser.def"
   .Default(false);
 }

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 25e1b36d05fd97..daa4b095eaa8ae 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -13325,9 +13325,7 @@ Value *CodeGenFunction::EmitX86CpuSupports(const 
CallExpr *E) {
 }
 
 Value *CodeGenFunction::EmitX86CpuSupports(ArrayRef FeatureStrs) {
-  uint64_t Mask = llvm::X86::getCpuSupportsMask(FeatureStrs);
-  std::array FeatureMask{Lo_32(Mask), Hi_32(Mask), 0, 0};
-  return EmitX86CpuSupports(FeatureMask);
+  return EmitX86CpuSupports(llvm::X86::getCpuSupportsMask(FeatureStrs));
 }
 
 llvm::Value *

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 7b456edf5a3623..bf83171e2c6814 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2683,24 +2683,12 @@ llvm::Value *CodeGenFunction::FormX86ResolverCondition(
 
   if (!RO.Conditions.Architecture.empty()) {
 StringRef Arch = RO.Conditions.Architecture;
-std::array Mask{};
-// If arch= specifies an x86-64 micro-architecture level, test a special
-// feature named FEATURE_X86_64_*, otherwise we use __builtin_cpu_is.
-if (Arch.consume_front("x86-64")) {
-  if (Arch.empty()) // FEATURE_X86_64_BASELINE 95=2*32+31
-Mask[2] = 1u << 31;
-  else if (Arch == "-v2") // FEATURE_X86_64_V2 96==3*32+0
-Mask[3] = 1u << 0;
-  else if (Arch == "-v3") // FEATURE_X86_64_V3 97==3*32+1
-Mask[3] = 1u << 1;
-  else if (Arch == "-v4") // FEATURE_X86_64_V3 98==3*32+2
-Mask[3] = 1u << 2;
-  else
-llvm_unreachable("invalid x86-64 micro-architecture level");
-  Condition = EmitX86CpuSupports(Mask);
-} else {
+// If arch= specifies an x86-64 micro-architecture level, test the feature
+// with __builtin_cpu_supports, otherwise use __builtin_cpu_is.
+if (Arch.starts_with("x86-64"))
+  Condition = EmitX86CpuSupports({Arch});
+else
   Condition = EmitX86CpuIs(Arch);
-}
   }
 
   if (!RO.Conditions.Features.empty()) {

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index b1e5c9fc96faa5..9b241165b7c579 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4168,8 +4168,9 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl 
GD) {
   // always run on at least a 'pentium'). We do this by deleting the 'least
   // advanced' (read, lowest mangling letter).
   while (Options.size() > 1 &&
- llvm::X86::getCpuSupportsMask(
- (Options.end() - 2)->Conditions.Features) == 0) {
+ llvm::all_of(llvm::X86::getCpuSupportsMask(
+  (Options.end() - 2)->Conditions.Features),

[PATCH] D158811: [X86] __builtin_cpu_supports: support x86-64{,-v2,-v3,-v4}

2023-08-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 553698.
MaskRay edited the summary of this revision.
MaskRay added a comment.

rebase after precommitting `target("x86-64") and cpu_specific(x86_64) 
attributes` tests
add `__builtin_cpu_supports x86-64-v5` test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158811

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/builtin-cpu-supports.c
  clang/test/Sema/builtin-cpu-supports.c
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/TargetParser/X86TargetParser.cpp

Index: llvm/lib/TargetParser/X86TargetParser.cpp
===
--- llvm/lib/TargetParser/X86TargetParser.cpp
+++ llvm/lib/TargetParser/X86TargetParser.cpp
@@ -703,18 +703,22 @@
   return I != std::end(Processors);
 }
 
-uint64_t llvm::X86::getCpuSupportsMask(ArrayRef FeatureStrs) {
+std::array
+llvm::X86::getCpuSupportsMask(ArrayRef FeatureStrs) {
   // Processor features and mapping to processor feature value.
-  uint64_t FeaturesMask = 0;
-  for (const StringRef &FeatureStr : FeatureStrs) {
+  std::array FeatureMask{};
+  for (StringRef FeatureStr : FeatureStrs) {
 unsigned Feature = StringSwitch(FeatureStr)
 #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY)\
   .Case(STR, llvm::X86::FEATURE_##ENUM)
+#define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY)   \
+  .Case(STR, llvm::X86::FEATURE_##ENUM)
 #include "llvm/TargetParser/X86TargetParser.def"
 ;
-FeaturesMask |= (1ULL << Feature);
+assert(Feature / 32 < FeatureMask.size());
+FeatureMask[Feature / 32] |= 1U << (Feature % 32);
   }
-  return FeaturesMask;
+  return FeatureMask;
 }
 
 unsigned llvm::X86::getFeaturePriority(ProcessorFeatures Feat) {
Index: llvm/include/llvm/TargetParser/X86TargetParser.h
===
--- llvm/include/llvm/TargetParser/X86TargetParser.h
+++ llvm/include/llvm/TargetParser/X86TargetParser.h
@@ -15,6 +15,7 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringMap.h"
+#include 
 
 namespace llvm {
 template  class SmallVectorImpl;
@@ -57,7 +58,10 @@
 enum ProcessorFeatures {
 #define X86_FEATURE(ENUM, STRING) FEATURE_##ENUM,
 #include "llvm/TargetParser/X86TargetParser.def"
-  CPU_FEATURE_MAX
+  CPU_FEATURE_MAX,
+
+#define X86_MICROARCH_LEVEL(ENUM, STRING, PRIORITY) FEATURE_##ENUM = PRIORITY,
+#include "llvm/TargetParser/X86TargetParser.def"
 };
 
 enum CPUKind {
@@ -171,7 +175,7 @@
 
 char getCPUDispatchMangling(StringRef Name);
 bool validateCPUSpecificCPUDispatch(StringRef Name);
-uint64_t getCpuSupportsMask(ArrayRef FeatureStrs);
+std::array getCpuSupportsMask(ArrayRef FeatureStrs);
 unsigned getFeaturePriority(ProcessorFeatures Feat);
 
 } // namespace X86
Index: llvm/include/llvm/TargetParser/X86TargetParser.def
===
--- llvm/include/llvm/TargetParser/X86TargetParser.def
+++ llvm/include/llvm/TargetParser/X86TargetParser.def
@@ -128,6 +128,10 @@
 #define X86_FEATURE(ENUM, STR)
 #endif
 
+#ifndef X86_MICROARCH_LEVEL
+#define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY)
+#endif
+
 X86_FEATURE_COMPAT(CMOV,"cmov",  0)
 X86_FEATURE_COMPAT(MMX, "mmx",   1)
 X86_FEATURE_COMPAT(POPCNT,  "popcnt",9)
@@ -242,5 +246,11 @@
 X86_FEATURE   (RETPOLINE_INDIRECT_CALLS,"retpoline-indirect-calls")
 X86_FEATURE   (LVI_CFI, "lvi-cfi")
 X86_FEATURE   (LVI_LOAD_HARDENING,  "lvi-load-hardening")
+
+X86_MICROARCH_LEVEL(X86_64_BASELINE,"x86-64",   95)
+X86_MICROARCH_LEVEL(X86_64_V2,  "x86-64-v2",96)
+X86_MICROARCH_LEVEL(X86_64_V3,  "x86-64-v3",97)
+X86_MICROARCH_LEVEL(X86_64_V4,  "x86-64-v4",98)
 #undef X86_FEATURE_COMPAT
 #undef X86_FEATURE
+#undef X86_MICROARCH_LEVEL
Index: clang/test/Sema/builtin-cpu-supports.c
===
--- clang/test/Sema/builtin-cpu-supports.c
+++ clang/test/Sema/builtin-cpu-supports.c
@@ -20,6 +20,12 @@
   (void)__builtin_cpu_is("x86-64-v2"); // expected-error {{invalid cpu name for builtin}}
   (void)__builtin_cpu_is("x86-64-v3"); // expected-error {{invalid cpu name for builtin}}
   (void)__builtin_cpu_is("x86-64-v4"); // expected-error {{invalid cpu name for builtin}}
+
+  (void)__builtin_cpu_supports("x86-64");
+  (void)__builtin_cpu_supports("x86-64-v2");
+  (void)__builtin_cpu_supports("x86-64-v3");
+  (void)__builtin_cpu_supports("x86-64-v4");
+  (void)__builtin_cpu_supports("x86-64-v5"); // expected-error {{invalid cpu feature string for builtin}}
 #else
   if (__

[PATCH] D158872: [clang][ASTMatchers] Add a few type-related Matchers

2023-08-25 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 553697.
danix800 added a comment.

Update docs for `bitIntType` & `dependentBitIntType`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158872

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTest.h

Index: clang/unittests/ASTMatchers/ASTMatchersTest.h
===
--- clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -284,6 +284,33 @@
   {"-fopenmp=libomp", "-fopenmp-version=51"});
 }
 
+template 
+testing::AssertionResult matchesOpenCL(const Twine &Code, const T &AMatcher) {
+  return matchesConditionally(Code, AMatcher, true,
+  {"-x", "cl", "-cl-no-stdinc", "-cl-std=CL2.0"},
+  FileContentMappings(), "input.cl");
+}
+
+template 
+testing::AssertionResult notMatchesOpenCL(const Twine &Code,
+  const T &AMatcher) {
+  return matchesConditionally(Code, AMatcher, false,
+  {"-x", "cl", "-cl-no-stdinc", "-cl-std=CL2.0"},
+  FileContentMappings(), "input.cl");
+}
+
+template 
+testing::AssertionResult matchesWithMatrixEnabled(const Twine &Code,
+  const T &AMatcher) {
+  return matchesConditionally(Code, AMatcher, true, {"-fenable-matrix"});
+}
+
+template 
+testing::AssertionResult notMatchesWithMatrixEnabled(const Twine &Code,
+ const T &AMatcher) {
+  return matchesConditionally(Code, AMatcher, false, {"-fenable-matrix"});
+}
+
 template 
 testing::AssertionResult matchAndVerifyResultConditionally(
 const Twine &Code, const T &AMatcher,
Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1549,6 +1549,89 @@
   EXPECT_TRUE(matches("struct S {};", qualType().bind("loc")));
 }
 
+TEST_P(ASTMatchersTest, BitIntType) {
+  StringRef code = "_BitInt(10) i;";
+  EXPECT_TRUE(matches(code, varDecl(hasType(bitIntType();
+  EXPECT_TRUE(notMatches(code, varDecl(hasType(builtinType();
+}
+
+TEST_P(ASTMatchersTest, ConstantMatrixType) {
+  StringRef Code = "typedef int __attribute__((matrix_type(5, 5))) X;";
+
+  EXPECT_TRUE(matchesWithMatrixEnabled(
+  Code, typedefDecl(hasType(constantMatrixType();
+  EXPECT_TRUE(
+  notMatchesWithMatrixEnabled(Code, typedefDecl(hasType(vectorType();
+}
+
+TEST_P(ASTMatchersTest, DependentAddressSpaceType) {
+  if (!GetParam().isCXX())
+return;
+
+  StringRef Code = "template"
+   "class vector {"
+   "  typedef T __attribute__((address_space(AddrSpace))) X;"
+   "};";
+  EXPECT_TRUE(matches(Code, typedefDecl(hasType(dependentAddressSpaceType();
+
+  EXPECT_TRUE(notMatches("int __attribute__((address_space(0))) X;",
+ typedefDecl(hasType(dependentAddressSpaceType();
+}
+
+TEST_P(ASTMatchersTest, DependentBitIntType) {
+  if (!GetParam().isCXX11OrLater())
+return;
+
+  EXPECT_TRUE(matches("template using X = _BitInt(Width);",
+  typeAliasDecl(hasType(dependentBitIntType();
+
+  EXPECT_TRUE(notMatches("typedef _BitInt(10) Int10;",
+ typedefDecl(hasType(dependentBitIntType();
+}
+
+TEST_P(ASTMatchersTest, DependentVectorType) {
+  if (!GetParam().isCXX())
+return;
+
+  StringRef DepCode = "template"
+  "class vector {"
+  "  typedef T __attribute__((vector_size(Size))) X;"
+  "};";
+  EXPECT_TRUE(matches(DepCode, dependentVectorType()));
+
+  StringRef NonDepCode = "typedef int __attribute__((vector_size(16))) X;";
+  EXPECT_TRUE(notMatches(NonDepCode, dependentVectorType()));
+}
+
+TEST_P(ASTMatchersTest, VectorType) {
+  if (!GetParam().isCXX())
+return;
+
+  StringRef NonDepCode = "typedef int __attribute__((vector_size(16))) X;";
+  EXPECT_TRUE(matches(NonDepCode, vectorType()));
+
+  StringRef DepCode = "template"
+  "class vector {"
+  "  typedef T __attribute__((vector_size(Size))) X;"
+  "};";
+  EXPECT_TRUE(notMatches(DepCode, vectorType()));
+}
+
+TEST_P(ASTMatchersTest, DependentSizedMatrixType) {
+  if (!GetParam().isCXX())
+return;
+
+  StringRef DepCode = "template"
+  

[PATCH] D158872: [clang][ASTMatchers] Add a few type-related Matchers

2023-08-25 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

In D158872#4618252 , @PiotrZSL wrote:

> LGTM.
> Nothing fancy, looks straight forward.
> You may want to wait for an Aaron Ballman opinion.

Thanks for the reviewing.

Ping @aaron.ballman, could you please take a look at this revision?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158872

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


[clang] 9de3b35 - [X86][test] Test that target("x86-64") and cpu_specific(x86_64) attributes are invalid

2023-08-25 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-08-25T20:45:45-07:00
New Revision: 9de3b35ac9159d5bae6e6796cb91e4f877a07189

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

LOG: [X86][test] Test that target("x86-64") and cpu_specific(x86_64) attributes 
are invalid

Added: 


Modified: 
clang/test/Sema/attr-cpuspecific.c
clang/test/Sema/attr-target.c

Removed: 




diff  --git a/clang/test/Sema/attr-cpuspecific.c 
b/clang/test/Sema/attr-cpuspecific.c
index f3d46cf8f1801a..3cd58f49faa5e6 100644
--- a/clang/test/Sema/attr-cpuspecific.c
+++ b/clang/test/Sema/attr-cpuspecific.c
@@ -181,3 +181,8 @@ int __attribute__((__overloadable__)) 
__attribute__((cpu_specific(ivybridge))) g
 // expected-error@+1 {{attribute 'cpu_specific' multiversioning cannot be 
combined with attribute 'overloadable'}}
 int __attribute__((__overloadable__)) __attribute__((cpu_specific(atom))) 
good_overload7(void);
 int __attribute__((cpu_specific(ivybridge))) good_overload7(int);
+
+// expected-error@+1 {{invalid option 'x86_64'}}
+int __attribute__((cpu_specific(x86_64))) baseline(void);
+// expected-error@+1 {{invalid option 'x86_64_v2'}}
+int __attribute__((cpu_specific(x86_64_v2))) baseline(void);

diff  --git a/clang/test/Sema/attr-target.c b/clang/test/Sema/attr-target.c
index 653550757bda76..3416a3d0a6ba13 100644
--- a/clang/test/Sema/attr-target.c
+++ b/clang/test/Sema/attr-target.c
@@ -26,6 +26,11 @@ int __attribute__((target("branch-protection=none"))) 
birch_tree(void) { return
 //expected-warning@+1 {{unknown tune CPU 'hiss' in the 'target' attribute 
string; 'target' attribute ignored}}
 int __attribute__((target("tune=hiss,tune=woof"))) apple_tree(void) { return 
4; }
 
+//expected-warning@+1 {{unsupported 'x86-64' in the 'target' attribute string}}
+void __attribute__((target("x86-64"))) baseline(void) {}
+//expected-warning@+1 {{unsupported 'x86-64-v2' in the 'target' attribute 
string}}
+void __attribute__((target("x86-64-v2"))) v2(void) {}
+
 #elifdef __aarch64__
 
 int __attribute__((target("sve,arch=armv8-a"))) foo(void) { return 4; }



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


[PATCH] D158920: Delete CloudABI support

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

Thanks for the cleanup.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158920

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


[PATCH] D158601: [Clang] Always constant-evaluate operands of comparisons to nullptr

2023-08-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

It might have been nice to add a test where `nullptr_t` comparison succeeds as 
well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158601

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


[PATCH] D158920: Delete CloudABI support

2023-08-25 Thread Brad Smith via Phabricator via cfe-commits
brad created this revision.
brad added reviewers: MaskRay, ed, dim.
brad added projects: LLVM, clang.
Herald added subscribers: steakhal, martong, hiraditya, krytarowski, 
arichardson, emaste.
Herald added a reviewer: NoQ.
Herald added a project: All.
brad requested review of this revision.

After this https://reviews.llvm.org/D108637 and with FreeBSD -current and now 
14 dropping support for CloudABI I think it is time to consider deleting the 
CloudABI support.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158920

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Lex/InitHeaderSearch.cpp
  clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
  clang/test/Analysis/security-syntax-checks.m
  clang/test/Driver/frame-pointer-elim.c
  clang/test/Driver/fsanitize.c
  clang/test/Frontend/gnu-mcount.c
  clang/test/Preprocessor/init-arm.c
  clang/test/Preprocessor/init-x86.c
  clang/test/Preprocessor/predefined-macros-no-warnings.c
  llvm/include/llvm/MC/MCELFObjectWriter.h
  llvm/include/llvm/TargetParser/Triple.h
  llvm/lib/TargetParser/Triple.cpp

Index: llvm/lib/TargetParser/Triple.cpp
===
--- llvm/lib/TargetParser/Triple.cpp
+++ llvm/lib/TargetParser/Triple.cpp
@@ -209,7 +209,6 @@
   case AMDPAL: return "amdpal";
   case Ananas: return "ananas";
   case CUDA: return "cuda";
-  case CloudABI: return "cloudabi";
   case Darwin: return "darwin";
   case DragonFly: return "dragonfly";
   case DriverKit: return "driverkit";
@@ -572,7 +571,6 @@
 static Triple::OSType parseOS(StringRef OSName) {
   return StringSwitch(OSName)
 .StartsWith("ananas", Triple::Ananas)
-.StartsWith("cloudabi", Triple::CloudABI)
 .StartsWith("darwin", Triple::Darwin)
 .StartsWith("dragonfly", Triple::DragonFly)
 .StartsWith("freebsd", Triple::FreeBSD)
Index: llvm/include/llvm/TargetParser/Triple.h
===
--- llvm/include/llvm/TargetParser/Triple.h
+++ llvm/include/llvm/TargetParser/Triple.h
@@ -185,7 +185,6 @@
 UnknownOS,
 
 Ananas,
-CloudABI,
 Darwin,
 DragonFly,
 FreeBSD,
Index: llvm/include/llvm/MC/MCELFObjectWriter.h
===
--- llvm/include/llvm/MC/MCELFObjectWriter.h
+++ llvm/include/llvm/MC/MCELFObjectWriter.h
@@ -71,8 +71,6 @@
 
   static uint8_t getOSABI(Triple::OSType OSType) {
 switch (OSType) {
-  case Triple::CloudABI:
-return ELF::ELFOSABI_CLOUDABI;
   case Triple::HermitCore:
 return ELF::ELFOSABI_STANDALONE;
   case Triple::PS4:
Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- clang/test/Preprocessor/predefined-macros-no-warnings.c
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -10,7 +10,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_32-darwin
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-darwin
-// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-cloudabi
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-freebsd
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-fuchsia
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-linux
@@ -26,7 +25,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-netbsd
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-darwin
-// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-cloudabi
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-freebsd
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-fuchsia
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-linux
@@ -136,7 +134,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-darwin
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-ananas
-// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-cloudabi
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-linux
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-linux-android
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-dragonfly
@@ -158,7 +155,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple x86_64
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple x86_64-darwin
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werro

[PATCH] D158811: [X86] __builtin_cpu_supports: support x86-64{,-v2,-v3,-v4}

2023-08-25 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei accepted this revision.
pengfei added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158811

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


[PATCH] D158808: [Clang] Modify Parser::ParseLambdaExpressionAfterIntroducer to check whether the lambda-declarator is valid

2023-08-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 553692.
shafik added a comment.

- Move test to C++20 file
- Apply clang-format


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

https://reviews.llvm.org/D158808

Files:
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/Parser/cxx2a-template-lambdas.cpp
  clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp


Index: clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
===
--- clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
+++ clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
@@ -5,12 +5,11 @@
 template T declval();
 
 template 
-auto Call(T x) -> decltype(declval()(0)) {} // expected-note{{candidate 
template ignored}}
+auto Call(T x) -> decltype(declval()(0)) {}
 
 class Status {};
 
 void fun() {
   // The Status() (instead of Status) here used to cause a crash.
   Call([](auto x) -> Status() {}); // expected-error{{function cannot return 
function type 'Status ()}}
-  // expected-error@-1{{no matching function for call to 'Call'}}
 }
Index: clang/test/Parser/cxx2a-template-lambdas.cpp
===
--- clang/test/Parser/cxx2a-template-lambdas.cpp
+++ clang/test/Parser/cxx2a-template-lambdas.cpp
@@ -32,3 +32,11 @@
 // expected-warning@-3 {{is a C++23 extension}}
 // expected-warning@-3 {{is a C++23 extension}}
 #endif
+
+namespace GH64962 {
+void f() {
+  [] (T i) -> int[] // expected-error {{function cannot return 
array type 'int[]'}}
+// extension-warning {{explicit template 
parameter list for lambdas is a C++20 extension}}
+{ return 3; } (v); // expected-error {{use of undeclared identifier 'v'}}
+}
+}
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1546,7 +1546,8 @@
   TemplateParamScope.Exit();
   LambdaScope.Exit();
 
-  if (!Stmt.isInvalid() && !TrailingReturnType.isInvalid())
+  if (!Stmt.isInvalid() && !TrailingReturnType.isInvalid() &&
+  !D.isInvalidType())
 return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get(), getCurScope());
 
   Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope());


Index: clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
===
--- clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
+++ clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
@@ -5,12 +5,11 @@
 template T declval();
 
 template 
-auto Call(T x) -> decltype(declval()(0)) {} // expected-note{{candidate template ignored}}
+auto Call(T x) -> decltype(declval()(0)) {}
 
 class Status {};
 
 void fun() {
   // The Status() (instead of Status) here used to cause a crash.
   Call([](auto x) -> Status() {}); // expected-error{{function cannot return function type 'Status ()}}
-  // expected-error@-1{{no matching function for call to 'Call'}}
 }
Index: clang/test/Parser/cxx2a-template-lambdas.cpp
===
--- clang/test/Parser/cxx2a-template-lambdas.cpp
+++ clang/test/Parser/cxx2a-template-lambdas.cpp
@@ -32,3 +32,11 @@
 // expected-warning@-3 {{is a C++23 extension}}
 // expected-warning@-3 {{is a C++23 extension}}
 #endif
+
+namespace GH64962 {
+void f() {
+  [] (T i) -> int[] // expected-error {{function cannot return array type 'int[]'}}
+// extension-warning {{explicit template parameter list for lambdas is a C++20 extension}}
+{ return 3; } (v); // expected-error {{use of undeclared identifier 'v'}}
+}
+}
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1546,7 +1546,8 @@
   TemplateParamScope.Exit();
   LambdaScope.Exit();
 
-  if (!Stmt.isInvalid() && !TrailingReturnType.isInvalid())
+  if (!Stmt.isInvalid() && !TrailingReturnType.isInvalid() &&
+  !D.isInvalidType())
 return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get(), getCurScope());
 
   Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148381: [WIP][Clang] Add counted_by attribute

2023-08-25 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 553682.
void added a comment.

Modify sanitize scope to avoid the instruction creation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Misc/warning-flags.c

Index: clang/test/Misc/warning-flags.c
===
--- clang/test/Misc/warning-flags.c
+++ clang/test/Misc/warning-flags.c
@@ -41,6 +41,7 @@
 CHECK-NEXT:   warn_char_constant_too_large
 CHECK-NEXT:   warn_collection_expr_type
 CHECK-NEXT:   warn_conflicting_variadic
+CHECK-NEXT:   warn_counted_by_placeholder
 CHECK-NEXT:   warn_delete_array_type
 CHECK-NEXT:   warn_double_const_requires_fp64
 CHECK-NEXT:   warn_drv_assuming_mfloat_abi_is
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -56,6 +56,7 @@
 // CHECK-NEXT: ConsumableAutoCast (SubjectMatchRule_record)
 // CHECK-NEXT: ConsumableSetOnRead (SubjectMatchRule_record)
 // CHECK-NEXT: Convergent (SubjectMatchRule_function)
+// CHECK-NEXT: CountedBy (SubjectMatchRule_field)
 // CHECK-NEXT: DLLExport (SubjectMatchRule_function, SubjectMatchRule_variable, SubjectMatchRule_record, SubjectMatchRule_objc_interface)
 // CHECK-NEXT: DLLImport (SubjectMatchRule_function, SubjectMatchRule_variable, SubjectMatchRule_record, SubjectMatchRule_objc_interface)
 // CHECK-NEXT: Destructor (SubjectMatchRule_function)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8380,6 +8380,21 @@
   D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL));
 }
 
+static void handleCountedByAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  // TODO: Probably needs more processing here. See Sema::AddAlignValueAttr.
+  if (!AL.isArgIdent(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+<< AL << AANT_ArgumentIdentifier;
+return;
+  }
+
+  IdentifierLoc *IL = AL.getArgAsIdent(0);
+  CountedByAttr *CBA =
+  ::new (S.Context) CountedByAttr(S.Context, AL, IL->Ident);
+  CBA->setCountedByFieldLoc(IL->Loc);
+  D->addAttr(CBA);
+}
+
 static void handleFunctionReturnThunksAttr(Sema &S, Decl *D,
const ParsedAttr &AL) {
   StringRef KindStr;
@@ -9326,6 +9341,10 @@
 handleAvailableOnlyInDefaultEvalMethod(S, D, AL);
 break;
 
+  case ParsedAttr::AT_CountedBy:
+handleCountedByAttr(S, D, AL);
+break;
+
   // Microsoft attributes:
   case ParsedAttr::AT_LayoutVersion:
 handleLayoutVersion(S, D, AL);
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -17903,6 +17903,40 @@
  "Broken injected-class-name");
 }
 
+static const FieldDecl *FindFieldWithCountedByAttr(const RecordDecl *RD) {
+  for (const Decl *D : RD->decls()) {
+if (const auto *FD = dyn_cast(D)) {
+  if (FD->hasAttr())
+return FD;
+}
+
+if (const auto *SubRD = dyn_cast(D)) {
+  return FindFieldWithCountedByAttr(SubRD);
+}
+  }
+
+  return nullptr;
+}
+
+/// CheckCountedByAttr - Return an \p IdentifierInfo if the attribute field
+/// doesn't exist in the enclosing structure. Returns \p nullptr if the
+/// attribute field does exist.
+static const IdentifierInfo *CheckCountedByAttr(const RecordDecl *RD,
+const FieldDecl *FD,
+SourceRange &Loc) {
+  const CountedByAttr *ECA = FD->getAttr();
+
+  auto It = llvm::find_if(RD->fields(), [&](const FieldDecl *Field) {
+return Field->getName() == ECA->getCountedByField()->getName();
+  });
+  if (It == RD->field_end()) {
+Loc = ECA->getCountedByFieldLoc();
+return ECA->getCountedByField();
+  }
+
+  return nullptr;
+}
+
 void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD,
 SourceRange BraceRange) {
   AdjustDeclIfTemplate(TagD);
@@ -17960,6 +17994,16 @@
  [](co

[PATCH] D158709: [Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized

2023-08-25 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 553677.
iana added a comment.

Modules don't support the #include #undef #include pattern to redefine macros, 
the second include has no effect. Move the #undef of NULL into __stddef_null.h 
so that the textual behavior is preserved, but the module behavior doesn't 
leave NULL undefined.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158709

Files:
  clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__stdarg___gnuc_va_list.h
  clang/lib/Headers/__stdarg___va_copy.h
  clang/lib/Headers/__stdarg_va_arg.h
  clang/lib/Headers/__stdarg_va_copy.h
  clang/lib/Headers/__stdarg_va_list.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/stddef.c
  compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
  llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
@@ -95,7 +95,21 @@
 "__clang_hip_math.h",
 "__clang_hip_runtime_wrapper.h",
 "__clang_hip_stdlib.h",
+"__stdarg___gnuc_va_list.h",
+"__stdarg___va_copy.h",
+"__stdarg_va_arg.h",
+"__stdarg_va_copy.h",
+"__stdarg_va_list.h",
 "__stddef_max_align_t.h",
+"__stddef_null.h",
+"__stddef_nullptr_t.h",
+"__stddef_offsetof.h",
+"__stddef_ptrdiff_t.h",
+"__stddef_rsize_t.h",
+"__stddef_size_t.h",
+"__stddef_unreachable.h",
+"__stddef_wchar_t.h",
+"__stddef_wint_t.h",
 "__wmmintrin_aes.h",
 "__wmmintrin_pclmul.h",
 "adxintrin.h",
Index: compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
===
--- compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
+++ compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
@@ -20,6 +20,15 @@
 #include 
 #include 
 // IWYU pragma: no_include <__stddef_max_align_t.h>
+// IWYU pragma: no_include <__stddef_null.h>
+// IWYU pragma: no_include <__stddef_nullptr_t.h>
+// IWYU pragma: no_include <__stddef_offsetof.h>
+// IWYU pragma: no_include <__stddef_ptrdiff_t.h>
+// IWYU pragma: no_include <__stddef_rsize_t.h>
+// IWYU pragma: no_include <__stddef_size_t.h>
+// IWYU pragma: no_include <__stddef_unreachable.h>
+// IWYU pragma: no_include <__stddef_wchar_t.h>
+// IWYU pragma: no_include <__stddef_wint_t.h>
 
 namespace gwp_asan {
 // This class is the primary implementation of the allocator portion of GWP-
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -6,7 +6,7 @@
 ptrdiff_t pdt;
 
 size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@stddef.h:* {{here}}
+// expected-note@__stddef_size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Headers/stddefneeds.c
===
--- clang/test/Headers/stddefneeds.c
+++ clang/test/Headers/stddefneeds.c
@@ -38,7 +38,7 @@
 ptrdiff_t p2;
 size_t s2;
 rsize_t r2; // c99-error{{unknown type}} c23-error{{unknown type}}
-// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+// c99-note@__stddef_size_t.h:*{{'size_t' declared here}} c23-note@__stddef_size_t.h:*{{'size_t' declared here}}
 wchar_t wc2; // c99-error{{unknown type}} c23-error{{unknown type}}
 void *v2 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
 nullptr_t n2; // c99-error{{unknown type}} c23-error{{unknown type}}
@@ -96,7 +96,7 @@
 // __need_nullptr_t generates an error in  // c99-error@stddef.h:*{{expected function body}}
+#include  // c99-error@__stddef_nullptr_t.h:*{{expected function body}}
 
 ptrdiff_t p6;
 size_t s6;
Index: clang/test/Headers/stddef.c
===
--- clang/test/Headers/stddef.c
+++ clang/test/Headers/stddef.c
@@ -22,7 +22,7 @@
 ptrdiff_t p1;
 size_t s1;
 rsize_t r1; // c99-error{{unknown type}} c11-error{{unknown type}} c23-error{{unknown type}}
-// c99-note@stddef.h:*{{'size_t' declared here}} c11-note@stddef.h:*{{'size_t' declared here}

[clang] 1376dfa - [OpenMP][Fix] Update test after changing flag value

2023-08-25 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-08-25T18:59:43-05:00
New Revision: 1376dfa32c5b94b33d396ecfd5a6e27cd9179b2f

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

LOG: [OpenMP][Fix] Update test after changing flag value

Summary:
Comments on a previous patch suggested changing this flag but I
neglected to update it in the Clang test accordingly. Fix this.

Added: 


Modified: 
clang/test/OpenMP/target_indirect_codegen.cpp

Removed: 




diff  --git a/clang/test/OpenMP/target_indirect_codegen.cpp 
b/clang/test/OpenMP/target_indirect_codegen.cpp
index c846233e6f9e94..0ecdb7279e20ac 100644
--- a/clang/test/OpenMP/target_indirect_codegen.cpp
+++ b/clang/test/OpenMP/target_indirect_codegen.cpp
@@ -11,13 +11,13 @@
 //.
 // HOST: @[[VAR:.+]] = global i8 0, align 1
 // HOST: @[[FOO_ENTRY_NAME:.+]] = internal unnamed_addr constant [{{[0-9]+}} x 
i8] c"[[FOO_NAME:__omp_offloading_[0-9a-z]+_[0-9a-z]+_foo_l[0-9]+]]\00"
-// HOST: @.omp_offloading.entry.[[FOO_NAME]] = weak constant 
%struct.__tgt_offload_entry { ptr @_Z3foov, ptr @[[FOO_ENTRY_NAME]], i64 8, i32 
4, i32 0 }, section "omp_offloading_entries", align 1
+// HOST: @.omp_offloading.entry.[[FOO_NAME]] = weak constant 
%struct.__tgt_offload_entry { ptr @_Z3foov, ptr @[[FOO_ENTRY_NAME]], i64 8, i32 
8, i32 0 }, section "omp_offloading_entries", align 1
 // HOST: @[[BAZ_ENTRY_NAME:.+]] = internal unnamed_addr constant [{{[0-9]+}} x 
i8] c"[[BAZ_NAME:__omp_offloading_[0-9a-z]+_[0-9a-z]+_baz_l[0-9]+]]\00"
-// HOST: @.omp_offloading.entry.[[BAZ_NAME]] = weak constant 
%struct.__tgt_offload_entry { ptr @_Z3bazv, ptr @[[BAZ_ENTRY_NAME]], i64 8, i32 
4, i32 0 }, section "omp_offloading_entries", align 1
+// HOST: @.omp_offloading.entry.[[BAZ_NAME]] = weak constant 
%struct.__tgt_offload_entry { ptr @_Z3bazv, ptr @[[BAZ_ENTRY_NAME]], i64 8, i32 
8, i32 0 }, section "omp_offloading_entries", align 1
 // HOST: @[[VAR_ENTRY_NAME:.+]] = internal unnamed_addr constant [4 x i8] 
c"var\00"
 // HOST: @.omp_offloading.entry.var = weak constant 
%struct.__tgt_offload_entry { ptr @[[VAR]], ptr @[[VAR_ENTRY_NAME]], i64 1, i32 
0, i32 0 }, section "omp_offloading_entries", align 1
 // HOST: @[[BAR_ENTRY_NAME:.+]] = internal unnamed_addr constant [{{[0-9]+}} x 
i8] c"[[BAR_NAME:__omp_offloading_[0-9a-z]+_[0-9a-z]+_bar_l[0-9]+]]\00"
-// HOST: @.omp_offloading.entry.[[BAR_NAME]] = weak constant 
%struct.__tgt_offload_entry { ptr @_ZL3barv, ptr @[[BAR_ENTRY_NAME]], i64 8, 
i32 4, i32 0 }, section "omp_offloading_entries", align 1
+// HOST: @.omp_offloading.entry.[[BAR_NAME]] = weak constant 
%struct.__tgt_offload_entry { ptr @_ZL3barv, ptr @[[BAR_ENTRY_NAME]], i64 8, 
i32 8, i32 0 }, section "omp_offloading_entries", align 1
 //.
 // DEVICE: @[[FOO_NAME:__omp_offloading_[0-9a-z]+_[0-9a-z]+_foo_l[0-9]+]] = 
protected addrspace(1) constant ptr @_Z3foov
 // DEVICE: @[[BAZ_NAME:__omp_offloading_[0-9a-z]+_[0-9a-z]+_baz_l[0-9]+]] = 
protected addrspace(1) constant ptr @_Z3bazv
@@ -44,8 +44,8 @@ char var = 0;
 
 #endif
 //.
-// HOST-DAG: !{{[0-9]+}} = !{i32 1, !"[[FOO_NAME]]", i32 4, i32 0}
-// HOST-DAG: !{{[0-9]+}} = !{i32 1, !"[[BAZ_NAME]]", i32 4, i32 1}
+// HOST-DAG: !{{[0-9]+}} = !{i32 1, !"[[FOO_NAME]]", i32 8, i32 0}
+// HOST-DAG: !{{[0-9]+}} = !{i32 1, !"[[BAZ_NAME]]", i32 8, i32 1}
 // HOST-DAG: !{{[0-9]+}} = !{i32 1, !"var", i32 0, i32 2}
-// HOST-DAG: !{{[0-9]+}} = !{i32 1, !"[[BAR_NAME]]", i32 4, i32 3}
+// HOST-DAG: !{{[0-9]+}} = !{i32 1, !"[[BAR_NAME]]", i32 8, i32 3}
 //.



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


[clang] 8456c8f - [CMake] Allow enabling Python in Fuchsia LLDB

2023-08-25 Thread Daniel Thornburgh via cfe-commits

Author: Daniel Thornburgh
Date: 2023-08-25T16:45:05-07:00
New Revision: 8456c8fe4e82e667e90beebb793c472bc0654a4c

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

LOG: [CMake] Allow enabling Python in Fuchsia LLDB

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake
clang/cmake/caches/Fuchsia.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 42d7f36df3f93d..3283c551ccb7cf 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -355,12 +355,16 @@ set(_FUCHSIA_DISTRIBUTIONS Toolchain)
 if(FUCHSIA_ENABLE_LLDB)
   list(APPEND _FUCHSIA_ENABLE_PROJECTS lldb)
   list(APPEND _FUCHSIA_DISTRIBUTIONS Debugger)
-  set(LLVM_Debugger_DISTRIBUTION_COMPONENTS
+  set(_FUCHSIA_LLDB_COMPONENTS
 lldb
 liblldb
 lldb-server
 lldb-argdumper
-CACHE STRING "")
+  )
+  if(LLDB_ENABLE_PYTHON)
+list(APPEND _FUCHSIA_LLDB_COMPONENTS lldb-python-scripts)
+  endif()
+  set(LLVM_Debugger_DISTRIBUTION_COMPONENTS ${_FUCHSIA_LLDB_COMPONENTS} CACHE 
STRING "")
 endif()
 
 set(LLVM_DISTRIBUTIONS ${_FUCHSIA_DISTRIBUTIONS} CACHE STRING "")

diff  --git a/clang/cmake/caches/Fuchsia.cmake 
b/clang/cmake/caches/Fuchsia.cmake
index bbaf8e262b9250..c599f141f9e5b1 100644
--- a/clang/cmake/caches/Fuchsia.cmake
+++ b/clang/cmake/caches/Fuchsia.cmake
@@ -44,6 +44,14 @@ set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH
   FUCHSIA_ENABLE_LLDB
   LLDB_ENABLE_CURSES
   LLDB_ENABLE_LIBEDIT
+  LLDB_ENABLE_PYTHON
+  LLDB_EMBED_PYTHON_HOME
+  LLDB_PYTHON_HOME
+  LLDB_PYTHON_RELATIVE_PATH
+  Python3_EXECUTABLE
+  Python3_LIBRARIES
+  Python3_INCLUDE_DIRS
+  Python3_RPATH
   CMAKE_FIND_PACKAGE_PREFER_CONFIG
   CMAKE_SYSROOT
   CMAKE_MODULE_LINKER_FLAGS



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


[PATCH] D158715: [Driver] Cleanup last vestiges of Minix / Contiki support

2023-08-25 Thread Brad Smith via Phabricator via cfe-commits
brad closed this revision.
brad added a comment.

Oops. I missed pasting the URL when commiting this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158715

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


[PATCH] D158795: Fix AlignArrayOfStructures + Cpp11BracedListStyle=false

2023-08-25 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/WhitespaceManager.cpp:1247
 if (Previous && Previous->isNot(TT_LineComment)) {
-  Changes[Next->Index].Spaces = 0;
+  Changes[Next->Index].Spaces = BracePadding;
   Changes[Next->Index].NewlinesBefore = 0;

owenpan wrote:
> Can we assert that `Spaces == 0`? If not, we should add a test case.
We can't assert that, but setting `Spaces` here seems superfluous as it's set 
correctly below anyways?


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

https://reviews.llvm.org/D158795

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


[PATCH] D158293: [NFC][Clang] Fix static code analyzer concern about null value dereference

2023-08-25 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann requested changes to this revision.
tahonermann added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/Lex/PPDirectives.cpp:494-495
   ++NumSkipped;
-  assert(!CurTokenLexer && CurPPLexer && "Lexing a macro, not a file?");
+  assert(!CurTokenLexer && CurPPLexer && CurLexer &&
+ "Lexing a macro, not a file?");
 

I would prefer that this `assert` be split up so that, when/if a failure 
occurs, we'll be able to tell which predicate failed.


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

https://reviews.llvm.org/D158293

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


[PATCH] D158869: [clang] Fix timing of propagation of MSInheritanceAttr for template instantiation declarations.

2023-08-25 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:10112
+  Specialization->addAttr(PrevDecl->getAttr());
+  Consumer.AssignInheritanceModel(Specialization);
+}

erichkeane wrote:
> tahonermann wrote:
> > I am concerned that moving the call to `Consumer.AssignInheritanceModel()` 
> > to immediately after the creation of the node, but before it is populated 
> > might be problematic. Previously, this call was still made before the node 
> > was completely constructed (e.g., before `setTemplateSpecializationKind()` 
> > is called for it). It is difficult to tell if any consumers might be 
> > dependent on more of the definition being present. 
> SO I think we still need to do this off of the definition, right?  Else if 
> `PrevDecl` ends up being a declaration (followed later by a definition that 
> has the attribute), we'll end up missing it?  Typically attributes are 
> 'added' by later decls, so only the 'latest one' (though attributes can't be 
> added after definition IIRC) has 'them all'.
This handles the situation where a new node is created for either an explicit 
template instantiation declaration or definition; that matches prior behavior. 
The goal is to ensure each node, regardless of the reason for its creation, 
inherits the attribute from the previous declaration; that ensures that any 
explicitly declared attributes are checked for consistency (see 
`Sema::mergeMSInheritanceAttr()`).

Note that an explicit class template specialization is not allowed to follow an 
explicit template instantiation declaration or definition. 
https://godbolt.org/z/cbvaac717.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158869

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


[PATCH] D157331: [clang] Implement C23

2023-08-25 Thread Zijun Zhao via Phabricator via cfe-commits
ZijunZhao updated this revision to Diff 553639.
ZijunZhao added a comment.

Add integer type test and update c2x tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157331

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/stdckdint.h
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/C/C2x/n2359.c
  clang/test/C/C2x/n2683.c
  clang/test/C/C2x/n2683_2.c
  clang/test/Headers/stdckdint.c
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -887,6 +887,11 @@
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2672.pdf";>N2672
   Yes
 
+
+  Towards Integer Safety
+  https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2683.pdf";>N2683
+  Clang 18
+
 
   Adding Fundamental Type for N-bit Integers
 
Index: clang/test/Modules/Inputs/System/usr/include/module.map
===
--- clang/test/Modules/Inputs/System/usr/include/module.map
+++ clang/test/Modules/Inputs/System/usr/include/module.map
@@ -14,6 +14,11 @@
 header "stdbool.h"
   }
 
+  // In both directories (compiler support version wins, does not forward)
+  module stdckdint {
+header "stdckdint.h"
+  }
+
   // In both directories (compiler support version wins, forwards)
   module stdint {
 header "stdint.h"
Index: clang/test/Headers/stdckdint.c
===
--- /dev/null
+++ clang/test/Headers/stdckdint.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -emit-llvm -verify -std=c23 %s -o - | FileCheck %s
+// expected-no-diagnostics
+#include 
+
+_Static_assert(__STDC_VERSION_STDCKDINT_H__ == 202311L, "");
+
+// CHECK-LABEL: define dso_local zeroext i1 @test_ckd_add() #0 {
+// CHECK:  entry:
+// CHECK:%result = alloca i32, align 4
+// CHECK:%0 = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 -1073741826, i32 -1073741826)
+// CHECK:%1 = extractvalue { i32, i1 } %0, 1
+// CHECK:%2 = extractvalue { i32, i1 } %0, 0
+// CHECK:store i32 %2, ptr %result, align 4
+// CHECK:ret i1 %1
+// CHECK:}
+// CHECK:; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+// CHECK:declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) #1
+bool test_ckd_add() {
+  int result;
+  return ckd_add(&result, -1073741826, -1073741826);
+}
+
+// CHECK-LABEL: define dso_local zeroext i1 @test_ckd_sub() #0 {
+// CHECK:  entry:
+// CHECK:%result = alloca i32, align 4
+// CHECK:%0 = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 -1073741826, i32 1073741826)
+// CHECK:%1 = extractvalue { i32, i1 } %0, 1
+// CHECK:%2 = extractvalue { i32, i1 } %0, 0
+// CHECK:store i32 %2, ptr %result, align 4
+// CHECK:ret i1 %1
+// CHECK:}
+// CHECK:declare { i32, i1 } @llvm.ssub.with.overflow.i32(i32, i32) #1
+bool test_ckd_sub() {
+  int result;
+  return ckd_sub(&result, -1073741826, 1073741826);
+}
+
+// CHECK-LABEL: define dso_local zeroext i1 @test_ckd_mul() #0 {
+// CHECK:  entry:
+// CHECK:%result = alloca i32, align 4
+// CHECK:%0 = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 -1073741826, i32 2)
+// CHECK:%1 = extractvalue { i32, i1 } %0, 1
+// CHECK:%2 = extractvalue { i32, i1 } %0, 0
+// CHECK:store i32 %2, ptr %result, align 4
+// CHECK:ret i1 %1
+// CHECK:}
+// CHECK:declare { i32, i1 } @llvm.smul.with.overflow.i32(i32, i32) #1
+bool test_ckd_mul() {
+  int result;
+  return ckd_mul(&result, -1073741826, 2);
+}
Index: clang/test/C/C2x/n2683_2.c
===
--- /dev/null
+++ clang/test/C/C2x/n2683_2.c
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -emit-llvm -o - -std=c23 %s | FileCheck %s
+
+#include 
+#include 
+// CHECK-LABEL: define dso_local void @test_add_overflow_to64() #0 {
+// CHECK:  entry:
+// CHECK:%result64 = alloca i64, align 8
+// CHECK:%flag_add = alloca i8, align 1
+// CHECK:store i64 0, ptr %result64, align 8
+// CHECK:%0 = call { i64, i1 } @llvm.sadd.with.overflow.i64(i64 2147483647, i64 1)
+// CHECK:%1 = extractvalue { i64, i1 } %0, 1 
+// CHECK:%2 = extractvalue { i64, i1 } %0, 0
+// CHECK:store i64 %2, ptr %result64, align 8
+// CHECK:%frombool = zext i1 %1 to i8
+// CHECK:store i8 %frombool, ptr %flag_add, align 1
+// CHECK:ret void
+// CHECK:  }
+void test_add_overflow_to64() {
+  int64_t result64 = 0;
+  bool flag_add = ckd_add(&result64, INT32_MAX, 1);
+}
+
+// CHECK-LABEL: define dso_local void @test_sub_overflow() #0 {
+// CHECK:  

[PATCH] D158496: [WIP][clang][modules] module build daemon initial commit

2023-08-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

(probably worth linking to the RFC/etc 
(https://discourse.llvm.org/t/rfc-modules-build-daemon-build-system-agnostic-support-for-explicitly-built-modules/71524/47)
 from the patch description/commit message)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158496

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


[PATCH] D151575: [clang][diagnostics] Always show include stacks on top-level diagnostics

2023-08-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

> Maybe we should consider adding a flag to set diagnostic verbosity level? 
> e.g., -fdiagnostic-verbosity=terse|default|verbose where terse never prints 
> notes or include stacks, default is what we do today, and verbose always 
> prints include stacks?

My guess would be that not enough people would discover and use it, so we 
shouldn't do that.

I guess a basic question: what does GCC do about these "included from" stacks 
compared to clang?

Also it seemed like on the bug there was a more narrower issue being discussed 
- that the notes were missing from a second error because it had the same 
include stack as a note attached to a previous error, but not the same include 
stack as the previous error (which is the last thing with the include stack 
mentioned)? I may've missed the point where it generalized from that particular 
bug to "let's put the include stack always instead" rather than addressing that 
mismatch of looking at the last message in general, rather than the last 
non-note message (I guess the include stack is only printed for non-notes, by 
the looks of the bug example? So those are the ones that should be 
cached/checked against)

But equally, I suspect it's probably OK to do it unconditionally... probably.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151575

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


[PATCH] D61670: [clang] [MinGW] Add the option -fno-autoimport

2023-08-25 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo updated this revision to Diff 553624.
mstorsjo edited the summary of this revision.
mstorsjo added a comment.

Updated to use the form -fno-auto-import and similar split it into two separate 
words everywhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61670

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/test/CodeGen/dso-local-executable.c
  clang/test/Driver/mingw-auto-import.c

Index: clang/test/Driver/mingw-auto-import.c
===
--- /dev/null
+++ clang/test/Driver/mingw-auto-import.c
@@ -0,0 +1,15 @@
+// By default, we don't pass any -fauto-import to -cc1, as that's the default.
+//
+// RUN: %clang --target=x86_64-w64-windows-gnu -### %s 2>&1 | FileCheck --check-prefixes=DEFAULT %s
+// RUN: %clang --target=x86_64-w64-windows-gnu -fno-auto-import -fauto-import -### %s 2>&1 | FileCheck --check-prefixes=DEFAULT %s
+// DEFAULT: "-cc1"
+// DEFAULT-NOT: no-auto-import
+// DEFAULT-NOT: --disable-auto-import
+
+// When compiling with -fno-auto-import, we pass -fno-auto-import to -cc1
+// and --disable-auto-import to the linker.
+//
+// RUN: %clang --target=x86_64-w64-windows-gnu -fauto-import -fno-auto-import -### %s 2>&1 | FileCheck --check-prefixes=NO_AUTOIMPORT %s
+// NO_AUTOIMPORT: "-cc1"
+// NO_AUTOIMPORT: "-fno-auto-import"
+// NO_AUTOIMPORT: "--disable-auto-import"
Index: clang/test/CodeGen/dso-local-executable.c
===
--- clang/test/CodeGen/dso-local-executable.c
+++ clang/test/CodeGen/dso-local-executable.c
@@ -9,12 +9,14 @@
 // COFF-DAG: define dso_local ptr @zed()
 // COFF-DAG: declare dllimport void @import_func()
 
-// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - | FileCheck --check-prefixes=MINGW,MINGW-NATIVE_TLS %s
-// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - -femulated-tls | FileCheck --check-prefixes=MINGW,MINGW-EMUTLS %s
+// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - | FileCheck --check-prefixes=MINGW,MINGW-NATIVE_TLS,MINGW-AUTO-IMPORT %s
+// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - -fno-auto-import | FileCheck --check-prefixes=MINGW,MINGW-NATIVE_TLS,MINGW-NO-AUTO-IMPORT %s
+// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - -femulated-tls | FileCheck --check-prefixes=MINGW,MINGW-EMUTLS,MINGW-AUTO-IMPORT %s
 // MINGW:  @baz = dso_local global i32 42
 // MINGW-NEXT: @import_var = external dllimport global i32
 // MINGW-NEXT: @weak_bar = extern_weak global i32
-// MINGW-NEXT: @bar = external global i32
+// MINGW-AUTO-IMPORT-NEXT: @bar = external global i32
+// MINGW-NO-AUTO-IMPORT-NEXT: @bar = external dso_local global i32
 // MINGW-NEXT: @local_thread_var = dso_local thread_local global i32 42
 // MINGW-NATIVE_TLS-NEXT: @thread_var = external dso_local thread_local global i32
 // MINGW-EMUTLS-NEXT: @thread_var = external thread_local global i32
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -169,6 +169,10 @@
   if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
 CmdArgs.push_back("--no-demangle");
 
+  if (!Args.hasFlag(options::OPT_fauto_import, options::OPT_fno_auto_import,
+true))
+CmdArgs.push_back("--disable-auto-import");
+
   if (Arg *A = Args.getLastArg(options::OPT_mguard_EQ)) {
 StringRef GuardArgs = A->getValue();
 if (GuardArgs == "none")
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5622,6 +5622,11 @@
 CmdArgs.push_back("-mms-bitfields");
   }
 
+  if (Triple.isWindowsGNUEnvironment()) {
+Args.addOptOutFlag(CmdArgs, options::OPT_fauto_import,
+   options::OPT_fno_auto_import);
+  }
+
   // Non-PIC code defaults to -fdirect-access-external-data while PIC code
   // defaults to -fno-direct-access-external-data. Pass the option if different
   // from the default.
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1409,6 +1409,7 @@
 return false;
 
   const llvm::Triple &TT = CGM.getTriple();
+  const auto &CGOpts = CGM.getCodeGenOpts();
   if (TT.isWindowsGNUEnvironment()) {
 // In MinGW, variables without DLLImport can still be automatically
 // imported from a DLL by the linker; don't mark variables that
@@ -1419,7 +1420,8 @@
 // such variables c

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

2023-08-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/include/clang/AST/Stmt.h:596-597
 
-// These don't need to be particularly wide, because they're
-// strictly limited by the forms of expressions we permit.
-unsigned NumSubExprs : 8;
-unsigned ResultIndex : 32 - 8 - NumExprBits;
+unsigned NumSubExprs : 16;
+unsigned ResultIndex : 16;
   };

aaron.ballman wrote:
> yronglin wrote:
> > aaron.ballman wrote:
> > > dblaikie wrote:
> > > > aaron.ballman wrote:
> > > > > yronglin wrote:
> > > > > > yronglin wrote:
> > > > > > > dblaikie wrote:
> > > > > > > > yronglin wrote:
> > > > > > > > > dblaikie wrote:
> > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > yronglin wrote:
> > > > > > > > > > > > dblaikie wrote:
> > > > > > > > > > > > > dblaikie wrote:
> > > > > > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > > > > > dblaikie wrote:
> > > > > > > > > > > > > > > > Could/should we add some error checking in the 
> > > > > > > > > > > > > > > > ctor to assert that we don't overflow these 
> > > > > > > > > > > > > > > > longer values/just hit the bug later on?
> > > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > (& could we use `unsigned short` here rather 
> > > > > > > > > > > > > > > > than bitfields?)
> > > > > > > > > > > > > > > We've already got them packed in with other 
> > > > > > > > > > > > > > > bit-fields from the expression bits, so I think 
> > > > > > > > > > > > > > > it's reasonable to continue the pattern of using 
> > > > > > > > > > > > > > > bit-fields (that way we don't accidentally end up 
> > > > > > > > > > > > > > > with padding between the unnamed bits at the 
> > > > > > > > > > > > > > > start and the named bits in this object).
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > I think adding some assertions would not be a bad 
> > > > > > > > > > > > > > > idea as a follow-up.
> > > > > > > > > > > > > > Maybe some unconditional (rather than only in 
> > > > > > > > > > > > > > asserts builds) error handling? 
> > > > > > > > > > > > > > (report_fatal_error, if this is low priority enough 
> > > > > > > > > > > > > > to not have an elegant failure mode, but something 
> > > > > > > > > > > > > > where we don't just overflow and carry on would be 
> > > > > > > > > > > > > > good... )
> > > > > > > > > > > > > Ping on this? I worry this code has just punted the 
> > > > > > > > > > > > > same bug further down, but not plugged the 
> > > > > > > > > > > > > hole/ensured we don't overflow on novel/larger inputs.
> > > > > > > > > > > > Sorry for the late reply, I was looking through the 
> > > > > > > > > > > > emails and found this. I agree add some assertions to 
> > > > > > > > > > > > check the value is a good idea, It's easy to help 
> > > > > > > > > > > > people catch bugs, at least with when 
> > > > > > > > > > > > `-DLLVM_ENABLE_ASSERTIONS=ON`, and I'm glad to work on 
> > > > > > > > > > > > it, but one thing that worries me is that, in 
> > > > > > > > > > > > ASTReader, we access this field directly, not through 
> > > > > > > > > > > > the constructor or accessor, and we have to add 
> > > > > > > > > > > > assertions everywhere. 
> > > > > > > > > > > > https://github.com/llvm/llvm-project/blob/05b4310c8aec7a050574277ced08a0ab86b27681/clang/lib/Serialization/ASTReaderStmt.cpp#L1382
> > > > > > > > > > > I don't think we have to add too many assertions. As best 
> > > > > > > > > > > I can tell, we'll need one in each of the 
> > > > > > > > > > > `PseudoObjectExpr` constructors and one in 
> > > > > > > > > > > `ASTStmtReader::VisitPseudoObjectExpr()`, but those are 
> > > > > > > > > > > the only places we assign a value into the bit-field. 
> > > > > > > > > > > Three assertions isn't a lot, but if we're worried, we 
> > > > > > > > > > > could add a setter method that does the assertion and use 
> > > > > > > > > > > the setter in all three places.
> > > > > > > > > > My concern wasn't (well, wasn't entirely) about adding more 
> > > > > > > > > > assertions - but about having a reliable error here. The 
> > > > > > > > > > patch only makes the sizes larger, but doesn't have a 
> > > > > > > > > > hard-stop in case those sizes are exceeded again (which, 
> > > > > > > > > > admittedly, is much harder to do - maybe it's totally 
> > > > > > > > > > unreachable now, for all practical purposes?) 
> > > > > > > > > > 
> > > > > > > > > > I suspect with more carefully constructed recursive inputs 
> > > > > > > > > > could still reach the higher limit & I think it'd be good 
> > > > > > > > > > to fail hard in that case in some way? (it's probably rare 
> > > > > > > > > > enough that a report_fatal_error would be 
> > > > > > > > > > not-the-worst-thing-ever)
> > > > > > > > > > 
> > > > > > > > > > But good assertions would be nice too (the old code only 
> > > > > > > > > > failed when you hit /exactly/ on just the overflow value, 
> > > > > > > > > > and any more 

[PATCH] D61670: [clang] [MinGW] Add the option -fno-autoimport

2023-08-25 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D61670#4611790 , @aeubanks wrote:

> In D61670#4607313 , @mstorsjo wrote:
>
>>> I expected the answer would be "yes", so I said "lgtm" and then phrased my 
>>> question very awkwardly.
>>
>> Ah, thanks for the clarification!
>>
>> Any opinion on the name, `-fno-autoimport` vs `-fno-auto-import`, given the 
>> existing linker option `--disable-auto-import`?
>
> Is there an official name, "auto-import"/"autoimport"/"auto import"?

Not really, no - it's all very much ad-hoc.

> Since cc1 flags are changeable and this hasn't landed yet, I think it'd be 
> nice to standardize before we commit on a stable name.
> If there isn't already a name, I like the dash in "auto-import".

Ok, sounds reasonable - I'll change it into that form then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61670

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


[PATCH] D158557: [clang] Fix crash in __builtin_strncmp and other related builtin functions

2023-08-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG33b6b674620d: [clang] Fix crash in __builtin_strncmp and 
other related builtin functions (authored by shafik).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158557

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ExprConstant.cpp
  clang/test/CodeGen/gh64876.cpp
  clang/test/SemaCXX/constexpr-string.cpp


Index: clang/test/SemaCXX/constexpr-string.cpp
===
--- clang/test/SemaCXX/constexpr-string.cpp
+++ clang/test/SemaCXX/constexpr-string.cpp
@@ -676,3 +676,24 @@
   }
   static_assert(test_address_of_incomplete_struct_type()); // expected-error 
{{constant}} expected-note {{in call}}
 }
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wconstant-conversion"
+namespace GH64876 {
+void f() {
+  __builtin_strncmp(0, 0, 0x);
+  __builtin_memcmp(0, 0, 0x);
+  __builtin_bcmp(0, 0, 0x);
+  __builtin_wmemcmp(0, 0, 0x);
+  __builtin_memchr((const void*)0, 1, 0x);
+  __builtin_wmemchr((const wchar_t*)0, 1, 0x);
+
+  __builtin_strncmp(0, 0, -511LL);
+  __builtin_memcmp(0, 0, -511LL);
+  __builtin_bcmp(0, 0, -511LL);
+  __builtin_wmemcmp(0, 0, -511LL);
+  __builtin_memchr((const void*)0, 1, -511LL);
+  __builtin_wmemchr((const wchar_t*)0, 1, -511LL);
+}
+}
+#pragma clang diagnostic pop
Index: clang/test/CodeGen/gh64876.cpp
===
--- /dev/null
+++ clang/test/CodeGen/gh64876.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -disable-llvm-passes -o - %s | 
FileCheck %s
+
+void f(const char* C, const wchar_t *WC) {
+  int x1 = __builtin_strncmp(C, "b", 0x);
+// CHECK: {{.*}}= call i32 @strncmp{{.*}}i64 noundef -1
+  int x2 = __builtin_memcmp(C, "b", 0x);
+// CHECK: {{.*}}= call i32 @memcmp{{.*}}i64 noundef -1
+  int x3 = __builtin_bcmp(C, "b", 0x);
+// CHECK: {{.*}}= call i32 @bcmp{{.*}}i64 noundef -1
+  int x4 = __builtin_wmemcmp(WC, L"b", 0x);
+// CHECK: {{.*}}= call i32 @wmemcmp{{.*}}i64 noundef -1
+  auto x5 = __builtin_memchr(C, (int)'a', 0x);
+// CHECK: {{.*}}= call ptr @memchr{{.*}}i64 noundef -1
+  auto x6 = __builtin_wmemchr(WC, (int)'a', 0x);
+// CHECK: {{.*}}= call ptr @wmemchr{{.*}}i64 noundef -1
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -9361,7 +9361,7 @@
   APSInt N;
   if (!EvaluateInteger(E->getArg(2), N, Info))
 return false;
-  MaxLength = N.getExtValue();
+  MaxLength = N.getZExtValue();
 }
 // We cannot find the value if there are no candidates to match against.
 if (MaxLength == 0u)
@@ -12385,7 +12385,7 @@
   APSInt N;
   if (!EvaluateInteger(E->getArg(2), N, Info))
 return false;
-  MaxLength = N.getExtValue();
+  MaxLength = N.getZExtValue();
 }
 
 // Empty substrings compare equal by definition.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -179,6 +179,9 @@
 - Clang now prints unnamed members in diagnostic messages instead of giving an
   empty ''. Fixes
   (`#63759 `_)
+- Fix crash in __builtin_strncmp and related builtins when the size value
+  exceeded the maximum value representable by int64_t. Fixes
+  (`#64876 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/constexpr-string.cpp
===
--- clang/test/SemaCXX/constexpr-string.cpp
+++ clang/test/SemaCXX/constexpr-string.cpp
@@ -676,3 +676,24 @@
   }
   static_assert(test_address_of_incomplete_struct_type()); // expected-error {{constant}} expected-note {{in call}}
 }
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wconstant-conversion"
+namespace GH64876 {
+void f() {
+  __builtin_strncmp(0, 0, 0x);
+  __builtin_memcmp(0, 0, 0x);
+  __builtin_bcmp(0, 0, 0x);
+  __builtin_wmemcmp(0, 0, 0x);
+  __builtin_memchr((const void*)0, 1, 0x);
+  __builtin_wmemchr((const wchar_t*)0, 1, 0x);
+
+  __builtin_strncmp(0, 0, -511LL);
+  __builtin_memcmp(0, 0, -511LL);
+  __builtin_bcmp(0, 0, -511LL);
+  __builtin_wmemcmp(0, 0, -511LL);
+  __builtin_memchr((const void*)0, 1, -511LL);
+  __builtin_

[clang] 33b6b67 - [clang] Fix crash in __builtin_strncmp and other related builtin functions

2023-08-25 Thread Shafik Yaghmour via cfe-commits

Author: Shafik Yaghmour
Date: 2023-08-25T13:54:50-07:00
New Revision: 33b6b674620d77e615d569f504b306aac528bab7

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

LOG: [clang] Fix crash in __builtin_strncmp and other related builtin functions

The implementation of __builtin_strncmp and other related builtins function use
getExtValue() to evaluate the size argument. This can cause a crash when the
value does not fit into an int64_t value, which is can be expected since the
type of the argument is size_t.

The fix is to switch to using getZExtValue().

This fixes: https://github.com/llvm/llvm-project/issues/64876

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

Added: 
clang/test/CodeGen/gh64876.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constexpr-string.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8580b2ccb20c24..0fff49c2c5108a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -179,6 +179,9 @@ Bug Fixes in This Version
 - Clang now prints unnamed members in diagnostic messages instead of giving an
   empty ''. Fixes
   (`#63759 `_)
+- Fix crash in __builtin_strncmp and related builtins when the size value
+  exceeded the maximum value representable by int64_t. Fixes
+  (`#64876 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d77c5d3f84a8d7..c6ab3758e99c1b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -9361,7 +9361,7 @@ bool PointerExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   APSInt N;
   if (!EvaluateInteger(E->getArg(2), N, Info))
 return false;
-  MaxLength = N.getExtValue();
+  MaxLength = N.getZExtValue();
 }
 // We cannot find the value if there are no candidates to match against.
 if (MaxLength == 0u)
@@ -12385,7 +12385,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   APSInt N;
   if (!EvaluateInteger(E->getArg(2), N, Info))
 return false;
-  MaxLength = N.getExtValue();
+  MaxLength = N.getZExtValue();
 }
 
 // Empty substrings compare equal by definition.

diff  --git a/clang/test/CodeGen/gh64876.cpp b/clang/test/CodeGen/gh64876.cpp
new file mode 100644
index 00..de46c4922768ae
--- /dev/null
+++ b/clang/test/CodeGen/gh64876.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -disable-llvm-passes -o - %s | 
FileCheck %s
+
+void f(const char* C, const wchar_t *WC) {
+  int x1 = __builtin_strncmp(C, "b", 0x);
+// CHECK: {{.*}}= call i32 @strncmp{{.*}}i64 noundef -1
+  int x2 = __builtin_memcmp(C, "b", 0x);
+// CHECK: {{.*}}= call i32 @memcmp{{.*}}i64 noundef -1
+  int x3 = __builtin_bcmp(C, "b", 0x);
+// CHECK: {{.*}}= call i32 @bcmp{{.*}}i64 noundef -1
+  int x4 = __builtin_wmemcmp(WC, L"b", 0x);
+// CHECK: {{.*}}= call i32 @wmemcmp{{.*}}i64 noundef -1
+  auto x5 = __builtin_memchr(C, (int)'a', 0x);
+// CHECK: {{.*}}= call ptr @memchr{{.*}}i64 noundef -1
+  auto x6 = __builtin_wmemchr(WC, (int)'a', 0x);
+// CHECK: {{.*}}= call ptr @wmemchr{{.*}}i64 noundef -1
+}

diff  --git a/clang/test/SemaCXX/constexpr-string.cpp 
b/clang/test/SemaCXX/constexpr-string.cpp
index cfee3566bbff71..c456740ef7551f 100644
--- a/clang/test/SemaCXX/constexpr-string.cpp
+++ b/clang/test/SemaCXX/constexpr-string.cpp
@@ -676,3 +676,24 @@ namespace MemcpyEtc {
   }
   static_assert(test_address_of_incomplete_struct_type()); // expected-error 
{{constant}} expected-note {{in call}}
 }
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wconstant-conversion"
+namespace GH64876 {
+void f() {
+  __builtin_strncmp(0, 0, 0x);
+  __builtin_memcmp(0, 0, 0x);
+  __builtin_bcmp(0, 0, 0x);
+  __builtin_wmemcmp(0, 0, 0x);
+  __builtin_memchr((const void*)0, 1, 0x);
+  __builtin_wmemchr((const wchar_t*)0, 1, 0x);
+
+  __builtin_strncmp(0, 0, -511LL);
+  __builtin_memcmp(0, 0, -511LL);
+  __builtin_bcmp(0, 0, -511LL);
+  __builtin_wmemcmp(0, 0, -511LL);
+  __builtin_memchr((const void*)0, 1, -511LL);
+  __builtin_wmemchr((const wchar_t*)0, 1, -511LL);
+}
+}
+#pragma clang diagnostic pop



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


[PATCH] D158873: [clangd] Do not ignore qualifier in heuristic resolution of dependent MemberExpr

2023-08-25 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf0f53cb4bfb2: [clangd] Do not ignore qualifier in heuristic 
resolution of dependent MemberExpr (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158873

Files:
  clang-tools-extra/clangd/HeuristicResolver.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1009,7 +1009,17 @@
 void play(Dog *dog) {
   [dog ho^wl];
 }
-  )objc"};
+  )objc",
+  R"cpp(
+struct PointerIntPairInfo {
+  static void *getPointer(void *Value);
+};
+
+template  struct PointerIntPair {
+  void *Value;
+  void *getPointer() const { return Info::get^Pointer(Value); }
+};
+)cpp"};
   for (const char *Test : Tests) {
 Annotations T(Test);
 std::optional WantDecl;
Index: clang-tools-extra/clangd/HeuristicResolver.cpp
===
--- clang-tools-extra/clangd/HeuristicResolver.cpp
+++ clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -119,8 +119,8 @@
 
 std::vector HeuristicResolver::resolveMemberExpr(
 const CXXDependentScopeMemberExpr *ME) const {
-  // If the expression has a qualifier, first try resolving the member
-  // inside the qualifier's type.
+  // If the expression has a qualifier, try resolving the member inside the
+  // qualifier's type.
   // Note that we cannot use a NonStaticFilter in either case, for a couple
   // of reasons:
   //   1. It's valid to access a static member using instance member syntax,
@@ -137,10 +137,15 @@
   if (!Decls.empty())
 return Decls;
 }
+
+// Do not proceed to try resolving the member in the expression's base type
+// without regard to the qualifier, as that could produce incorrect 
results.
+// For example, `void foo() { this->Base::foo(); }` shouldn't resolve to
+// foo() itself!
+return {};
   }
 
-  // If that didn't yield any results, try resolving the member inside
-  // the expression's base type.
+  // Try resolving the member inside the expression's base type.
   const Type *BaseType = ME->getBaseType().getTypePtrOrNull();
   if (ME->isArrow()) {
 BaseType = getPointeeType(BaseType);


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1009,7 +1009,17 @@
 void play(Dog *dog) {
   [dog ho^wl];
 }
-  )objc"};
+  )objc",
+  R"cpp(
+struct PointerIntPairInfo {
+  static void *getPointer(void *Value);
+};
+
+template  struct PointerIntPair {
+  void *Value;
+  void *getPointer() const { return Info::get^Pointer(Value); }
+};
+)cpp"};
   for (const char *Test : Tests) {
 Annotations T(Test);
 std::optional WantDecl;
Index: clang-tools-extra/clangd/HeuristicResolver.cpp
===
--- clang-tools-extra/clangd/HeuristicResolver.cpp
+++ clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -119,8 +119,8 @@
 
 std::vector HeuristicResolver::resolveMemberExpr(
 const CXXDependentScopeMemberExpr *ME) const {
-  // If the expression has a qualifier, first try resolving the member
-  // inside the qualifier's type.
+  // If the expression has a qualifier, try resolving the member inside the
+  // qualifier's type.
   // Note that we cannot use a NonStaticFilter in either case, for a couple
   // of reasons:
   //   1. It's valid to access a static member using instance member syntax,
@@ -137,10 +137,15 @@
   if (!Decls.empty())
 return Decls;
 }
+
+// Do not proceed to try resolving the member in the expression's base type
+// without regard to the qualifier, as that could produce incorrect results.
+// For example, `void foo() { this->Base::foo(); }` shouldn't resolve to
+// foo() itself!
+return {};
   }
 
-  // If that didn't yield any results, try resolving the member inside
-  // the expression's base type.
+  // Try resolving the member inside the expression's base type.
   const Type *BaseType = ME->getBaseType().getTypePtrOrNull();
   if (ME->isArrow()) {
 BaseType = getPointeeType(BaseType);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] f0f53cb - [clangd] Do not ignore qualifier in heuristic resolution of dependent MemberExpr

2023-08-25 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2023-08-25T16:54:29-04:00
New Revision: f0f53cb4bfb2b6c5ec6661b565a764c704484fa2

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

LOG: [clangd] Do not ignore qualifier in heuristic resolution of dependent 
MemberExpr

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

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

Added: 


Modified: 
clang-tools-extra/clangd/HeuristicResolver.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/HeuristicResolver.cpp 
b/clang-tools-extra/clangd/HeuristicResolver.cpp
index 719094dbf2b7e5..3c147b6b582bf0 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.cpp
+++ b/clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -119,8 +119,8 @@ const Type *HeuristicResolver::getPointeeType(const Type 
*T) const {
 
 std::vector HeuristicResolver::resolveMemberExpr(
 const CXXDependentScopeMemberExpr *ME) const {
-  // If the expression has a qualifier, first try resolving the member
-  // inside the qualifier's type.
+  // If the expression has a qualifier, try resolving the member inside the
+  // qualifier's type.
   // Note that we cannot use a NonStaticFilter in either case, for a couple
   // of reasons:
   //   1. It's valid to access a static member using instance member syntax,
@@ -137,10 +137,15 @@ std::vector 
HeuristicResolver::resolveMemberExpr(
   if (!Decls.empty())
 return Decls;
 }
+
+// Do not proceed to try resolving the member in the expression's base type
+// without regard to the qualifier, as that could produce incorrect 
results.
+// For example, `void foo() { this->Base::foo(); }` shouldn't resolve to
+// foo() itself!
+return {};
   }
 
-  // If that didn't yield any results, try resolving the member inside
-  // the expression's base type.
+  // Try resolving the member inside the expression's base type.
   const Type *BaseType = ME->getBaseType().getTypePtrOrNull();
   if (ME->isArrow()) {
 BaseType = getPointeeType(BaseType);

diff  --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index 6d7fd62016991a..f53cbf01b7992c 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1009,7 +1009,17 @@ TEST(LocateSymbol, All) {
 void play(Dog *dog) {
   [dog ho^wl];
 }
-  )objc"};
+  )objc",
+  R"cpp(
+struct PointerIntPairInfo {
+  static void *getPointer(void *Value);
+};
+
+template  struct PointerIntPair {
+  void *Value;
+  void *getPointer() const { return Info::get^Pointer(Value); }
+};
+)cpp"};
   for (const char *Test : Tests) {
 Annotations T(Test);
 std::optional WantDecl;



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


[PATCH] D158873: [clangd] Do not ignore qualifier in heuristic resolution of dependent MemberExpr

2023-08-25 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 553607.
nridge added a comment.

Address review comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158873

Files:
  clang-tools-extra/clangd/HeuristicResolver.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1004,7 +1004,17 @@
 void play(Dog *dog) {
   [dog ho^wl];
 }
-  )objc"};
+  )objc",
+  R"cpp(
+struct PointerIntPairInfo {
+  static void *getPointer(void *Value);
+};
+
+template  struct PointerIntPair {
+  void *Value;
+  void *getPointer() const { return Info::get^Pointer(Value); }
+};
+)cpp"};
   for (const char *Test : Tests) {
 Annotations T(Test);
 std::optional WantDecl;
Index: clang-tools-extra/clangd/HeuristicResolver.cpp
===
--- clang-tools-extra/clangd/HeuristicResolver.cpp
+++ clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -119,8 +119,8 @@
 
 std::vector HeuristicResolver::resolveMemberExpr(
 const CXXDependentScopeMemberExpr *ME) const {
-  // If the expression has a qualifier, first try resolving the member
-  // inside the qualifier's type.
+  // If the expression has a qualifier, try resolving the member inside the
+  // qualifier's type.
   // Note that we cannot use a NonStaticFilter in either case, for a couple
   // of reasons:
   //   1. It's valid to access a static member using instance member syntax,
@@ -137,10 +137,15 @@
   if (!Decls.empty())
 return Decls;
 }
+
+// Do not proceed to try resolving the member in the expression's base type
+// without regard to the qualifier, as that could produce incorrect 
results.
+// For example, `void foo() { this->Base::foo(); }` shouldn't resolve to
+// foo() itself!
+return {};
   }
 
-  // If that didn't yield any results, try resolving the member inside
-  // the expression's base type.
+  // Try resolving the member inside the expression's base type.
   const Type *BaseType = ME->getBaseType().getTypePtrOrNull();
   if (ME->isArrow()) {
 BaseType = getPointeeType(BaseType);


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1004,7 +1004,17 @@
 void play(Dog *dog) {
   [dog ho^wl];
 }
-  )objc"};
+  )objc",
+  R"cpp(
+struct PointerIntPairInfo {
+  static void *getPointer(void *Value);
+};
+
+template  struct PointerIntPair {
+  void *Value;
+  void *getPointer() const { return Info::get^Pointer(Value); }
+};
+)cpp"};
   for (const char *Test : Tests) {
 Annotations T(Test);
 std::optional WantDecl;
Index: clang-tools-extra/clangd/HeuristicResolver.cpp
===
--- clang-tools-extra/clangd/HeuristicResolver.cpp
+++ clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -119,8 +119,8 @@
 
 std::vector HeuristicResolver::resolveMemberExpr(
 const CXXDependentScopeMemberExpr *ME) const {
-  // If the expression has a qualifier, first try resolving the member
-  // inside the qualifier's type.
+  // If the expression has a qualifier, try resolving the member inside the
+  // qualifier's type.
   // Note that we cannot use a NonStaticFilter in either case, for a couple
   // of reasons:
   //   1. It's valid to access a static member using instance member syntax,
@@ -137,10 +137,15 @@
   if (!Decls.empty())
 return Decls;
 }
+
+// Do not proceed to try resolving the member in the expression's base type
+// without regard to the qualifier, as that could produce incorrect results.
+// For example, `void foo() { this->Base::foo(); }` shouldn't resolve to
+// foo() itself!
+return {};
   }
 
-  // If that didn't yield any results, try resolving the member inside
-  // the expression's base type.
+  // Try resolving the member inside the expression's base type.
   const Type *BaseType = ME->getBaseType().getTypePtrOrNull();
   if (ME->isArrow()) {
 BaseType = getPointeeType(BaseType);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156894: [NFC] Update OpenMP Support page for Clang/LLVM 17

2023-08-25 Thread Chi Chun Chen via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG59fdd4c0715f: [NFC] Update OpenMP Support page for 
Clang/LLVM 17 (authored by cchen).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156894

Files:
  clang/docs/OpenMPSupport.rst

Index: clang/docs/OpenMPSupport.rst
===
--- clang/docs/OpenMPSupport.rst
+++ clang/docs/OpenMPSupport.rst
@@ -148,7 +148,7 @@
 +--+--+--+---+
 | task | task affinity| :part:`not upstream` | https://github.com/jklinkenberg/openmp/tree/task-affinity |
 +--+--+--+---+
-| task | clause: depend on the taskwait construct | :part:`mostly done`  | D113540 (regular codegen only)|
+| task | clause: depend on the taskwait construct | :good:`done` | D113540 (regular codegen only)|
 +--+--+--+---+
 | task | depend objects and detachable tasks  | :good:`done` |   |
 +--+--+--+---+
@@ -196,7 +196,7 @@
 +--+--+--+---+
 | device   | allow access to the reference count (omp_target_is_present)  | :good:`done` |   |
 +--+--+--+---+
-| device   | requires directive   | :part:`partial`  |   |
+| device   | requires directive   | :good:`done` |   |
 +--+--+--+---+
 | device   | clause: unified_shared_memory| :good:`done` | D52625,D52359 |
 +--+--+--+---+
@@ -208,7 +208,7 @@
 +--+--+--+---+
 | device   | clause: dynamic_allocators   | :part:`unclaimed parts`  | D53079|
 +--+--+--+---+
-| device   | user-defined mappers | :part:`worked on`| D56326,D58638,D58523,D58074,D60972,D59474 |
+| device   | user-defined mappers | :good:`done` | D56326,D58638,D58523,D58074,D60972,D59474 |
 +--+--+--+---

[clang] 59fdd4c - [NFC] Update OpenMP Support page for Clang/LLVM 17

2023-08-25 Thread Chi Chun Chen via cfe-commits

Author: Chi Chun Chen
Date: 2023-08-25T15:50:39-05:00
New Revision: 59fdd4c0715fe16accf61aa3ce76b9bb1350d0e9

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

LOG: [NFC] Update OpenMP Support page for Clang/LLVM 17

Updating the status for a number of features in the OpenMP support page for 
Clang/LLVM 17.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/docs/OpenMPSupport.rst

Removed: 




diff  --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index 5a5fa950adcd41..be3894389a3517 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -148,7 +148,7 @@ implementation.
 
+--+--+--+---+
 | task | task affinity 
   | :part:`not upstream` | 
https://github.com/jklinkenberg/openmp/tree/task-affinity |
 
+--+--+--+---+
-| task | clause: depend on the taskwait construct  
   | :part:`mostly done`  | D113540 (regular codegen only)  
  |
+| task | clause: depend on the taskwait construct  
   | :good:`done` | D113540 (regular codegen only)  
  |
 
+--+--+--+---+
 | task | depend objects and detachable tasks   
   | :good:`done` | 
  |
 
+--+--+--+---+
@@ -196,7 +196,7 @@ implementation.
 
+--+--+--+---+
 | device   | allow access to the reference count 
(omp_target_is_present)  | :good:`done` |   
|
 
+--+--+--+---+
-| device   | requires directive
   | :part:`partial`  | 
  |
+| device   | requires directive
   | :good:`done` | 
  |
 
+--+--+--+---+
 | device   | clause: unified_shared_memory 
   | :good:`done` | D52625,D52359   
  |
 
+--+--+--+---+
@@ -208,7 +208,7 @@ implementation.
 
+--+--+--+---+
 | device   | clause: dynamic_allocators
   | :part:`unclaimed parts`  | D53079  
  |
 
+--+--+--+---+
-| device   | user-defined mappers  
   | :part:`worked on`| 
D56326,D58638,D58523,D58074,D60972,D59474 |
+| device   | user-defined mappers   

[PATCH] D158805: [clang-format][NFC] Remove extraneous newlines at end of test cases

2023-08-25 Thread Owen Pan via Phabricator via cfe-commits
owenpan marked an inline comment as done.
owenpan added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:24187
 
   // Newlines are important here.
+  verifyFormat("FOO(1+2 )", Style);

HazardyKnusperkeks wrote:
> This.
Good catch! Though `verifyFormat` removed the newlines anyways.


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

https://reviews.llvm.org/D158805

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


[PATCH] D158557: [clang] Fix crash in __builtin_strncmp and other related builtin functions

2023-08-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.

Still LGTM.


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

https://reviews.llvm.org/D158557

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


[PATCH] D158557: [clang] Fix crash in __builtin_strncmp and other related builtin functions

2023-08-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 553601.
shafik added a comment.

- Extended constexpr-string.cpp test
- Added release notes


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

https://reviews.llvm.org/D158557

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ExprConstant.cpp
  clang/test/CodeGen/gh64876.cpp
  clang/test/SemaCXX/constexpr-string.cpp


Index: clang/test/SemaCXX/constexpr-string.cpp
===
--- clang/test/SemaCXX/constexpr-string.cpp
+++ clang/test/SemaCXX/constexpr-string.cpp
@@ -676,3 +676,24 @@
   }
   static_assert(test_address_of_incomplete_struct_type()); // expected-error 
{{constant}} expected-note {{in call}}
 }
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wconstant-conversion"
+namespace GH64876 {
+void f() {
+  __builtin_strncmp(0, 0, 0x);
+  __builtin_memcmp(0, 0, 0x);
+  __builtin_bcmp(0, 0, 0x);
+  __builtin_wmemcmp(0, 0, 0x);
+  __builtin_memchr((const void*)0, 1, 0x);
+  __builtin_wmemchr((const wchar_t*)0, 1, 0x);
+
+  __builtin_strncmp(0, 0, -511LL);
+  __builtin_memcmp(0, 0, -511LL);
+  __builtin_bcmp(0, 0, -511LL);
+  __builtin_wmemcmp(0, 0, -511LL);
+  __builtin_memchr((const void*)0, 1, -511LL);
+  __builtin_wmemchr((const wchar_t*)0, 1, -511LL);
+}
+}
+#pragma clang diagnostic pop
Index: clang/test/CodeGen/gh64876.cpp
===
--- /dev/null
+++ clang/test/CodeGen/gh64876.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -disable-llvm-passes -o - %s | 
FileCheck %s
+
+void f(const char* C, const wchar_t *WC) {
+  int x1 = __builtin_strncmp(C, "b", 0x);
+// CHECK: {{.*}}= call i32 @strncmp{{.*}}i64 noundef -1
+  int x2 = __builtin_memcmp(C, "b", 0x);
+// CHECK: {{.*}}= call i32 @memcmp{{.*}}i64 noundef -1
+  int x3 = __builtin_bcmp(C, "b", 0x);
+// CHECK: {{.*}}= call i32 @bcmp{{.*}}i64 noundef -1
+  int x4 = __builtin_wmemcmp(WC, L"b", 0x);
+// CHECK: {{.*}}= call i32 @wmemcmp{{.*}}i64 noundef -1
+  auto x5 = __builtin_memchr(C, (int)'a', 0x);
+// CHECK: {{.*}}= call ptr @memchr{{.*}}i64 noundef -1
+  auto x6 = __builtin_wmemchr(WC, (int)'a', 0x);
+// CHECK: {{.*}}= call ptr @wmemchr{{.*}}i64 noundef -1
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -9361,7 +9361,7 @@
   APSInt N;
   if (!EvaluateInteger(E->getArg(2), N, Info))
 return false;
-  MaxLength = N.getExtValue();
+  MaxLength = N.getZExtValue();
 }
 // We cannot find the value if there are no candidates to match against.
 if (MaxLength == 0u)
@@ -12385,7 +12385,7 @@
   APSInt N;
   if (!EvaluateInteger(E->getArg(2), N, Info))
 return false;
-  MaxLength = N.getExtValue();
+  MaxLength = N.getZExtValue();
 }
 
 // Empty substrings compare equal by definition.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -179,6 +179,9 @@
 - Clang now prints unnamed members in diagnostic messages instead of giving an
   empty ''. Fixes
   (`#63759 `_)
+- Fix crash in __builtin_strncmp and related builtins when the size value
+  exceeded the maximum value representable by int64_t. Fixes
+  (`#64876 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/constexpr-string.cpp
===
--- clang/test/SemaCXX/constexpr-string.cpp
+++ clang/test/SemaCXX/constexpr-string.cpp
@@ -676,3 +676,24 @@
   }
   static_assert(test_address_of_incomplete_struct_type()); // expected-error {{constant}} expected-note {{in call}}
 }
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wconstant-conversion"
+namespace GH64876 {
+void f() {
+  __builtin_strncmp(0, 0, 0x);
+  __builtin_memcmp(0, 0, 0x);
+  __builtin_bcmp(0, 0, 0x);
+  __builtin_wmemcmp(0, 0, 0x);
+  __builtin_memchr((const void*)0, 1, 0x);
+  __builtin_wmemchr((const wchar_t*)0, 1, 0x);
+
+  __builtin_strncmp(0, 0, -511LL);
+  __builtin_memcmp(0, 0, -511LL);
+  __builtin_bcmp(0, 0, -511LL);
+  __builtin_wmemcmp(0, 0, -511LL);
+  __builtin_memchr((const void*)0, 1, -511LL);
+  __builtin_wmemchr((const wchar_t*)0, 1, -511LL);
+}
+}
+#pragma clang diagnostic pop
Index: clang/test/CodeGen/gh64876.cpp
===
--- /dev/null
+++ cl

[PATCH] D158842: [include-cleaner] Handle decls/refs to concepts.

2023-08-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I think we're not *that* far away from landing the AST change, and changing 
RecursiveASTVisitor now is probably confusing and not worth the churn.
So I'd prefer to wait for now...




Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:240
+
+  bool TraverseConceptReference(const ConceptReference &C) {
+report(C.getConceptNameLoc(), C.getFoundDecl());

after D155858 this can be VisitConceptReference



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:217
+void $2^func2() requires $Bar4^Bar {}
+  )cpp");
+  Inputs.Code = Code.code();

to complete the set I think you want

`void foo(Bar auto x)` (abbreviated template param) and `Bar auto x = 1` 
(deduced type).

Though these may not pass yet


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158842

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


[PATCH] D158572: [clang][modules] Use relative offsets for input files

2023-08-25 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D158572#4615234 , @phosek wrote:

> In D158572#4615231 , @jansvoboda11 
> wrote:
>
>> @phosek BTW can you confirm whether these started failing with this patch or 
>> with D158573 ?
>
> I'm trying to do a local build now to find out.

Looks like it was D158573  so it should be 
safe to reland this, sorry about the confusion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158572

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


[PATCH] D153152: Adds tweak to add declarations for pure virtuals

2023-08-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D153152#4617391 , @robot wrote:

>> so you could replace the logic that prints the return type + arg list with 
>> `printType(functype, class, methodname)` (from AST.h). That should pick up 
>> noexcept etc.
>
> I've tried it and it's not obvious to me how to do it properly: Since 
> `printType` wants to print the _function type_, it will parenthesize the 
> placeholder (methodname):
>
>   void (foo)()
>
> I've tried adding a flag to `PrintingPolicy` to avoid parenthesizing the 
> name, but I wonder if adjusting a "type printer" to print a function 
> declaration is a clean design. Next problem I ran into is parameters: A type 
> printer does not need to concern itself with parameter names nor default 
> arguments:
>
>   void foo(int x = 0) = 0;
>   void foo(int) override;
>
> Shall I continue to pursue that path? Shall I adjust the type printer to be 
> able to print parameter names and default arguments?

Sorry, it does sound like I sent you down a bad path.
You *could* (no need for an option for parens, here we can detect that the 
placeholder isValidAsciiIdentifier), but entirely possible more things are 
broken still.

If you prefer the approach with copying the tokens, adding heuristics to patch 
them up as needed is maybe no worse than the alternatives.

(BTW, I don't think we want to copy default arguments - it's certainly not 
necessary, and not helpful in common cases where the function is only called 
through the base)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153152

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


[clang] 8cfe9d8 - [Driver] Remove remnant myriad pieces after Myriad.cpp removal

2023-08-25 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-08-25T13:29:10-07:00
New Revision: 8cfe9d8f2ad3a52ba7fd5841d3939aa810536e16

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

LOG: [Driver] Remove remnant myriad pieces after Myriad.cpp removal

after D104279 and D158706.

Added: 


Modified: 
clang/lib/Basic/Targets/Sparc.cpp
clang/lib/Driver/ToolChains/Arch/Sparc.cpp
clang/test/Driver/sparc-as.c
clang/test/Misc/target-invalid-cpu-note.c
clang/test/Preprocessor/predefined-arch-macros.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/Sparc.cpp 
b/clang/lib/Basic/Targets/Sparc.cpp
index 4548902ca12b9e..8b9e149037 100644
--- a/clang/lib/Basic/Targets/Sparc.cpp
+++ b/clang/lib/Basic/Targets/Sparc.cpp
@@ -93,12 +93,6 @@ static constexpr SparcCPUInfo CPUInfo[] = {
 {{"ma2480"}, SparcTargetInfo::CK_MYRIAD2480, SparcTargetInfo::CG_V8},
 {{"ma2485"}, SparcTargetInfo::CK_MYRIAD2485, SparcTargetInfo::CG_V8},
 {{"ma2x8x"}, SparcTargetInfo::CK_MYRIAD2x8x, SparcTargetInfo::CG_V8},
-// FIXME: the myriad2[.n] spellings are obsolete,
-// but a grace period is needed to allow updating dependent builds.
-{{"myriad2"}, SparcTargetInfo::CK_MYRIAD2x5x, SparcTargetInfo::CG_V8},
-{{"myriad2.1"}, SparcTargetInfo::CK_MYRIAD2100, SparcTargetInfo::CG_V8},
-{{"myriad2.2"}, SparcTargetInfo::CK_MYRIAD2x5x, SparcTargetInfo::CG_V8},
-{{"myriad2.3"}, SparcTargetInfo::CK_MYRIAD2x8x, SparcTargetInfo::CG_V8},
 {{"leon2"}, SparcTargetInfo::CK_LEON2, SparcTargetInfo::CG_V8},
 {{"at697e"}, SparcTargetInfo::CK_LEON2_AT697E, SparcTargetInfo::CG_V8},
 {{"at697f"}, SparcTargetInfo::CK_LEON2_AT697F, SparcTargetInfo::CG_V8},
@@ -160,72 +154,6 @@ void SparcV8TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   break;
 }
   }
-  if (getTriple().getVendor() == llvm::Triple::Myriad) {
-std::string MyriadArchValue, Myriad2Value;
-Builder.defineMacro("__sparc_v8__");
-Builder.defineMacro("__leon__");
-switch (CPU) {
-case CK_MYRIAD2100:
-  MyriadArchValue = "__ma2100";
-  Myriad2Value = "1";
-  break;
-case CK_MYRIAD2150:
-  MyriadArchValue = "__ma2150";
-  Myriad2Value = "2";
-  break;
-case CK_MYRIAD2155:
-  MyriadArchValue = "__ma2155";
-  Myriad2Value = "2";
-  break;
-case CK_MYRIAD2450:
-  MyriadArchValue = "__ma2450";
-  Myriad2Value = "2";
-  break;
-case CK_MYRIAD2455:
-  MyriadArchValue = "__ma2455";
-  Myriad2Value = "2";
-  break;
-case CK_MYRIAD2x5x:
-  Myriad2Value = "2";
-  break;
-case CK_MYRIAD2080:
-  MyriadArchValue = "__ma2080";
-  Myriad2Value = "3";
-  break;
-case CK_MYRIAD2085:
-  MyriadArchValue = "__ma2085";
-  Myriad2Value = "3";
-  break;
-case CK_MYRIAD2480:
-  MyriadArchValue = "__ma2480";
-  Myriad2Value = "3";
-  break;
-case CK_MYRIAD2485:
-  MyriadArchValue = "__ma2485";
-  Myriad2Value = "3";
-  break;
-case CK_MYRIAD2x8x:
-  Myriad2Value = "3";
-  break;
-default:
-  MyriadArchValue = "__ma2100";
-  Myriad2Value = "1";
-  break;
-}
-if (!MyriadArchValue.empty()) {
-  Builder.defineMacro(MyriadArchValue, "1");
-  Builder.defineMacro(MyriadArchValue + "__", "1");
-}
-if (Myriad2Value == "2") {
-  Builder.defineMacro("__ma2x5x", "1");
-  Builder.defineMacro("__ma2x5x__", "1");
-} else if (Myriad2Value == "3") {
-  Builder.defineMacro("__ma2x8x", "1");
-  Builder.defineMacro("__ma2x8x__", "1");
-}
-Builder.defineMacro("__myriad2__", Myriad2Value);
-Builder.defineMacro("__myriad2", Myriad2Value);
-  }
   if (getCPUGeneration(CPU) == CG_V9) {
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");

diff  --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp 
b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
index 11c9444fde2b17..22e583021515e5 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -63,10 +63,6 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
 .Case("ma2480", "-Aleon")
 .Case("ma2485", "-Aleon")
 .Case("ma2x8x", "-Aleon")
-.Case("myriad2", "-Aleon")
-.Case("myriad2.1", "-Aleon")
-.Case("myriad2.2", "-Aleon")
-.Case("myriad2.3", "-Aleon")
 .Case("leon2", "-Av8")
 .Case("at697e", "-Av8")
 .Case("at697f", "-Av8")

diff  --git a/clang/test/Driver/sparc-as.c b/clang/test/Driver/sparc-as.c
index dca78f52fc9a18..30b685434de200 100644
--- a/clang/test/Driver/sparc-as.c
+++ b/clang/test/Driver/sparc-as.c
@@ -120,22 +120,6 @@
 // RUN: -no-integrated-as --sysroot=%S/Inputs

[PATCH] D158872: [clang][ASTMatchers] Add a few type-related Matchers

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

LGTM.
Nothing fancy, looks straight forward.
You may want to wait for an Aaron Ballman opinion.




Comment at: clang/docs/LibASTMatchersReference.html:2454
+MatcherType>bitIntTypeMatcherBitIntType>...
+Matches _BitInt types.
+

Maybe: "Matches a fixed int type of a specified bitwidth."


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158872

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


[PATCH] D158787: [clang-tidy][readability] add Leading_upper_snake_case

2023-08-25 Thread Steven Lewis via Phabricator via cfe-commits
MasterCopy8GB updated this revision to Diff 553593.
MasterCopy8GB added a comment.

Combine readability-identifier-naming improvements in release notes


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

https://reviews.llvm.org/D158787

Files:
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-violation.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -49,7 +49,7 @@
 // RUN: readability-identifier-naming.StaticConstantCase: UPPER_CASE, \
 // RUN: readability-identifier-naming.StaticVariableCase: camelBack, \
 // RUN: readability-identifier-naming.StaticVariablePrefix: 's_', \
-// RUN: readability-identifier-naming.StructCase: lower_case, \
+// RUN: readability-identifier-naming.StructCase: Leading_upper_snake_case, \
 // RUN: readability-identifier-naming.TemplateParameterCase: UPPER_CASE, \
 // RUN: readability-identifier-naming.TemplateTemplateParameterCase: CamelCase, \
 // RUN: readability-identifier-naming.TemplateUsingCase: lower_case, \
@@ -513,9 +513,9 @@
 
 struct THIS___Structure {
 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 'THIS___Structure'
-// CHECK-FIXES: {{^}}struct this_structure {{{$}}
+// CHECK-FIXES: {{^}}struct This_structure {{{$}}
 THIS___Structure();
-// CHECK-FIXES: {{^}}this_structure();{{$}}
+// CHECK-FIXES: {{^}}This_structure();{{$}}
 
   union __MyUnion_is_wonderful__ {};
 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for union '__MyUnion_is_wonderful__'
@@ -524,7 +524,7 @@
 
 typedef THIS___Structure struct_type;
 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for typedef 'struct_type'
-// CHECK-FIXES: {{^}}typedef this_structure struct_type_t;{{$}}
+// CHECK-FIXES: {{^}}typedef This_structure struct_type_t;{{$}}
 
 struct_type GlobalTypedefTestFunction(struct_type a_argument1) {
 // CHECK-FIXES: {{^}}struct_type_t GlobalTypedefTestFunction(struct_type_t a_argument1) {
@@ -534,7 +534,7 @@
 
 using my_struct_type = THIS___Structure;
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type'
-// CHECK-FIXES: {{^}}using my_Struct_Type_t = this_structure;{{$}}
+// CHECK-FIXES: {{^}}using my_Struct_Type_t = This_structure;{{$}}
 
 template
 using SomeOtherTemplate = my_other_templated_class  <:: FOO_NS  ::my_class>;
@@ -596,6 +596,8 @@
 }
 
 template  struct a {
+// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: invalid case style for struct 'a'
+// CHECK-FIXES: {{^}}template  struct A {{{$}}
   typename t_t::template b<> c;
 
   char const MY_ConstMember_string[4] = "123";
@@ -609,9 +611,11 @@
 
 template
 char const a::MyConstClass_string[] = "123";
-// CHECK-FIXES: {{^}}char const a::kMyConstClassString[] = "123";{{$}}
+// CHECK-FIXES: {{^}}char const A::kMyConstClassString[] = "123";{{$}}
 
 template  class A> struct b { A c; };
+// CHECK-MESSAGES: :[[@LINE-1]]:47: warning: invalid case style for struct 'b'
+// CHECK-FIXES:template  class A> struct B { A c; };{{$}}
 
 unsigned MY_GLOBAL_array[] = {1,2,3};
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'MY_GLOBAL_array'
@@ -645,17 +649,17 @@
 // CHECK-FIXES: {{^}}using namespace foo_ns::inline_namespace;
 
 void QualifiedTypeLocTest(THIS___Structure);
-// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure);{{$}}
+// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(This_structure);{{$}}
 void QualifiedTypeLocTest(THIS___Structure &);
-// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure &);{{$}}
+// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(This_structure &);{{$}}
 void QualifiedTypeLocTest(THIS___Structure &&);
-// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure &&);{{$}}
+// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(This_structure &&);{{$}}
 void QualifiedTypeLocTest(const THIS___Structure);
-// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure);{{$}}
+// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const This_structure);{{$}}
 void QualifiedTypeLocTest(const THIS___Structure &);
-// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure &);{{$}}
+// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const This_structure &);{{$}}
 void QualifiedTypeLocTest(volatile THIS___Structure &);
-// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(volatile this_structure &);{{$}}

[PATCH] D158795: Fix AlignArrayOfStructures + Cpp11BracedListStyle=false

2023-08-25 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

> I'm not exactly sure why this function needs to override the Spaces as it 
> seems to generally already be set to either 0 or 1 according to the other 
> formatting settings

If so, can we address the issue without the "explicit fix"?




Comment at: clang/lib/Format/WhitespaceManager.cpp:1229
 
+  const auto BracePadding = Style.Cpp11BracedListStyle ? 0 : 1;
   auto &Cells = CellDescs.Cells;





Comment at: clang/lib/Format/WhitespaceManager.cpp:1247
 if (Previous && Previous->isNot(TT_LineComment)) {
-  Changes[Next->Index].Spaces = 0;
+  Changes[Next->Index].Spaces = BracePadding;
   Changes[Next->Index].NewlinesBefore = 0;

Can we assert that `Spaces == 0`? If not, we should add a test case.



Comment at: clang/lib/Format/WhitespaceManager.cpp:1303
 
+  const auto BracePadding = Style.Cpp11BracedListStyle ? 0 : 1;
   auto &Cells = CellDescs.Cells;

Ditto.



Comment at: clang/unittests/Format/FormatTest.cpp:20888
+   "  {  7, 5,\"!!\" }\n"
+   "};\n",
+   Style);





Comment at: clang/unittests/Format/FormatTest.cpp:21130
+   "  { 7,  5, \"!!\"}\n"
+   "};\n",
+   Style);

Ditto.


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

https://reviews.llvm.org/D158795

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


[PATCH] D158820: [Sema][HLSL] Fix naming of anyhit/closesthit shaders

2023-08-25 Thread Justin Bogner via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG43a9b92d79ab: [Sema][HLSL] Fix naming of anyhit/closesthit 
shaders (authored by bogner).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158820

Files:
  clang/include/clang/Basic/Attr.td
  clang/test/SemaHLSL/entry_shader.hlsl
  clang/test/SemaHLSL/shader_type_attr.hlsl
  clang/test/SemaHLSL/valid-shader-stages.hlsl

Index: clang/test/SemaHLSL/valid-shader-stages.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/valid-shader-stages.hlsl
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -finclude-default-header -o - %s -verify
+
+// expected-no-diagnostics
+
+[shader("pixel")] void pixel() {}
+[shader("vertex")] void vertex() {}
+[shader("raygeneration")] void raygeneration() {}
+[shader("intersection")] void intersection() {}
+
+[numthreads(1,1,1)][shader("compute")] void compute() {}
+[numthreads(1,1,1)][shader("mesh")] void mesh() {}
+
+// Note: the rest of these have additional constraints that aren't implemented
+// yet, so here we just declare them to make sure the spelling works and
+// whatnot.
+[shader("geometry")] void geometry();
+[shader("hull")] void hull();
+[shader("domain")] void domain();
+[shader("callable")] void callable();
+[shader("closesthit")] void closesthit();
+[shader("anyhit")] void anyhit();
+[shader("miss")] void miss();
+
+[numthreads(1,1,1)][shader("amplification")] void amplification();
Index: clang/test/SemaHLSL/shader_type_attr.hlsl
===
--- clang/test/SemaHLSL/shader_type_attr.hlsl
+++ clang/test/SemaHLSL/shader_type_attr.hlsl
@@ -28,7 +28,7 @@
 } // namespace spec
 
 // expected-error@+1 {{'shader' attribute parameters do not match the previous declaration}}
-[shader("compute")]
+[shader("pixel")]
 // expected-note@+1 {{conflicting attribute is here}}
 [shader("vertex")]
 int doubledUp() {
@@ -40,7 +40,7 @@
 int forwardDecl();
 
 // expected-error@+1 {{'shader' attribute parameters do not match the previous declaration}}
-[shader("compute")]
+[shader("compute")][numthreads(8,1,1)]
 int forwardDecl() {
   return 1;
 }
@@ -57,19 +57,22 @@
 [shader("library")]
 #endif // END of FAIL
 
-// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
-[shader("compute")]
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}}  8 1 1
+[shader("compute")][numthreads(8,1,1)]
 int entry() {
   return 1;
 }
 
 // Because these two attributes match, they should both appear in the AST
-[shader("compute")]
-// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+[shader("compute")][numthreads(8,1,1)]
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}}  8 1 1
 int secondFn();
 
-[shader("compute")]
-// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+[shader("compute")][numthreads(8,1,1)]
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}}  8 1 1
 int secondFn() {
   return 1;
 }
Index: clang/test/SemaHLSL/entry_shader.hlsl
===
--- clang/test/SemaHLSL/entry_shader.hlsl
+++ clang/test/SemaHLSL/entry_shader.hlsl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry foo  -o - %s -DSHADER='"anyHit"' -verify
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry foo  -o - %s -DSHADER='"mesh"' -verify
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry foo  -o - %s -DSHADER='"compute"'
 
 // expected-error@+1 {{'shader' attribute on entry function does not match the target profile}}
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -4143,8 +4143,8 @@
 EnumArgument<"Type", "ShaderType",
  [
"pixel", "vertex", "geometry", "hull", "domain", "compute",
-   "library", "raygeneration", "intersection", "anyHit",
-   "closestHit", "miss", "callable", "mesh", "amplification"
+   "library", "raygeneration", "intersection", "anyhit",
+   "closesthit", "miss", "callable", "mesh", "amplification"
  ],
  [
"Pixel", "Vertex", "Geometry", "Hull", "Domain", "Compute",
@@ -4232,4 +4232,3 @@
   let Subjects = SubjectList<[TypedefName], ErrorDiag>;
   let Documentation = [Undocumented];
 }
-
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 43a9b92 - [Sema][HLSL] Fix naming of anyhit/closesthit shaders

2023-08-25 Thread Justin Bogner via cfe-commits

Author: Justin Bogner
Date: 2023-08-25T13:08:36-07:00
New Revision: 43a9b92d79ab6a59c3cfaa926bb32f161ef2facc

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

LOG: [Sema][HLSL] Fix naming of anyhit/closesthit shaders

Also test all shader types and be a bit more careful to make shaders
reasonably valid in these tests.

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

Added: 
clang/test/SemaHLSL/valid-shader-stages.hlsl

Modified: 
clang/include/clang/Basic/Attr.td
clang/test/SemaHLSL/entry_shader.hlsl
clang/test/SemaHLSL/shader_type_attr.hlsl

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8623bf1bb87b77..f7d19a3df25176 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4143,8 +4143,8 @@ def HLSLShader : InheritableAttr {
 EnumArgument<"Type", "ShaderType",
  [
"pixel", "vertex", "geometry", "hull", "domain", "compute",
-   "library", "raygeneration", "intersection", "anyHit",
-   "closestHit", "miss", "callable", "mesh", "amplification"
+   "library", "raygeneration", "intersection", "anyhit",
+   "closesthit", "miss", "callable", "mesh", "amplification"
  ],
  [
"Pixel", "Vertex", "Geometry", "Hull", "Domain", "Compute",
@@ -4232,4 +4232,3 @@ def AvailableOnlyInDefaultEvalMethod : InheritableAttr {
   let Subjects = SubjectList<[TypedefName], ErrorDiag>;
   let Documentation = [Undocumented];
 }
-

diff  --git a/clang/test/SemaHLSL/entry_shader.hlsl 
b/clang/test/SemaHLSL/entry_shader.hlsl
index 75279f5e562d70..0ed6c0c9d417ec 100644
--- a/clang/test/SemaHLSL/entry_shader.hlsl
+++ b/clang/test/SemaHLSL/entry_shader.hlsl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"anyHit"' -verify
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"mesh"' -verify
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"compute"'
 
 // expected-error@+1 {{'shader' attribute on entry function does not match the 
target profile}}

diff  --git a/clang/test/SemaHLSL/shader_type_attr.hlsl 
b/clang/test/SemaHLSL/shader_type_attr.hlsl
index 2582aaad2907c8..d497b0582d1a72 100644
--- a/clang/test/SemaHLSL/shader_type_attr.hlsl
+++ b/clang/test/SemaHLSL/shader_type_attr.hlsl
@@ -28,7 +28,7 @@ static void oops() {}
 } // namespace spec
 
 // expected-error@+1 {{'shader' attribute parameters do not match the previous 
declaration}}
-[shader("compute")]
+[shader("pixel")]
 // expected-note@+1 {{conflicting attribute is here}}
 [shader("vertex")]
 int doubledUp() {
@@ -40,7 +40,7 @@ int doubledUp() {
 int forwardDecl();
 
 // expected-error@+1 {{'shader' attribute parameters do not match the previous 
declaration}}
-[shader("compute")]
+[shader("compute")][numthreads(8,1,1)]
 int forwardDecl() {
   return 1;
 }
@@ -57,19 +57,22 @@ int forwardDecl() {
 [shader("library")]
 #endif // END of FAIL
 
-// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
-[shader("compute")]
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}}  8 1 1
+[shader("compute")][numthreads(8,1,1)]
 int entry() {
   return 1;
 }
 
 // Because these two attributes match, they should both appear in the AST
-[shader("compute")]
-// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+[shader("compute")][numthreads(8,1,1)]
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}}  8 1 1
 int secondFn();
 
-[shader("compute")]
-// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+[shader("compute")][numthreads(8,1,1)]
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}}  8 1 1
 int secondFn() {
   return 1;
 }

diff  --git a/clang/test/SemaHLSL/valid-shader-stages.hlsl 
b/clang/test/SemaHLSL/valid-shader-stages.hlsl
new file mode 100644
index 00..523500c77c0abf
--- /dev/null
+++ b/clang/test/SemaHLSL/valid-shader-stages.hlsl
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl 
-finclude-default-header -o - %s -verify
+
+// expected-no-diagnostics
+
+[shader("pixel")] void pixel() {}
+[shader("vertex")] void vertex() {}
+[shader("raygeneration")] void raygeneration() {}
+[shader("intersection")] void intersection() {}
+
+[numthreads(1,1,1)][shader("compute")] void compute() {}
+[numthreads(1,1,1)][shader("mesh")] void mesh() {}
+
+// Note: the rest of these have additional constraints that aren't implemented
+// yet, so here we just d

[PATCH] D158787: [clang-tidy][readability] add Leading_upper_snake_case

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

After you update release notes entry, it could land...


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

https://reviews.llvm.org/D158787

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


[PATCH] D158787: [clang-tidy][readability] add Leading_upper_snake_case

2023-08-25 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:240-245
   ` check to emit proper
   warnings when a type forward declaration precedes its definition.
 
+- Improved :doc:`readability-identifier-naming
+  ` allow for
+  ``Leading_upper_snake_case`` naming convention.

There is already entry for this check, so just add it to previous:

```
warnings when a type forward declaration precedes its definition and
added support for ``Leading_upper_snake_case`` naming convention.
```


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

https://reviews.llvm.org/D158787

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


[PATCH] D158873: [clangd] Do not ignore qualifier in heuristic resolution of dependent MemberExpr

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

Oh, this is surprising!




Comment at: clang-tools-extra/clangd/HeuristicResolver.cpp:142
+// Do not proceed to try resolving the member in the expression's base type
+// without regard to the qualifier, as that could produce incorrect 
results.
+return {};

I think the pattern from the testcase clarifies enough to be worth an extra line

> `void foo() { this->Base::foo(); }` shouldn't resolve to foo() itself!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158873

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


[PATCH] D158820: [Sema][HLSL] Fix naming of anyhit/closesthit shaders

2023-08-25 Thread Justin Bogner via Phabricator via cfe-commits
bogner updated this revision to Diff 553588.
bogner added a comment.

Address feedback and simplify valid shader stage test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158820

Files:
  clang/include/clang/Basic/Attr.td
  clang/test/SemaHLSL/entry_shader.hlsl
  clang/test/SemaHLSL/shader_type_attr.hlsl
  clang/test/SemaHLSL/valid-shader-stages.hlsl

Index: clang/test/SemaHLSL/valid-shader-stages.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/valid-shader-stages.hlsl
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -finclude-default-header -o - %s -verify
+
+// expected-no-diagnostics
+
+[shader("pixel")] void pixel() {}
+[shader("vertex")] void vertex() {}
+[shader("raygeneration")] void raygeneration() {}
+[shader("intersection")] void intersection() {}
+
+[numthreads(1,1,1)][shader("compute")] void compute() {}
+[numthreads(1,1,1)][shader("mesh")] void mesh() {}
+
+// Note: the rest of these have additional constraints that aren't implemented
+// yet, so here we just declare them to make sure the spelling works and
+// whatnot.
+[shader("geometry")] void geometry();
+[shader("hull")] void hull();
+[shader("domain")] void domain();
+[shader("callable")] void callable();
+[shader("closesthit")] void closesthit();
+[shader("anyhit")] void anyhit();
+[shader("miss")] void miss();
+
+[numthreads(1,1,1)][shader("amplification")] void amplification();
Index: clang/test/SemaHLSL/shader_type_attr.hlsl
===
--- clang/test/SemaHLSL/shader_type_attr.hlsl
+++ clang/test/SemaHLSL/shader_type_attr.hlsl
@@ -28,7 +28,7 @@
 } // namespace spec
 
 // expected-error@+1 {{'shader' attribute parameters do not match the previous declaration}}
-[shader("compute")]
+[shader("pixel")]
 // expected-note@+1 {{conflicting attribute is here}}
 [shader("vertex")]
 int doubledUp() {
@@ -40,7 +40,7 @@
 int forwardDecl();
 
 // expected-error@+1 {{'shader' attribute parameters do not match the previous declaration}}
-[shader("compute")]
+[shader("compute")][numthreads(8,1,1)]
 int forwardDecl() {
   return 1;
 }
@@ -57,19 +57,22 @@
 [shader("library")]
 #endif // END of FAIL
 
-// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
-[shader("compute")]
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}}  8 1 1
+[shader("compute")][numthreads(8,1,1)]
 int entry() {
   return 1;
 }
 
 // Because these two attributes match, they should both appear in the AST
-[shader("compute")]
-// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+[shader("compute")][numthreads(8,1,1)]
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}}  8 1 1
 int secondFn();
 
-[shader("compute")]
-// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+[shader("compute")][numthreads(8,1,1)]
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}}  8 1 1
 int secondFn() {
   return 1;
 }
Index: clang/test/SemaHLSL/entry_shader.hlsl
===
--- clang/test/SemaHLSL/entry_shader.hlsl
+++ clang/test/SemaHLSL/entry_shader.hlsl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry foo  -o - %s -DSHADER='"anyHit"' -verify
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry foo  -o - %s -DSHADER='"mesh"' -verify
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry foo  -o - %s -DSHADER='"compute"'
 
 // expected-error@+1 {{'shader' attribute on entry function does not match the target profile}}
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -4143,8 +4143,8 @@
 EnumArgument<"Type", "ShaderType",
  [
"pixel", "vertex", "geometry", "hull", "domain", "compute",
-   "library", "raygeneration", "intersection", "anyHit",
-   "closestHit", "miss", "callable", "mesh", "amplification"
+   "library", "raygeneration", "intersection", "anyhit",
+   "closesthit", "miss", "callable", "mesh", "amplification"
  ],
  [
"Pixel", "Vertex", "Geometry", "Hull", "Domain", "Compute",
@@ -4232,4 +4232,3 @@
   let Subjects = SubjectList<[TypedefName], ErrorDiag>;
   let Documentation = [Undocumented];
 }
-
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158671: [NFC][Clang] Fix static analyzer concerns

2023-08-25 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG847186eb94bd: [NFC][Clang] Fix static analyzer concern 
(authored by eandrews).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158671

Files:
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp


Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5062,6 +5062,7 @@
 } IR{*this, PatternRec, NewRec};
 
 TypeSourceInfo *NewSI = IR.TransformType(Function->getTypeSourceInfo());
+assert(NewSI && "Type Transform failed?");
 Function->setType(NewSI->getType());
 Function->setTypeSourceInfo(NewSI);
 
Index: clang/lib/ExtractAPI/DeclarationFragments.cpp
===
--- clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -688,9 +688,9 @@
 const CXXMethodDecl *Method) {
   DeclarationFragments Fragments;
   std::string Name;
-  if (isa(Method)) {
+  if (const auto *Constructor = dyn_cast(Method)) {
 Name = Method->getNameAsString();
-if (dyn_cast(Method)->isExplicit())
+if (Constructor->isExplicit())
   Fragments.append("explicit", DeclarationFragments::FragmentKind::Keyword)
   .appendSpace();
   } else if (isa(Method))
Index: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
===
--- clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -266,7 +266,9 @@
 
   if (Decl->isStaticDataMember()) {
 SymbolReference Context;
-auto Record = dyn_cast(Decl->getDeclContext());
+// getDeclContext() should return a RecordDecl since we
+// are currently handling a static data member.
+auto *Record = cast(Decl->getDeclContext());
 Context.Name = Record->getName();
 Context.USR = API.recordUSR(Record);
 auto Access = DeclarationFragmentsBuilder::getAccessControl(Decl);


Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5062,6 +5062,7 @@
 } IR{*this, PatternRec, NewRec};
 
 TypeSourceInfo *NewSI = IR.TransformType(Function->getTypeSourceInfo());
+assert(NewSI && "Type Transform failed?");
 Function->setType(NewSI->getType());
 Function->setTypeSourceInfo(NewSI);
 
Index: clang/lib/ExtractAPI/DeclarationFragments.cpp
===
--- clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -688,9 +688,9 @@
 const CXXMethodDecl *Method) {
   DeclarationFragments Fragments;
   std::string Name;
-  if (isa(Method)) {
+  if (const auto *Constructor = dyn_cast(Method)) {
 Name = Method->getNameAsString();
-if (dyn_cast(Method)->isExplicit())
+if (Constructor->isExplicit())
   Fragments.append("explicit", DeclarationFragments::FragmentKind::Keyword)
   .appendSpace();
   } else if (isa(Method))
Index: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
===
--- clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -266,7 +266,9 @@
 
   if (Decl->isStaticDataMember()) {
 SymbolReference Context;
-auto Record = dyn_cast(Decl->getDeclContext());
+// getDeclContext() should return a RecordDecl since we
+// are currently handling a static data member.
+auto *Record = cast(Decl->getDeclContext());
 Context.Name = Record->getName();
 Context.USR = API.recordUSR(Record);
 auto Access = DeclarationFragmentsBuilder::getAccessControl(Decl);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 847186e - [NFC][Clang] Fix static analyzer concern

2023-08-25 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-08-25T13:03:06-07:00
New Revision: 847186eb94bd8c3535f0384456eeffe85f1d9696

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

LOG: [NFC][Clang] Fix static analyzer concern

Fix a few static analyzer concerns about dereferencing
null value.

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

Added: 


Modified: 
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h 
b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
index 17c2ab6fd20501..84ea8e2f7ce385 100644
--- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -266,7 +266,9 @@ bool ExtractAPIVisitorBase::VisitVarDecl(const 
VarDecl *Decl) {
 
   if (Decl->isStaticDataMember()) {
 SymbolReference Context;
-auto Record = dyn_cast(Decl->getDeclContext());
+// getDeclContext() should return a RecordDecl since we
+// are currently handling a static data member.
+auto *Record = cast(Decl->getDeclContext());
 Context.Name = Record->getName();
 Context.USR = API.recordUSR(Record);
 auto Access = DeclarationFragmentsBuilder::getAccessControl(Decl);

diff  --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp 
b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index 3c15d5073b01eb..5c5a9df6505271 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -688,9 +688,9 @@ 
DeclarationFragmentsBuilder::getFragmentsForSpecialCXXMethod(
 const CXXMethodDecl *Method) {
   DeclarationFragments Fragments;
   std::string Name;
-  if (isa(Method)) {
+  if (const auto *Constructor = dyn_cast(Method)) {
 Name = Method->getNameAsString();
-if (dyn_cast(Method)->isExplicit())
+if (Constructor->isExplicit())
   Fragments.append("explicit", DeclarationFragments::FragmentKind::Keyword)
   .appendSpace();
   } else if (isa(Method))

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index f78d46f5950360..63f022d5c2ff09 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5062,6 +5062,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 } IR{*this, PatternRec, NewRec};
 
 TypeSourceInfo *NewSI = IR.TransformType(Function->getTypeSourceInfo());
+assert(NewSI && "Type Transform failed?");
 Function->setType(NewSI->getType());
 Function->setTypeSourceInfo(NewSI);
 



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


[PATCH] D158869: [clang] Fix timing of propagation of MSInheritanceAttr for template instantiation declarations.

2023-08-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:10112
+  Specialization->addAttr(PrevDecl->getAttr());
+  Consumer.AssignInheritanceModel(Specialization);
+}

tahonermann wrote:
> I am concerned that moving the call to `Consumer.AssignInheritanceModel()` to 
> immediately after the creation of the node, but before it is populated might 
> be problematic. Previously, this call was still made before the node was 
> completely constructed (e.g., before `setTemplateSpecializationKind()` is 
> called for it). It is difficult to tell if any consumers might be dependent 
> on more of the definition being present. 
SO I think we still need to do this off of the definition, right?  Else if 
`PrevDecl` ends up being a declaration (followed later by a definition that has 
the attribute), we'll end up missing it?  Typically attributes are 'added' by 
later decls, so only the 'latest one' (though attributes can't be added after 
definition IIRC) has 'them all'.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158869

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


[PATCH] D158820: [Sema][HLSL] Fix naming of anyhit/closesthit shaders

2023-08-25 Thread Justin Bogner via Phabricator via cfe-commits
bogner added inline comments.



Comment at: clang/test/SemaHLSL/entry_shader.hlsl:1
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"anyHit"' -verify
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"mesh"' -verify
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"compute"'

bob80905 wrote:
> Why was this changed to mesh instead of "anyhit" ?
Another case of trying to keep things to one error - `anyhit` doesn't support 
the `numthreads` attribute



Comment at: clang/test/SemaHLSL/shader_type_attr.hlsl:30
 
 // expected-error@+1 {{'shader' attribute parameters do not match the previous 
declaration}}
+[shader("pixel")]

beanz wrote:
> bob80905 wrote:
> > bogner wrote:
> > > bob80905 wrote:
> > > > I don't think we should expect this error, given that there is no 
> > > > previous declaration for doubledUp(). Maybe something else like %0 and 
> > > > %1 are incompatible attributes? 
> > > I don't necessarily disagree, but if we're going to change that I think 
> > > it should be in a different change than this one.
> > I'm also curious, why is the change from compute to pixel necessary here?
> I suspect this change is just to prevent the presence of the `compute` 
> annotation from triggering the `missing numthreads` error.
That's correct - just trying to keep to testing the conflicting attribute error 
and not have a spurious numthreads as well.



Comment at: clang/test/SemaHLSL/shader_type_attr.hlsl:61
 // CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
-[shader("compute")]
+[shader("compute"), numthreads(8,1,1)]
 int entry() {

beanz wrote:
> Oh interesting! DXC doesn't actually support this syntax, but I think it is 
> worth supporting in Clang.
> Should we also check for the numthreads attribute?
Hm, it might be better to stick to the syntax dxc handles for these tests at 
least. I'll update that. Sure, checking both attributes seems like a good idea.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158820

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


[PATCH] D148131: Avoid unnecessarily aggressive line-breaking when using "LambdaBodyIndentation: OuterScope" with argument bin-packing.

2023-08-25 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:169
 all arguments being able to fit on the same line.
+- Avoid unnecessarily aggressive line-breaking when using
+  ``LambdaBodyIndentation: OuterScope`` with argument bin-packing.

Owens comment holds, no bug fix in release notes.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1077
+  if (!NestedBlockSpecialCase) {
+auto ParentLevelIt = State.Stack.rbegin() + 1;
+if (Style.LambdaBodyIndentation == FormatStyle::LBI_OuterScope &&

I don't know if LLVM has any policy in this regard, but I prefer this.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1100
+  auto MaybeIncrement = [&](const auto &It) {
+return It != State.Stack.rend() ? (It + 1) : It;
+  };

see above



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1107
+}
+if (ParentLevelIt != State.Stack.rend())
+  for (auto It = ParentLevelIt; It != State.Stack.rend(); ++It)

Drop the if, the loop does the checking.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1108-1109
+if (ParentLevelIt != State.Stack.rend())
+  for (auto It = ParentLevelIt; It != State.Stack.rend(); ++It)
+It->BreakBeforeParameter = true;
+  }

Would be consistent with the code base.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1123
+  // because we have been forced to break before a lambda body.
+  !(Style.BraceWrapping.BeforeLambdaBody && Current.is(TT_LambdaLBrace))) {
 CurrentState.BreakBeforeParameter = true;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148131

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


[PATCH] D158873: [clangd] Do not ignore qualifier in heuristic resolution of dependent MemberExpr

2023-08-25 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

https://github.com/llvm/llvm-project/issues/64841


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158873

Files:
  clang-tools-extra/clangd/HeuristicResolver.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1004,7 +1004,17 @@
 void play(Dog *dog) {
   [dog ho^wl];
 }
-  )objc"};
+  )objc",
+  R"cpp(
+struct PointerIntPairInfo {
+  static void *getPointer(void *Value);
+};
+
+template  struct PointerIntPair {
+  void *Value;
+  void *getPointer() const { return Info::get^Pointer(Value); }
+};
+)cpp"};
   for (const char *Test : Tests) {
 Annotations T(Test);
 std::optional WantDecl;
Index: clang-tools-extra/clangd/HeuristicResolver.cpp
===
--- clang-tools-extra/clangd/HeuristicResolver.cpp
+++ clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -119,8 +119,8 @@
 
 std::vector HeuristicResolver::resolveMemberExpr(
 const CXXDependentScopeMemberExpr *ME) const {
-  // If the expression has a qualifier, first try resolving the member
-  // inside the qualifier's type.
+  // If the expression has a qualifier, try resolving the member inside the
+  // qualifier's type.
   // Note that we cannot use a NonStaticFilter in either case, for a couple
   // of reasons:
   //   1. It's valid to access a static member using instance member syntax,
@@ -137,10 +137,13 @@
   if (!Decls.empty())
 return Decls;
 }
+
+// Do not proceed to try resolving the member in the expression's base type
+// without regard to the qualifier, as that could produce incorrect 
results.
+return {};
   }
 
-  // If that didn't yield any results, try resolving the member inside
-  // the expression's base type.
+  // Try resolving the member inside the expression's base type.
   const Type *BaseType = ME->getBaseType().getTypePtrOrNull();
   if (ME->isArrow()) {
 BaseType = getPointeeType(BaseType);


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1004,7 +1004,17 @@
 void play(Dog *dog) {
   [dog ho^wl];
 }
-  )objc"};
+  )objc",
+  R"cpp(
+struct PointerIntPairInfo {
+  static void *getPointer(void *Value);
+};
+
+template  struct PointerIntPair {
+  void *Value;
+  void *getPointer() const { return Info::get^Pointer(Value); }
+};
+)cpp"};
   for (const char *Test : Tests) {
 Annotations T(Test);
 std::optional WantDecl;
Index: clang-tools-extra/clangd/HeuristicResolver.cpp
===
--- clang-tools-extra/clangd/HeuristicResolver.cpp
+++ clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -119,8 +119,8 @@
 
 std::vector HeuristicResolver::resolveMemberExpr(
 const CXXDependentScopeMemberExpr *ME) const {
-  // If the expression has a qualifier, first try resolving the member
-  // inside the qualifier's type.
+  // If the expression has a qualifier, try resolving the member inside the
+  // qualifier's type.
   // Note that we cannot use a NonStaticFilter in either case, for a couple
   // of reasons:
   //   1. It's valid to access a static member using instance member syntax,
@@ -137,10 +137,13 @@
   if (!Decls.empty())
 return Decls;
 }
+
+// Do not proceed to try resolving the member in the expression's base type
+// without regard to the qualifier, as that could produce incorrect results.
+return {};
   }
 
-  // If that didn't yield any results, try resolving the member inside
-  // the expression's base type.
+  // Try resolving the member inside the expression's base type.
   const Type *BaseType = ME->getBaseType().getTypePtrOrNull();
   if (ME->isArrow()) {
 BaseType = getPointeeType(BaseType);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158872: [clang][ASTMatchers] Add a few type-related Matchers

2023-08-25 Thread Ding Fei via Phabricator via cfe-commits
danix800 created this revision.
Herald added a subscriber: ChuanqiXu.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add a few type-related Matchers

- bitIntType
- constantMatrixType
- dependentAddressSpaceType
- dependentBitIntType
- dependentSizedMatrixType
- dependentVectorType
- hasTypeForDecl
- objcTypeParamDecl
- objcTypeParamType
- pipeType
- vectorType


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158872

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTest.h

Index: clang/unittests/ASTMatchers/ASTMatchersTest.h
===
--- clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -284,6 +284,33 @@
   {"-fopenmp=libomp", "-fopenmp-version=51"});
 }
 
+template 
+testing::AssertionResult matchesOpenCL(const Twine &Code, const T &AMatcher) {
+  return matchesConditionally(Code, AMatcher, true,
+  {"-x", "cl", "-cl-no-stdinc", "-cl-std=CL2.0"},
+  FileContentMappings(), "input.cl");
+}
+
+template 
+testing::AssertionResult notMatchesOpenCL(const Twine &Code,
+  const T &AMatcher) {
+  return matchesConditionally(Code, AMatcher, false,
+  {"-x", "cl", "-cl-no-stdinc", "-cl-std=CL2.0"},
+  FileContentMappings(), "input.cl");
+}
+
+template 
+testing::AssertionResult matchesWithMatrixEnabled(const Twine &Code,
+  const T &AMatcher) {
+  return matchesConditionally(Code, AMatcher, true, {"-fenable-matrix"});
+}
+
+template 
+testing::AssertionResult notMatchesWithMatrixEnabled(const Twine &Code,
+ const T &AMatcher) {
+  return matchesConditionally(Code, AMatcher, false, {"-fenable-matrix"});
+}
+
 template 
 testing::AssertionResult matchAndVerifyResultConditionally(
 const Twine &Code, const T &AMatcher,
Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1549,6 +1549,89 @@
   EXPECT_TRUE(matches("struct S {};", qualType().bind("loc")));
 }
 
+TEST_P(ASTMatchersTest, BitIntType) {
+  StringRef code = "_BitInt(10) i;";
+  EXPECT_TRUE(matches(code, varDecl(hasType(bitIntType();
+  EXPECT_TRUE(notMatches(code, varDecl(hasType(builtinType();
+}
+
+TEST_P(ASTMatchersTest, ConstantMatrixType) {
+  StringRef Code = "typedef int __attribute__((matrix_type(5, 5))) X;";
+
+  EXPECT_TRUE(matchesWithMatrixEnabled(
+  Code, typedefDecl(hasType(constantMatrixType();
+  EXPECT_TRUE(
+  notMatchesWithMatrixEnabled(Code, typedefDecl(hasType(vectorType();
+}
+
+TEST_P(ASTMatchersTest, DependentAddressSpaceType) {
+  if (!GetParam().isCXX())
+return;
+
+  StringRef Code = "template"
+   "class vector {"
+   "  typedef T __attribute__((address_space(AddrSpace))) X;"
+   "};";
+  EXPECT_TRUE(matches(Code, typedefDecl(hasType(dependentAddressSpaceType();
+
+  EXPECT_TRUE(notMatches("int __attribute__((address_space(0))) X;",
+ typedefDecl(hasType(dependentAddressSpaceType();
+}
+
+TEST_P(ASTMatchersTest, DependentBitIntType) {
+  if (!GetParam().isCXX11OrLater())
+return;
+
+  EXPECT_TRUE(matches("template using X = _BitInt(Width);",
+  typeAliasDecl(hasType(dependentBitIntType();
+
+  EXPECT_TRUE(notMatches("typedef _BitInt(10) Int10;",
+ typedefDecl(hasType(dependentBitIntType();
+}
+
+TEST_P(ASTMatchersTest, DependentVectorType) {
+  if (!GetParam().isCXX())
+return;
+
+  StringRef DepCode = "template"
+  "class vector {"
+  "  typedef T __attribute__((vector_size(Size))) X;"
+  "};";
+  EXPECT_TRUE(matches(DepCode, dependentVectorType()));
+
+  StringRef NonDepCode = "typedef int __attribute__((vector_size(16))) X;";
+  EXPECT_TRUE(notMatches(NonDepCode, dependentVectorType()));
+}
+
+TEST_P(ASTMatchersTest, VectorType) {
+  if (!GetParam().isCXX())
+return;
+
+  StringRef NonDepCode = "typedef int __attribute__((vector_size(16))) X;";
+  EXPECT_TRUE(matches(NonDepCode, vectorType()));
+
+  StringRef DepCode = "template"
+  "class vector {"
+  "  typedef T __attribut

[PATCH] D158822: [Fuchsia] Make __start_* / __stop_* symbols hidden

2023-08-25 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG53ee31c9871d: [Fuchsia] Make __start_* / __stop_* symbols 
hidden (authored by phosek).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158822

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/test/Driver/fuchsia.c
  clang/test/Driver/fuchsia.cpp


Index: clang/test/Driver/fuchsia.cpp
===
--- clang/test/Driver/fuchsia.cpp
+++ clang/test/Driver/fuchsia.cpp
@@ -40,7 +40,7 @@
 // CHECK-RISCV64: "-internal-isystem" 
"{{.*[/\\]}}include{{/|}}riscv64-unknown-fuchsia{{/|}}c++{{/|}}v1"
 // CHECK: "-internal-isystem" "{{.*[/\\]}}include{{/|}}c++{{/|}}v1"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "now" "-z" "rodynamic" "-z" 
"separate-loadable-segments"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "now" "-z" "start-stop-visibility=hidden" 
"-z" "rodynamic" "-z" "separate-loadable-segments" "-z" "rel" 
"--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -36,7 +36,7 @@
 // CHECK: "-stack-protector" "2"
 // CHECK-AARCH64: "-target-feature" "+outline-atomics"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "-z" "rel" 
"--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"start-stop-visibility=hidden" "-z" "rodynamic" "-z" 
"separate-loadable-segments" "-z" "rel" "--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -56,6 +56,9 @@
   CmdArgs.push_back("-z");
   CmdArgs.push_back("now");
 
+  CmdArgs.push_back("-z");
+  CmdArgs.push_back("start-stop-visibility=hidden");
+
   const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
   if (llvm::sys::path::filename(Exec).equals_insensitive("ld.lld") ||
   llvm::sys::path::stem(Exec).equals_insensitive("ld.lld")) {


Index: clang/test/Driver/fuchsia.cpp
===
--- clang/test/Driver/fuchsia.cpp
+++ clang/test/Driver/fuchsia.cpp
@@ -40,7 +40,7 @@
 // CHECK-RISCV64: "-internal-isystem" "{{.*[/\\]}}include{{/|}}riscv64-unknown-fuchsia{{/|}}c++{{/|}}v1"
 // CHECK: "-internal-isystem" "{{.*[/\\]}}include{{/|}}c++{{/|}}v1"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "now" "-z" "start-stop-visibility=hidden" "-z" "rodynamic" "-z" "separate-loadable-segments" "-z" "rel" "--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -36,7 +36,7 @@
 // CHECK: "-stack-protector" "2"
 // CHECK-AARCH64: "-target-feature" "+outline-atomics"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments" "-z" "rel" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "start-stop-visibility=hidden" "-z" "rodynamic" "-z" "separate-loadable-segments" "-z" "rel" "--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -56,6 +56,9 @@
   CmdArgs.push_back("-z");
   CmdArgs.push_back("now");
 
+  CmdArgs.push_back("-z");
+  CmdArgs.push_back("start-stop-visibility=hidden");
+
   const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
   if (llvm::sys::path::filename(Exec).equals_insensitive("ld.lld") ||
   llvm::sys::path::stem(Exec).equals_insensitive("ld.lld")) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 53ee31c - [Fuchsia] Make __start_* / __stop_* symbols hidden

2023-08-25 Thread Petr Hosek via cfe-commits

Author: Petr Hosek
Date: 2023-08-25T18:50:46Z
New Revision: 53ee31c9871deceaff625dc772d52c0cec520ff9

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

LOG: [Fuchsia] Make __start_* / __stop_* symbols hidden

This is the intended semantics, see for more details:
https://sourceware.org/pipermail/binutils/2020-June/111685.html

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/test/Driver/fuchsia.c
clang/test/Driver/fuchsia.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 65692cc7f954cb..af34a46ae4f7d6 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -56,6 +56,9 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back("-z");
   CmdArgs.push_back("now");
 
+  CmdArgs.push_back("-z");
+  CmdArgs.push_back("start-stop-visibility=hidden");
+
   const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
   if (llvm::sys::path::filename(Exec).equals_insensitive("ld.lld") ||
   llvm::sys::path::stem(Exec).equals_insensitive("ld.lld")) {

diff  --git a/clang/test/Driver/fuchsia.c b/clang/test/Driver/fuchsia.c
index e6010c2c51bb00..cfcb8ad0d3ab42 100644
--- a/clang/test/Driver/fuchsia.c
+++ b/clang/test/Driver/fuchsia.c
@@ -36,7 +36,7 @@
 // CHECK: "-stack-protector" "2"
 // CHECK-AARCH64: "-target-feature" "+outline-atomics"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "-z" "rel" 
"--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"start-stop-visibility=hidden" "-z" "rodynamic" "-z" 
"separate-loadable-segments" "-z" "rel" "--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"

diff  --git a/clang/test/Driver/fuchsia.cpp b/clang/test/Driver/fuchsia.cpp
index 0f307811edf80e..69d5cb19041a7a 100644
--- a/clang/test/Driver/fuchsia.cpp
+++ b/clang/test/Driver/fuchsia.cpp
@@ -40,7 +40,7 @@
 // CHECK-RISCV64: "-internal-isystem" 
"{{.*[/\\]}}include{{/|}}riscv64-unknown-fuchsia{{/|}}c++{{/|}}v1"
 // CHECK: "-internal-isystem" "{{.*[/\\]}}include{{/|}}c++{{/|}}v1"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "now" "-z" "rodynamic" "-z" 
"separate-loadable-segments"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "now" "-z" "start-stop-visibility=hidden" 
"-z" "rodynamic" "-z" "separate-loadable-segments" "-z" "rel" 
"--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"



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


[PATCH] D158820: [Sema][HLSL] Fix naming of anyhit/closesthit shaders

2023-08-25 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/test/SemaHLSL/shader_type_attr.hlsl:30
 
 // expected-error@+1 {{'shader' attribute parameters do not match the previous 
declaration}}
+[shader("pixel")]

bob80905 wrote:
> bogner wrote:
> > bob80905 wrote:
> > > I don't think we should expect this error, given that there is no 
> > > previous declaration for doubledUp(). Maybe something else like %0 and %1 
> > > are incompatible attributes? 
> > I don't necessarily disagree, but if we're going to change that I think it 
> > should be in a different change than this one.
> I'm also curious, why is the change from compute to pixel necessary here?
I suspect this change is just to prevent the presence of the `compute` 
annotation from triggering the `missing numthreads` error.



Comment at: clang/test/SemaHLSL/shader_type_attr.hlsl:61
 // CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
-[shader("compute")]
+[shader("compute"), numthreads(8,1,1)]
 int entry() {

Oh interesting! DXC doesn't actually support this syntax, but I think it is 
worth supporting in Clang.
Should we also check for the numthreads attribute?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158820

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


[PATCH] D158820: [Sema][HLSL] Fix naming of anyhit/closesthit shaders

2023-08-25 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 added inline comments.



Comment at: clang/test/SemaHLSL/entry_shader.hlsl:1
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"anyHit"' -verify
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"mesh"' -verify
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"compute"'

Why was this changed to mesh instead of "anyhit" ?



Comment at: clang/test/SemaHLSL/shader_type_attr.hlsl:30
 
 // expected-error@+1 {{'shader' attribute parameters do not match the previous 
declaration}}
+[shader("pixel")]

bogner wrote:
> bob80905 wrote:
> > I don't think we should expect this error, given that there is no previous 
> > declaration for doubledUp(). Maybe something else like %0 and %1 are 
> > incompatible attributes? 
> I don't necessarily disagree, but if we're going to change that I think it 
> should be in a different change than this one.
I'm also curious, why is the change from compute to pixel necessary here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158820

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


[PATCH] D158805: [clang-format][NFC] Remove extraneous newlines at end of test cases

2023-08-25 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:24187
 
   // Newlines are important here.
+  verifyFormat("FOO(1+2 )", Style);

This.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158805

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


[clang] bbcc7c5 - [NFC] Initialize member pointer and avoid potential null dereference

2023-08-25 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-08-25T11:35:44-07:00
New Revision: bbcc7c5614cd642c8e71b89a6655b097454d57ea

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

LOG: [NFC] Initialize member pointer and avoid potential null dereference

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

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h
clang/lib/Analysis/ThreadSafety.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index cfef45d2e8d689..180bd5add2e262 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -201,13 +201,14 @@ bool Ret(InterpState &S, CodePtr &PC, APValue &Result) {
   return false;
   }
 
+  assert(S.Current);
   assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame");
   if (!S.checkingPotentialConstantExpression() || S.Current->Caller) {
 // Certain builtin functions are declared as func-name(...), so the
 // parameters are checked in Sema and only available through the CallExpr.
 // The interp::Function we create for them has 0 parameters, so we need to
 // remove them from the stack by checking the CallExpr.
-if (S.Current && S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()))
+if (S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()))
   popBuiltinArgs(S, PC);
 else
   S.Current->popArgs();

diff  --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 087994e6ebd702..34260ac8f4e7d6 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -1008,7 +1008,7 @@ class ThreadSafetyAnalyzer {
   threadSafety::SExprBuilder SxBuilder;
 
   ThreadSafetyHandler &Handler;
-  const CXXMethodDecl *CurrentMethod;
+  const CXXMethodDecl *CurrentMethod = nullptr;
   LocalVariableMap LocalVarMap;
   FactManager FactMan;
   std::vector BlockInfo;



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


[PATCH] D158775: [NFC] Initialize member pointer and avoid potential null dereference

2023-08-25 Thread Sindhu Chittireddy via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbbcc7c5614cd: [NFC] Initialize member pointer and avoid 
potential null dereference (authored by schittir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158775

Files:
  clang/lib/AST/Interp/Interp.h
  clang/lib/Analysis/ThreadSafety.cpp


Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -1008,7 +1008,7 @@
   threadSafety::SExprBuilder SxBuilder;
 
   ThreadSafetyHandler &Handler;
-  const CXXMethodDecl *CurrentMethod;
+  const CXXMethodDecl *CurrentMethod = nullptr;
   LocalVariableMap LocalVarMap;
   FactManager FactMan;
   std::vector BlockInfo;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -201,13 +201,14 @@
   return false;
   }
 
+  assert(S.Current);
   assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame");
   if (!S.checkingPotentialConstantExpression() || S.Current->Caller) {
 // Certain builtin functions are declared as func-name(...), so the
 // parameters are checked in Sema and only available through the CallExpr.
 // The interp::Function we create for them has 0 parameters, so we need to
 // remove them from the stack by checking the CallExpr.
-if (S.Current && S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()))
+if (S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()))
   popBuiltinArgs(S, PC);
 else
   S.Current->popArgs();


Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -1008,7 +1008,7 @@
   threadSafety::SExprBuilder SxBuilder;
 
   ThreadSafetyHandler &Handler;
-  const CXXMethodDecl *CurrentMethod;
+  const CXXMethodDecl *CurrentMethod = nullptr;
   LocalVariableMap LocalVarMap;
   FactManager FactMan;
   std::vector BlockInfo;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -201,13 +201,14 @@
   return false;
   }
 
+  assert(S.Current);
   assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame");
   if (!S.checkingPotentialConstantExpression() || S.Current->Caller) {
 // Certain builtin functions are declared as func-name(...), so the
 // parameters are checked in Sema and only available through the CallExpr.
 // The interp::Function we create for them has 0 parameters, so we need to
 // remove them from the stack by checking the CallExpr.
-if (S.Current && S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()))
+if (S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()))
   popBuiltinArgs(S, PC);
 else
   S.Current->popArgs();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158775: [NFC] Initialize member pointer and avoid potential null dereference

2023-08-25 Thread Sindhu Chittireddy via Phabricator via cfe-commits
schittir added a comment.

Thank you for the reviews, Aaron and Aaron! 
All tests pass. Landing the patch now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158775

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


[PATCH] D158822: [Fuchsia] Make __start_* / __stop_* symbols hidden

2023-08-25 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr accepted this revision.
mcgrathr added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158822

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


[PATCH] D158869: [clang] Fix timing of propagation of MSInheritanceAttr for template instantiation declarations.

2023-08-25 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added reviewers: rnk, zequanwu.
tahonermann added a comment.

Adding Erich as attributes owner, and Reid and Zequan for MS ABI. This patch 
slightly modifies the changes made via D94646  
and committed as rG4fffbc150cca1638051b8ad2a20f4b8240df0869 
 for 
GH48031 .




Comment at: clang/lib/Sema/SemaTemplate.cpp:10112
+  Specialization->addAttr(PrevDecl->getAttr());
+  Consumer.AssignInheritanceModel(Specialization);
+}

I am concerned that moving the call to `Consumer.AssignInheritanceModel()` to 
immediately after the creation of the node, but before it is populated might be 
problematic. Previously, this call was still made before the node was 
completely constructed (e.g., before `setTemplateSpecializationKind()` is 
called for it). It is difficult to tell if any consumers might be dependent on 
more of the definition being present. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158869

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


[clang] 54c99a9 - [Clang] Update the core issues list

2023-08-25 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-08-25T20:23:17+02:00
New Revision: 54c99a906740a6dee2e0827d38b351d5966c2e2d

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

LOG: [Clang] Update the core issues list

>From revision 112

Added: 


Modified: 
clang/test/CXX/drs/dr25xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr25xx.cpp b/clang/test/CXX/drs/dr25xx.cpp
index a535f65e085608..68fb4bdaaf2e7d 100644
--- a/clang/test/CXX/drs/dr25xx.cpp
+++ b/clang/test/CXX/drs/dr25xx.cpp
@@ -81,7 +81,7 @@ using ::dr2521::operator""_div;
 #endif
 } // namespace dr2521
 
-namespace dr2565 { // dr2565: 16 open
+namespace dr2565 { // dr2565: 16
 #if __cplusplus >= 202002L
   template
 concept C = requires (typename T::type x) {

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index d044679d617a90..ee9712e9bab994 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -69,11 +69,11 @@ C++ defect report implementation status
 CV-qualifiers and type conversions
 Yes
   
-  
+  
 https://cplusplus.github.io/CWG/issues/6.html";>6
-open
+NAD
 Should the optimization that allows a class object to alias another 
object also allow the case of a parameter in an inline function to alias its 
argument?
-Not resolved
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/7.html";>7
@@ -1055,7 +1055,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/170.html";>170
-tentatively ready
+DR
 Pointer-to-member conversions
 Unknown
   
@@ -1434,7 +1434,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/233.html";>233
-open
+drafting
 References vs pointers in UDC overload resolution
 Not resolved
   
@@ -2675,11 +2675,11 @@ C++ defect report implementation 
status
 Guarantees on casting pointer back to cv-qualified version of original 
type
 Unknown
   
-  
+  
 https://cplusplus.github.io/CWG/issues/440.html";>440
-open
+NAD
 Allow implicit pointer-to-member conversion on nontype template 
argument
-Not resolved
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/441.html";>441
@@ -2873,11 +2873,11 @@ C++ defect report implementation 
status
 Casting across protected inheritance
 Not resolved
   
-  
+  
 https://cplusplus.github.io/CWG/issues/473.html";>473
-open
+NAD
 Block-scope declarations of allocator functions
-Not resolved
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/474.html";>474
@@ -3059,11 +3059,11 @@ C++ defect report implementation 
status
 Cv-qualified function types in template argument deduction
 Not resolved
   
-  
+  
 https://cplusplus.github.io/CWG/issues/504.html";>504
-open
+NAD
 Should use of a variable in its own initializer require a 
diagnostic?
-Not resolved
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/505.html";>505
@@ -3203,11 +3203,11 @@ C++ defect report implementation 
status
 Problems with linkage of types
 N/A
   
-  
+  
 https://cplusplus.github.io/CWG/issues/528.html";>528
-open
+NAD
 Why are incomplete class types not allowed with typeid?
-Not resolved
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/529.html";>529
@@ -3877,11 +3877,11 @@ C++ defect report implementation 
status
 What makes side effects “
diff erent” from one another?
 Yes
   
-  
+  
 https://cplusplus.github.io/CWG/issues/640.html";>640
-open
+NAD
 Accessing destroyed local objects of static storage duration
-Not resolved
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/641.html";>641
@@ -4345,11 +4345,11 @@ C++ defect report implementation 
status
 Unintentional restrictions on the use of thread_local
 Unknown
   
-  
+  
 https://cplusplus.github.io/CWG/issues/718.html";>718
-open
+NAD
 Non-class, non-function friend declarations
-Not resolved
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/719.html";>719
@@ -5235,7 +5235,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/900.html";>900
-DRWP
+C++23
 Lifetime of temporaries in range-based for
 Unknown
   
@@ -6031,11 +6031,11 @@ C++ defect report implementation 
status
 Requirements for operands of delete-expressions and 
deallocation functions
 Unknown
   
-  
+  
 https://cplusplus.github.io/CWG/issues/1038.html";>1038
-review
+tentatively ready
 Overload resolution of &x.static_func
-Not resolved
+Unknown
   
   
 https://cplusplus.github.io/

[PATCH] D158869: [clang] Fix timing of propagation of MSInheritanceAttr for template instantiation declarations.

2023-08-25 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann created this revision.
tahonermann added reviewers: erichkeane, aaron.ballman.
Herald added a project: All.
tahonermann requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change addresses two issues:

1. A failure to propagate a `MSInheritanceAttr` prior to it being required by 
an explicit class template instantiation definition.
2. The same `MSInheritanceAttr` attribute being attached to the same 
`ClassTemplateSpecializationDecl` twice.

`Sema::ActOnExplicitInstantiation()` is responsible for the construction of 
`ClassTemplateSpecializationDecl` nodes for explicit template instantiation 
declarations and definitions.  When invoked when a prior declaration node 
corresponding to an implicit instantiation exists, the prior declaration node 
is repurposed to represent the explicit instantiation declaration or 
definition.  When no previous declaration node exists or when the previous node 
corresponds to an explicit declaration, a new node is allocated. Previously, in 
either case, the function attempted to propagate any existing 
`MSInheritanceAttr` attribute from the previous node, but did so regardless of 
whether the previous node was reused (in which case the repurposed previous 
node would gain a second attachment of the attribute; the second issue listed 
above) or a new node was created.  In the latter case, the attribute was not 
propagated before it was required to be present when compiling for C++17 or 
later (the first issue listed above).  The absent attribute resulted in an 
assertion failure that occurred during instantiation of the specialization 
definition when attempting to complete the definition in order to determine its 
alignment so as to resolve a lookup for a deallocation function for a virtual 
destructor.  This change addresses both issues by propagating the attribute 
closer in time to when a new `ClassTemplateSpecializationDecl` node is created 
and only when such a node is newly created.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158869

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp


Index: clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - 
-triple=i386-pc-win32 -fms-extensions | FileCheck -allow-deprecated-dag-overlap 
%s
 // RUN: %clang_cc1 -std=c++11 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - 
-triple=x86_64-pc-win32 -fms-extensions | FileCheck %s -check-prefix=X64
+// RUN: %clang_cc1 -std=c++17 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - 
-triple=x86_64-pc-win32 -fms-extensions | FileCheck %s -check-prefix=X64
 // RUN: %clang_cc1 -std=c++11 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - 
-triple=i386-pc-win32 -DINCOMPLETE_VIRTUAL -fms-extensions -verify
 // RUN: %clang_cc1 -std=c++11 -Wno-uninitialized -fno-rtti -emit-llvm %s -o - 
-triple=i386-pc-win32 -DINCOMPLETE_VIRTUAL -DMEMFUN -fms-extensions -verify
 
@@ -934,3 +935,25 @@
 void A::printd() { JSMethod(); }
 // CHECK-LABEL: 
@"??$JSMethod@VA@PMFInTemplateArgument@@$1?printd@12@AAEHH@Z@PMFInTemplateArgument@@YAXXZ"(
 }
+
+namespace MissingMSInheritanceAttr {
+// This is a regression test for an assertion failure that occurred when
+// compiling for C++17. The issue concerned a failure to propagate a
+// MSInheritanceAttr attribute for the explicit template instantiation
+// definition prior to it being required to complete the specialization
+// definition in order to determine its alignment so as to resolve a
+// lookup for a deallocation function for the virtual destructor.
+template 
+class a;
+class b {
+  typedef void (a::*f)();
+  f d;
+};
+template 
+class a {
+  virtual ~a();
+  b e;
+};
+extern template class a;
+template class a;
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10105,6 +10105,13 @@
 ClassTemplate, CanonicalConverted, PrevDecl);
 SetNestedNameSpecifier(*this, Specialization, SS);
 
+// A MSInheritanceAttr attached to the previous declaration must be
+// propagated to the new node prior to instantiation.
+if (PrevDecl && PrevDecl->hasAttr()) {
+  Specialization->addAttr(PrevDecl->getAttr());
+  Consumer.AssignInheritanceModel(Specialization);
+}
+
 if (!HasNoEffect && !PrevDecl) {
   // Insert the new specialization.
   ClassTemplate->AddSpecialization(Specialization, InsertPos);
@@ -10221,11 +10228,6 @@
   dllExportImportClassTemplateSpecialization(*this, Def);
 }
 
-if (Def->hasAttr()) {
-  Specialization->addAttr(Def->getAttr());
-  Consumer.Assign

[PATCH] D158641: [AArch64][Android][DRAFT] Fix FMV ifunc resolver usage on old Android APIs.

2023-08-25 Thread Stephen Hines via Phabricator via cfe-commits
srhines added inline comments.



Comment at: compiler-rt/lib/builtins/cpu_model.c:1382
+return;
+#if defined(__ANDROID__)
+  // ifunc resolvers don't have hwcaps in arguments on Android API lower

MaskRay wrote:
> enh wrote:
> > ilinpv wrote:
> > > MaskRay wrote:
> > > > I am unfamiliar with how Android ndk builds compiler-rt.
> > > > 
> > > > If `__ANDROID_API__ >= 30`, shall we use the regular Linux code path?
> > > I think that leads to shipping different compile-rt libraries depend on 
> > > ANDROID_API. If this is an option to consider than runtime check 
> > > android_get_device_api_level() < 30 can be replaced by `__ANDROID_API__ < 
> > > 30`
> > depends what you mean... in 10 years or so, yes, no-one is likely to still 
> > care about the older API levels and we can just delete this. but until 
> > then, no, there's _one_ copy of compiler-rt that everyone uses, and 
> > although _OS developers_ don't need to support anything more than a couple 
> > of years old, most app developers are targeting far lower API levels than 
> > that (to maximize the number of possible customers).
> > 
> > TL;DR: "you could add that condition to the `#if`, but no-one would use it 
> > for a decade". (and i think the comment and `if` below should make it clear 
> > enough to future archeologists when this code block can be removed :-) )
> My thought was that people build Android with a specific `__ANDROID_API__`, 
> and only systems >= this level are supported.
> ```
> #If __ANDROID_API__ < 30
> ...
> #endif
> ```
> 
> This code has a greater chance to be removed when it becomes obsoleted. The 
> argument is similar to how we find obsoleted GCC workarounds.
Yes, the NDK currently just ships the oldest supported target API level for 
compiler-rt, while the Android platform build does have access to both the 
oldest supported target API level + the most recent target API level, so that 
we can make better use of features there.

Maybe I'm missing something, but it's feeling like the NDK users won't be able 
to make great use of FMV without us either bumping the minimum level or 
shipping multiple runtimes (and then using the #ifdefs properly here).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158641

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


[PATCH] D158709: [Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized

2023-08-25 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D158709#4617295 , @aaron.ballman 
wrote:

> I'm a bit concerned about the impact on (non-modules) build time performance. 
> This splits stddef.h and stdarg.h into needing to open 14 different files 
> instead of 2. Hopefully that's not a lot of overhead, but given that stddef.h 
> is included in approximately every TU and that sometimes external forces 
> cause files to be slow to open (network drives, AV software, etc), I think we 
> should be cautious and measure the impact. I also really do not like how 
> poorly this scales -- the fact that this is only needed for these two files 
> helps a bit, but this is a lot of C++-specific hoops to jump through for C 
> standard library headers.

This is in support of clang modules, not C++ modules. The plan is to make 
modules like this.

  module _Builtin_stddef [system] {
textual header "stddef.h"
  
explicit module max_align_t {
  header "__stddef_max_align_t.h"
  export *
}
  
explicit module null {
  header "__stddef_null.h"
  export *
}
...
  }

I do agree it's a bit of a file explosion, but I can't really think of any 
better alternatives. It's tough to measure build time performance impact. If 
you have a slow enough file system (and the fs on our builders at Apple is 
quite slow), and you aren't using modules or pch's, and you have quite a lot of 
source files, then probably this would be noticeable? I still don't know what 
we could really do about it besides have `#if !__has_feature(modules)` and 
inline the contents in that case. That seems like a maintenance headache and a 
half though. I would hope that most sizable projects either use clang modules 
or pch's?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158709

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


[PATCH] D158787: [clang-tidy][readability] add Leading_upper_snake_case

2023-08-25 Thread Steven Lewis via Phabricator via cfe-commits
MasterCopy8GB updated this revision to Diff 553550.
MasterCopy8GB added a comment.

Fix documentation comments


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

https://reviews.llvm.org/D158787

Files:
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-violation.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -49,7 +49,7 @@
 // RUN: readability-identifier-naming.StaticConstantCase: UPPER_CASE, \
 // RUN: readability-identifier-naming.StaticVariableCase: camelBack, \
 // RUN: readability-identifier-naming.StaticVariablePrefix: 's_', \
-// RUN: readability-identifier-naming.StructCase: lower_case, \
+// RUN: readability-identifier-naming.StructCase: Leading_upper_snake_case, \
 // RUN: readability-identifier-naming.TemplateParameterCase: UPPER_CASE, \
 // RUN: readability-identifier-naming.TemplateTemplateParameterCase: CamelCase, \
 // RUN: readability-identifier-naming.TemplateUsingCase: lower_case, \
@@ -513,9 +513,9 @@
 
 struct THIS___Structure {
 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 'THIS___Structure'
-// CHECK-FIXES: {{^}}struct this_structure {{{$}}
+// CHECK-FIXES: {{^}}struct This_structure {{{$}}
 THIS___Structure();
-// CHECK-FIXES: {{^}}this_structure();{{$}}
+// CHECK-FIXES: {{^}}This_structure();{{$}}
 
   union __MyUnion_is_wonderful__ {};
 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for union '__MyUnion_is_wonderful__'
@@ -524,7 +524,7 @@
 
 typedef THIS___Structure struct_type;
 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for typedef 'struct_type'
-// CHECK-FIXES: {{^}}typedef this_structure struct_type_t;{{$}}
+// CHECK-FIXES: {{^}}typedef This_structure struct_type_t;{{$}}
 
 struct_type GlobalTypedefTestFunction(struct_type a_argument1) {
 // CHECK-FIXES: {{^}}struct_type_t GlobalTypedefTestFunction(struct_type_t a_argument1) {
@@ -534,7 +534,7 @@
 
 using my_struct_type = THIS___Structure;
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type'
-// CHECK-FIXES: {{^}}using my_Struct_Type_t = this_structure;{{$}}
+// CHECK-FIXES: {{^}}using my_Struct_Type_t = This_structure;{{$}}
 
 template
 using SomeOtherTemplate = my_other_templated_class  <:: FOO_NS  ::my_class>;
@@ -596,6 +596,8 @@
 }
 
 template  struct a {
+// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: invalid case style for struct 'a'
+// CHECK-FIXES: {{^}}template  struct A {{{$}}
   typename t_t::template b<> c;
 
   char const MY_ConstMember_string[4] = "123";
@@ -609,9 +611,11 @@
 
 template
 char const a::MyConstClass_string[] = "123";
-// CHECK-FIXES: {{^}}char const a::kMyConstClassString[] = "123";{{$}}
+// CHECK-FIXES: {{^}}char const A::kMyConstClassString[] = "123";{{$}}
 
 template  class A> struct b { A c; };
+// CHECK-MESSAGES: :[[@LINE-1]]:47: warning: invalid case style for struct 'b'
+// CHECK-FIXES:template  class A> struct B { A c; };{{$}}
 
 unsigned MY_GLOBAL_array[] = {1,2,3};
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'MY_GLOBAL_array'
@@ -645,17 +649,17 @@
 // CHECK-FIXES: {{^}}using namespace foo_ns::inline_namespace;
 
 void QualifiedTypeLocTest(THIS___Structure);
-// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure);{{$}}
+// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(This_structure);{{$}}
 void QualifiedTypeLocTest(THIS___Structure &);
-// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure &);{{$}}
+// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(This_structure &);{{$}}
 void QualifiedTypeLocTest(THIS___Structure &&);
-// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure &&);{{$}}
+// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(This_structure &&);{{$}}
 void QualifiedTypeLocTest(const THIS___Structure);
-// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure);{{$}}
+// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const This_structure);{{$}}
 void QualifiedTypeLocTest(const THIS___Structure &);
-// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure &);{{$}}
+// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const This_structure &);{{$}}
 void QualifiedTypeLocTest(volatile THIS___Structure &);
-// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(volatile this_structure &);{{$}}
+// CHECK-FIXES: {{^}}void QualifiedTypeL

[PATCH] D158820: [Sema][HLSL] Fix naming of anyhit/closesthit shaders

2023-08-25 Thread Justin Bogner via Phabricator via cfe-commits
bogner added inline comments.



Comment at: clang/test/SemaHLSL/shader_type_attr.hlsl:30
 
 // expected-error@+1 {{'shader' attribute parameters do not match the previous 
declaration}}
+[shader("pixel")]

bob80905 wrote:
> I don't think we should expect this error, given that there is no previous 
> declaration for doubledUp(). Maybe something else like %0 and %1 are 
> incompatible attributes? 
I don't necessarily disagree, but if we're going to change that I think it 
should be in a different change than this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158820

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


[PATCH] D158671: [NFC][Clang] Fix static analyzer concerns

2023-08-25 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 553534.
eandrews added a comment.

Thanks for the reviews! Requested changes have been made in latest patch


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

https://reviews.llvm.org/D158671

Files:
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp


Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5062,6 +5062,7 @@
 } IR{*this, PatternRec, NewRec};
 
 TypeSourceInfo *NewSI = IR.TransformType(Function->getTypeSourceInfo());
+assert(NewSI && "Type Transform failed?");
 Function->setType(NewSI->getType());
 Function->setTypeSourceInfo(NewSI);
 
Index: clang/lib/ExtractAPI/DeclarationFragments.cpp
===
--- clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -688,9 +688,9 @@
 const CXXMethodDecl *Method) {
   DeclarationFragments Fragments;
   std::string Name;
-  if (isa(Method)) {
+  if (const auto *Constructor = dyn_cast(Method)) {
 Name = Method->getNameAsString();
-if (dyn_cast(Method)->isExplicit())
+if (Constructor->isExplicit())
   Fragments.append("explicit", DeclarationFragments::FragmentKind::Keyword)
   .appendSpace();
   } else if (isa(Method))
Index: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
===
--- clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -266,7 +266,9 @@
 
   if (Decl->isStaticDataMember()) {
 SymbolReference Context;
-auto Record = dyn_cast(Decl->getDeclContext());
+// getDeclContext() should return a RecordDecl since we
+// are currently handling a static data member.
+auto *Record = cast(Decl->getDeclContext());
 Context.Name = Record->getName();
 Context.USR = API.recordUSR(Record);
 auto Access = DeclarationFragmentsBuilder::getAccessControl(Decl);


Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5062,6 +5062,7 @@
 } IR{*this, PatternRec, NewRec};
 
 TypeSourceInfo *NewSI = IR.TransformType(Function->getTypeSourceInfo());
+assert(NewSI && "Type Transform failed?");
 Function->setType(NewSI->getType());
 Function->setTypeSourceInfo(NewSI);
 
Index: clang/lib/ExtractAPI/DeclarationFragments.cpp
===
--- clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -688,9 +688,9 @@
 const CXXMethodDecl *Method) {
   DeclarationFragments Fragments;
   std::string Name;
-  if (isa(Method)) {
+  if (const auto *Constructor = dyn_cast(Method)) {
 Name = Method->getNameAsString();
-if (dyn_cast(Method)->isExplicit())
+if (Constructor->isExplicit())
   Fragments.append("explicit", DeclarationFragments::FragmentKind::Keyword)
   .appendSpace();
   } else if (isa(Method))
Index: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
===
--- clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -266,7 +266,9 @@
 
   if (Decl->isStaticDataMember()) {
 SymbolReference Context;
-auto Record = dyn_cast(Decl->getDeclContext());
+// getDeclContext() should return a RecordDecl since we
+// are currently handling a static data member.
+auto *Record = cast(Decl->getDeclContext());
 Context.Name = Record->getName();
 Context.USR = API.recordUSR(Record);
 auto Access = DeclarationFragmentsBuilder::getAccessControl(Decl);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158820: [Sema][HLSL] Fix naming of anyhit/closesthit shaders

2023-08-25 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 added inline comments.



Comment at: clang/test/SemaHLSL/shader_type_attr.hlsl:30
 
 // expected-error@+1 {{'shader' attribute parameters do not match the previous 
declaration}}
+[shader("pixel")]

I don't think we should expect this error, given that there is no previous 
declaration for doubledUp(). Maybe something else like %0 and %1 are 
incompatible attributes? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158820

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


[PATCH] D158614: [UBSan] Disable the function sanitizer on an execute-only target.

2023-08-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:326
 def err_unsupported_abi_for_opt : Error<"'%0' can only be used with the '%1' 
ABI">;
+def err_unsupported_opt_for_execute_only_target
+: Error<"unsupported option '%0' for the execute only target '%1'">;

MaggieYi wrote:
> MaskRay wrote:
> > We don't need this diagnostic as a common kind (we only use it in driver).
> > 
> > I think we can reuse `err_drv_argument_not_allowed_with` . Though for PS5 
> > you will get `... allowed with '-mexecute-only'` even if the user doesn't 
> > specify `-mexecute-only`, but I hope it is fine.
> Since `err_drv_argument_not_allowed_with` is an ARM-only option, We cannot 
> reuse it.
`err_drv_argument_not_allowed_with` is a generic diagnostic. My point is that 
we don't need an extra err_unsupported_opt_for_execute_only_target.



Comment at: clang/lib/Basic/Sanitizers.cpp:126
+  // execute-only output (no data access to code sections).
+  if (const llvm::opt::Arg *A =
+  Args.getLastArg(clang::driver::options::OPT_mexecute_only,

The idiom is `hasFlag(clang::driver::options::OPT_mexecute_only, 
clang::driver::options::OPT_mno_execute_only, false)`



Comment at: clang/lib/Basic/Sanitizers.cpp:130
+if (A->getOption().matches(clang::driver::options::OPT_mexecute_only) &&
+llvm::ARM::supportedExecuteOnly(Triple)) {
+  return true;

I don't think we need an extra `llvm::ARM::supportedExecuteOnly` check. We just 
return true when `-mexecute-only` is in effect.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:478
   }
+  // `-fsanitize=function` is silently discarded on an execute-only target
+  // if implicitly enabled through group expansion.

`-fsanitize=function => NotAllowedWithExecuteOnly

since we now handle kcfi as well.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:481
+  if (isExecuteOnlyTarget(Triple, Args)) {
+Add &= ~NotAllowedWithExecuteOnly;
+  }

omit braces



Comment at: clang/test/Driver/fsanitize.c:981
+// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=function %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined 
-fsanitize=function %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI

Drop `not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined 
-fsanitize=function`. 
Testing just `-fsanitize=function` for the negative test is sufficient.



Comment at: clang/test/Driver/fsanitize.c:983
+// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI
+// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=function 
-fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI 
--check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED

Drop `-fsanitize=function -fsanitize=kcfi` line. They already lead to an error.



Comment at: clang/test/Driver/fsanitize.c:984
+// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=function 
-fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI 
--check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED
+

`--target=armv6t2-eabi -mexecute-only -fsanitize=undefined` needs a custom 
check prefix that checks `function` is not enabled.



Comment at: llvm/lib/TargetParser/ARMTargetParser.cpp:602
+
+bool ARM::supportedExecuteOnly(const Triple &TT) {
+  if (parseArchVersion(TT.getArchName()) < 7 &&

We don't need to extract the function.


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

https://reviews.llvm.org/D158614

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


[PATCH] D158858: [analyzer] MPIChecker: add defensive checking (check against nullptr)

2023-08-25 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

In D158858#4617510 , @steakhal wrote:

> Makes sense.
> Would thus test crash without the early returns? And now they wouldn't?

Yes, the original crash shown in https://godbolt.org/z/39P7W6KPa


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158858

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


[PATCH] D158318: [Sema] tolerate more promotion matches in format string checking

2023-08-25 Thread Félix Cloutier via Phabricator via cfe-commits
fcloutier added a comment.

Commit is 
https://github.com/llvm/llvm-project/commit/04e6178ae932c9a1d939dcfe3ef1189f4bbb21aa.


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

https://reviews.llvm.org/D158318

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


[PATCH] D158318: [Sema] tolerate more promotion matches in format string checking

2023-08-25 Thread Félix Cloutier via Phabricator via cfe-commits
fcloutier closed this revision.
fcloutier added a comment.

Apologies, I landed the change but forgot to update the commit message to 
include the "Differential Revision:" link. -_- I'm closing this change and I'll 
update the GitHub issue, which is linked.


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

https://reviews.llvm.org/D158318

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


[clang] 04e6178 - [Sema] tolerate more promotion matches in format string checking

2023-08-25 Thread Félix Cloutier via cfe-commits

Author: Félix Cloutier
Date: 2023-08-25T10:14:01-07:00
New Revision: 04e6178ae932c9a1d939dcfe3ef1189f4bbb21aa

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

LOG: [Sema] tolerate more promotion matches in format string checking

It's been reported that when using __attribute__((format)) on non-variadic
functions, certain values that normally get promoted when passed as variadic
arguments now unconditionally emit a diagnostic:

```c
void foo(const char *fmt, float f) __attribute__((format(printf, 1, 2)));
void bar(void) {
foo("%g", 123.f);
//   ^ format specifies type 'double' but the argument has type 'float'
}
```

This is normally not an issue because float values get promoted to doubles when
passed as variadic arguments, but needless to say, variadic argument promotion
does not apply to non-variadic arguments.

While this can be fixed by adjusting the prototype of `foo`, this is sometimes
undesirable in C (for instance, if `foo` is ABI). In C++, using variadic
templates, this might instead require call-site fixing, which is tedious and
arguably needless work:

```c++
template
void foo(const char *fmt, Args &&...args) __attribute__((format(printf, 1, 2)));
void bar(void) {
foo("%g", 123.f);
//   ^ format specifies type 'double' but the argument has type 'float'
}
```

To address this issue, we teach FormatString about a few promotions that have
always been around but that have never been exercised in the direction that
FormatString checks for:

* `char`, `unsigned char` -> `int`, `unsigned`
* `half`, `float16`, `float` -> `double`

This addresses issue https://github.com/llvm/llvm-project/issues/59824.

Added: 
clang/test/SemaCXX/format-strings-scanf.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/FormatString.cpp
clang/test/Sema/attr-format.c
clang/test/SemaCXX/attr-format.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f0e601fc2df88b..8580b2ccb20c24 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -128,6 +128,13 @@ Removed Compiler Flags
 Attribute Changes in Clang
 --
 
+- When a non-variadic function is decorated with the ``format`` attribute,
+  Clang now checks that the format string would match the function's 
parameters'
+  types after default argument promotion. As a result, it's no longer an
+  automatic diagnostic to use parameters of types that the format style
+  supports but that are never the result of default argument promotion, such as
+  ``float``. (`#59824: `_)
+
 Improvements to Clang's diagnostics
 ---
 - Clang constexpr evaluator now prints template arguments when displaying

diff  --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index ad5af9508983fe..f86278e4b5163d 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -458,6 +458,10 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 switch (BT->getKind()) {
 default:
   break;
+case BuiltinType::Bool:
+  if (T == C.IntTy || T == C.UnsignedIntTy)
+return MatchPromotion;
+  break;
 case BuiltinType::Int:
 case BuiltinType::UInt:
   if (T == C.SignedCharTy || T == C.UnsignedCharTy ||
@@ -465,6 +469,24 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
   T == C.WideCharTy)
 return MatchPromotion;
   break;
+case BuiltinType::Char_U:
+  if (T == C.UnsignedIntTy)
+return MatchPromotion;
+  if (T == C.UnsignedShortTy)
+return NoMatchPromotionTypeConfusion;
+  break;
+case BuiltinType::Char_S:
+  if (T == C.IntTy)
+return MatchPromotion;
+  if (T == C.ShortTy)
+return NoMatchPromotionTypeConfusion;
+  break;
+case BuiltinType::Half:
+case BuiltinType::Float16:
+case BuiltinType::Float:
+  if (T == C.DoubleTy)
+return MatchPromotion;
+  break;
 case BuiltinType::Short:
 case BuiltinType::UShort:
   if (T == C.SignedCharTy || T == C.UnsignedCharTy)

diff  --git a/clang/test/Sema/attr-format.c b/clang/test/Sema/attr-format.c
index d891828a77a4c6..9cc6b5482144a7 100644
--- a/clang/test/Sema/attr-format.c
+++ b/clang/test/Sema/attr-format.c
@@ -94,13 +94,9 @@ void call_nonvariadic(void) {
   d3("%s", 123); // expected-warning{{format specifies type 'char *' but the 
argu

[PATCH] D156624: [clang-tidy] Access checks not done classes derived of std::array

2023-08-25 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG41818ce150fd: [clang-tidy] Access checks not done classes 
derived of std::array (authored by sousajo, committed by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156624

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
@@ -23,6 +23,9 @@
   return base + 3;
 }
 
+template
+class DerivedArray : public std::array {};
+
 void f(std::array a, int pos) {
   a [ pos / 2 /*comment*/] = 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
@@ -68,6 +71,81 @@
   m[const_index(6)] = 3; // OK, constant index and inside bounds
 }
 
+template
+class PrivateDerivedArray : std::array {
+public:
+  T& operator[](size_t n){
+return std::array::operator[](static_cast(n));
+  };
+  T& at(size_t n) {
+return std::array::at(static_cast(n));
+  };
+};
+
+void f_derived(DerivedArray a, int pos) {
+  a [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
+  int j = a[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use array subscript when the index is not an integer constant expression
+
+  a.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(a, pos-1) = 2; // OK, gsl::at() instead of []
+
+  a[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  a[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements) [cppcoreguidelines-pro-bounds-constant-array-index]
+
+  a[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements)
+
+  a[0] = 3; // OK, constant index and inside bounds
+  a[1] = 3; // OK, constant index and inside bounds
+  a[9] = 3; // OK, constant index and inside bounds
+  a[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyArray = DerivedArray;
+  MyArray m{};
+  m [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
+  int jj = m[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not use array subscript when the index is not an integer constant expression
+
+  m.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(m, pos-1) = 2; // OK, gsl::at() instead of []
+  m[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  m[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements) [cppcoreguidelines-pro-bounds-constant-array-index]
+
+  m[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements)
+
+  m[0] = 3; // OK, constant index and inside bounds
+  m[1] = 3; // OK, constant index and inside bounds
+  m[9] = 3; // OK, constant index and inside bounds
+  m[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyPrivateArray = PrivateDerivedArray;
+  MyPrivateArray pm{};
+  pm [ pos / 2 /*comment*/] = 1;
+  int jjj = pm[pos - 1];
+
+  pm.at(pos-1) = 2; // OK, at() instead of []
+  pm[-1] = 3;
+  pm[10] = 4;
+
+  pm[const_index(7)] = 3;
+
+  pm[0] = 3; // OK, constant index and inside bounds
+  pm[1] = 3; // OK, constant index and inside bounds
+  pm[9] = 3; // OK, constant index and inside bounds
+  pm[const_index(6)] = 3; // OK, constant index and inside bounds
+}
+
+
+
+
 void g() {
   int a[10];
   for (int i = 0; i < 10; ++i) {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -202,6 +202,10 @@
   ` check
   to ignore predefined expression (e.g., ``__func__``, ...).
 
+- Improved :doc:`cppcoreguidelines-pro-bounds-con

[clang-tools-extra] 41818ce - [clang-tidy] Access checks not done classes derived of std::array

2023-08-25 Thread Piotr Zegar via cfe-commits

Author: Jorge Pinto Sousa
Date: 2023-08-25T17:09:04Z
New Revision: 41818ce150fd7534480a28d6c0d603f1a503db79

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

LOG: [clang-tidy] Access checks not done classes derived of std::array

Index accessing checks are not performed for derived classes of
of `std::array`, as only `std::array` itself and its aliases
seems to be checked.

This patch aims to extend it for derived classes such as:
```
template
class DerivedArray : public std::array {};
```

Reviewed By: PiotrZSL

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

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
index fbc3cd314ee53a..20f9a2e549fe2f 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
@@ -48,9 +48,8 @@ void 
ProBoundsConstantArrayIndexCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   cxxOperatorCallExpr(
   hasOverloadedOperatorName("[]"),
-  hasArgument(
-  0, hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
- cxxRecordDecl(hasName("::std::array")).bind("type")),
+  callee(cxxMethodDecl(
+  ofClass(cxxRecordDecl(hasName("::std::array")).bind("type",
   hasArgument(1, expr().bind("index")))
   .bind("expr"),
   this);

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 1bc56023f142a1..54fd0ed0263208 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -202,6 +202,10 @@ Changes in existing checks
   ` 
check
   to ignore predefined expression (e.g., ``__func__``, ...).
 
+- Improved :doc:`cppcoreguidelines-pro-bounds-constant-array-index
+  ` check
+  to perform checks on derived classes of  ``std::array``.
+
 - Improved :doc:`cppcoreguidelines-pro-type-member-init
   ` check to ignore
   dependent delegate constructors.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
index e689677578f8d0..e8a4bc40a2e4e1 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
@@ -23,6 +23,9 @@ constexpr int const_index(int base) {
   return base + 3;
 }
 
+template
+class DerivedArray : public std::array {};
+
 void f(std::array a, int pos) {
   a [ pos / 2 /*comment*/] = 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when 
the index is not an integer constant expression 
[cppcoreguidelines-pro-bounds-constant-array-index]
@@ -68,6 +71,81 @@ void f(std::array a, int pos) {
   m[const_index(6)] = 3; // OK, constant index and inside bounds
 }
 
+template
+class PrivateDerivedArray : std::array {
+public:
+  T& operator[](size_t n){
+return std::array::operator[](static_cast(n));
+  };
+  T& at(size_t n) {
+return std::array::at(static_cast(n));
+  };
+};
+
+void f_derived(DerivedArray a, int pos) {
+  a [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when 
the index is not an integer constant expression 
[cppcoreguidelines-pro-bounds-constant-array-index]
+  int j = a[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use array subscript when 
the index is not an integer constant expression
+
+  a.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(a, pos-1) = 2; // OK, gsl::at() instead of []
+
+  a[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is 
negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  a[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past 
the end of the array (which contains 10 elements) 
[cppcoreguidelines-pro-bounds-constant-array-index]
+
+  a[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past 
the end of the array (which contains 10 elements)
+
+  a[0] = 3; // OK, constant index and inside bounds
+  a[1] = 3; // OK, constant index and inside bounds

[PATCH] D158811: [X86] __builtin_cpu_supports: support x86-64{,-v2,-v3,-v4}

2023-08-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 553524.
MaskRay marked 2 inline comments as done.
MaskRay added a comment.

add assert


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158811

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/builtin-cpu-supports.c
  clang/test/Sema/attr-cpuspecific.c
  clang/test/Sema/attr-target.c
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/TargetParser/X86TargetParser.cpp

Index: llvm/lib/TargetParser/X86TargetParser.cpp
===
--- llvm/lib/TargetParser/X86TargetParser.cpp
+++ llvm/lib/TargetParser/X86TargetParser.cpp
@@ -703,18 +703,22 @@
   return I != std::end(Processors);
 }
 
-uint64_t llvm::X86::getCpuSupportsMask(ArrayRef FeatureStrs) {
+std::array
+llvm::X86::getCpuSupportsMask(ArrayRef FeatureStrs) {
   // Processor features and mapping to processor feature value.
-  uint64_t FeaturesMask = 0;
-  for (const StringRef &FeatureStr : FeatureStrs) {
+  std::array FeatureMask{};
+  for (StringRef FeatureStr : FeatureStrs) {
 unsigned Feature = StringSwitch(FeatureStr)
 #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY)\
   .Case(STR, llvm::X86::FEATURE_##ENUM)
+#define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY)   \
+  .Case(STR, llvm::X86::FEATURE_##ENUM)
 #include "llvm/TargetParser/X86TargetParser.def"
 ;
-FeaturesMask |= (1ULL << Feature);
+assert(Feature / 32 < FeatureMask.size());
+FeatureMask[Feature / 32] |= 1U << (Feature % 32);
   }
-  return FeaturesMask;
+  return FeatureMask;
 }
 
 unsigned llvm::X86::getFeaturePriority(ProcessorFeatures Feat) {
Index: llvm/include/llvm/TargetParser/X86TargetParser.h
===
--- llvm/include/llvm/TargetParser/X86TargetParser.h
+++ llvm/include/llvm/TargetParser/X86TargetParser.h
@@ -15,6 +15,7 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringMap.h"
+#include 
 
 namespace llvm {
 template  class SmallVectorImpl;
@@ -57,7 +58,10 @@
 enum ProcessorFeatures {
 #define X86_FEATURE(ENUM, STRING) FEATURE_##ENUM,
 #include "llvm/TargetParser/X86TargetParser.def"
-  CPU_FEATURE_MAX
+  CPU_FEATURE_MAX,
+
+#define X86_MICROARCH_LEVEL(ENUM, STRING, PRIORITY) FEATURE_##ENUM = PRIORITY,
+#include "llvm/TargetParser/X86TargetParser.def"
 };
 
 enum CPUKind {
@@ -171,7 +175,7 @@
 
 char getCPUDispatchMangling(StringRef Name);
 bool validateCPUSpecificCPUDispatch(StringRef Name);
-uint64_t getCpuSupportsMask(ArrayRef FeatureStrs);
+std::array getCpuSupportsMask(ArrayRef FeatureStrs);
 unsigned getFeaturePriority(ProcessorFeatures Feat);
 
 } // namespace X86
Index: llvm/include/llvm/TargetParser/X86TargetParser.def
===
--- llvm/include/llvm/TargetParser/X86TargetParser.def
+++ llvm/include/llvm/TargetParser/X86TargetParser.def
@@ -128,6 +128,10 @@
 #define X86_FEATURE(ENUM, STR)
 #endif
 
+#ifndef X86_MICROARCH_LEVEL
+#define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY)
+#endif
+
 X86_FEATURE_COMPAT(CMOV,"cmov",  0)
 X86_FEATURE_COMPAT(MMX, "mmx",   1)
 X86_FEATURE_COMPAT(POPCNT,  "popcnt",9)
@@ -242,5 +246,11 @@
 X86_FEATURE   (RETPOLINE_INDIRECT_CALLS,"retpoline-indirect-calls")
 X86_FEATURE   (LVI_CFI, "lvi-cfi")
 X86_FEATURE   (LVI_LOAD_HARDENING,  "lvi-load-hardening")
+
+X86_MICROARCH_LEVEL(X86_64_BASELINE,"x86-64",   95)
+X86_MICROARCH_LEVEL(X86_64_V2,  "x86-64-v2",96)
+X86_MICROARCH_LEVEL(X86_64_V3,  "x86-64-v3",97)
+X86_MICROARCH_LEVEL(X86_64_V4,  "x86-64-v4",98)
 #undef X86_FEATURE_COMPAT
 #undef X86_FEATURE
+#undef X86_MICROARCH_LEVEL
Index: clang/test/Sema/attr-target.c
===
--- clang/test/Sema/attr-target.c
+++ clang/test/Sema/attr-target.c
@@ -26,6 +26,11 @@
 //expected-warning@+1 {{unknown tune CPU 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
 int __attribute__((target("tune=hiss,tune=woof"))) apple_tree(void) { return 4; }
 
+//expected-warning@+1 {{unsupported 'x86-64' in the 'target' attribute string}}
+void __attribute__((target("x86-64"))) baseline(void) {}
+//expected-warning@+1 {{unsupported 'x86-64-v2' in the 'target' attribute string}}
+void __attribute__((target("x86-64-v2"))) v2(void) {}
+
 #elifdef __aarch64__
 
 int __attribute__((target("sve,arch=armv8-a"))) foo(void) { return 4; }
Index: clang/test/Sema/attr-cpuspecific.c
===
--- clang/test/Sema

[PATCH] D158858: [analyzer] MPIChecker: add defensive checking (check against nullptr)

2023-08-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

Makes sense.
Would thus test crash without the early returns? And now they wouldn't?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158858

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


[PATCH] D152054: [OpenMP] Codegen support for thread_limit on target directive

2023-08-25 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152054

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


[PATCH] D157572: [clang] Add `[[clang::library_extension]]` attribute

2023-08-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a subscriber: Mordante.
aaron.ballman added a comment.

In D157572#4614561 , @cjdb wrote:

> In D157572#4613622 , @aaron.ballman 
> wrote:
>
>> In D157572#4612141 , @cjdb wrote:
>>
>>> I don't dislike it, but I am a bit concerned about misuse being noisy.
>>
>> So you're concerned that a library author uses `diagnose_if` to add a 
>> diagnostic to a warning group that makes the diagnostic seem too chatty, so 
>> the user disables the group and loses the compiler's diagnostics? Or are 
>> there other kinds of misuse you're worried about?
>
> More or less the former. I don't know if it'll actually manifest in practice 
> though, I don't see many `diagnose_if` diagnostics to begin with.

I think the former is sort of a "doctor, doctor, it hurts" situation; the issue 
isn't really with `diagnose_if`, it's with the library author's use of it. But 
at the same time, I can see why it would be beneficial to be able to work 
around it if needed.

>>> As much as I hate suppressing diagnostics, I think there needs to be a way 
>>> to suppress the `diagnose_if` forms of warning without suppressing 
>>> something that the compiler would otherwise generate. Something like:
>>>
>>> - `-Wno-deprecated`: suppresses anything that `-Wdeprecated` would turn on.
>>> - `-Wno-deprecated=diagnose_if`: just the ones flagged by `diagnose_if`.
>>> - `-Wno-deprecated=non-diagnose_if`: complement to #2.
>>>
>>> (and similarly for `-Wno-error=`.)
>>>
>>> I'm not sure about the system header knob though: `[[deprecated]]` and 
>>> `[[nodiscard]]` still show up even when the declaration is in a system 
>>> header?
>>
>> Correct, those will still show up when the declaration is in a system header 
>> but not when the use is in a system header: https://godbolt.org/z/PjqKbGsrr
>
> Right, my question was more "what is this knob doing?"

Ah! We have various knobs on our diagnostics, like:
`ShowInSystemHeader` -- 
https://github.com/llvm/llvm-project/blob/2dc6281b98d07f43a64d0ef34405d9a12d59e8b6/clang/include/clang/Basic/DiagnosticSemaKinds.td#L7818
 (if used, the diagnostic will be shown in a system header)
`SFINAEFailure` -- 
https://github.com/llvm/llvm-project/blob/2dc6281b98d07f43a64d0ef34405d9a12d59e8b6/clang/include/clang/Basic/DiagnosticSemaKinds.td#L93
 (if used, the diagnostic causes SFINAE to fail in a SFINAE context)
`DefaultIgnore` -- 
https://github.com/llvm/llvm-project/blob/2dc6281b98d07f43a64d0ef34405d9a12d59e8b6/clang/include/clang/Basic/DiagnosticSemaKinds.td#L141
 (if used, the warning is off by default and must be explicitly enabled via its 
group)
`DefaultError` -- 
https://github.com/llvm/llvm-project/blob/2dc6281b98d07f43a64d0ef34405d9a12d59e8b6/clang/include/clang/Basic/DiagnosticSemaKinds.td#L262
 (if used, the warning defaults to being an error but users can disable the 
error with `-Wno`)
(etc)

All of these have been of use to us as implementers, so it seems likely that 
these same knobs would be of use to library authors adding their own compiler 
diagnostics, so perhaps we should consider that as part of the design?

>> We currently have `-Wuser-defined-warnings` as the warning group for 
>> `diagnose_if` warning diagnostics, so I wonder if it would make sense to 
>> allow `-Wno-deprecated` suppresses anything that `-Wdeprecated` would turn 
>> on, while `-Wdeprecated -Wno-user-defined-warnings` would turn on only the 
>> compiler-generated deprecation warnings and not the diagnose_if-generated 
>> ones?
>
> Oh neat, this simplifies things a lot!

I think it could make for a reasonable user experience.

I'm curious what @erichkeane thinks as attributes code owner, but personally, I 
like the idea of extending `diagnose_if` over the idea of adding 
`clang::library_extension` because it's a more general solution that I think 
will give more utility to our users. However, I also want to know if @philnik 
@Mordante @ldionne (and others) share that preference because I think they're 
going to be the guinea pigs^W^Wearly adopters of this functionality.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157572

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


[PATCH] D158763: [flang][driver] Mark -L as visible in Flang

2023-08-25 Thread Bryan Chan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1561495cd128: [flang][driver] Mark -L as visible in Flang 
(authored by erjin, committed by bryanpkc).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158763

Files:
  clang/include/clang/Driver/Options.td
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/misc-flags.f90


Index: flang/test/Driver/misc-flags.f90
===
--- flang/test/Driver/misc-flags.f90
+++ flang/test/Driver/misc-flags.f90
@@ -7,6 +7,9 @@
 ! Make sure that `-fuse-ld' is "visible" to Flang's driver
 ! RUN: %flang -fuse-ld= -### %s
 
+! Make sure that `-L' is "visible" to Flang's driver
+! RUN: %flang -L/ -### %s
+
 program hello
   write(*,*), "Hello world!"
 end program hello
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -90,6 +90,7 @@
 ! HELP-NEXT: --help-hidden   Display help for hidden options
 ! HELP-NEXT: -help   Display available options
 ! HELP-NEXT: -I Add directory to the end of the list of 
include search paths
+! HELP-NEXT: -L Add directory to library search path
 ! HELP-NEXT: -march=  For a list of available architectures for 
the target use '-mcpu=help'
 ! HELP-NEXT: -mcpu=   For a list of available CPUs for the 
target use '-mcpu=help'
 ! HELP-NEXT: -mllvm=Alias for -mllvm
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -102,6 +102,7 @@
 ! CHECK-NEXT: --help-hidden   Display help for hidden options
 ! CHECK-NEXT: -help   Display available options
 ! CHECK-NEXT: -I Add directory to the end of the list of 
include search paths
+! CHECK-NEXT: -L Add directory to library search path
 ! CHECK-NEXT: -march=  For a list of available architectures 
for the target use '-mcpu=help'
 ! CHECK-NEXT: -mcpu=   For a list of available CPUs for the 
target use '-mcpu=help'
 ! CHECK-NEXT: -mllvm=Alias for -mllvm
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -818,6 +818,7 @@
 paths, for example if also specified with -isystem, the -I option
 will be ignored}]>;
 def L : JoinedOrSeparate<["-"], "L">, Flags<[RenderJoined]>, Group,
+Visibility<[ClangOption, FlangOption]>,
 MetaVarName<"">, HelpText<"Add directory to library search path">;
 def MD : Flag<["-"], "MD">, Group,
 HelpText<"Write a depfile containing user and system headers">;


Index: flang/test/Driver/misc-flags.f90
===
--- flang/test/Driver/misc-flags.f90
+++ flang/test/Driver/misc-flags.f90
@@ -7,6 +7,9 @@
 ! Make sure that `-fuse-ld' is "visible" to Flang's driver
 ! RUN: %flang -fuse-ld= -### %s
 
+! Make sure that `-L' is "visible" to Flang's driver
+! RUN: %flang -L/ -### %s
+
 program hello
   write(*,*), "Hello world!"
 end program hello
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -90,6 +90,7 @@
 ! HELP-NEXT: --help-hidden   Display help for hidden options
 ! HELP-NEXT: -help   Display available options
 ! HELP-NEXT: -I Add directory to the end of the list of include search paths
+! HELP-NEXT: -L Add directory to library search path
 ! HELP-NEXT: -march=  For a list of available architectures for the target use '-mcpu=help'
 ! HELP-NEXT: -mcpu=   For a list of available CPUs for the target use '-mcpu=help'
 ! HELP-NEXT: -mllvm=Alias for -mllvm
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -102,6 +102,7 @@
 ! CHECK-NEXT: --help-hidden   Display help for hidden options
 ! CHECK-NEXT: -help   Display available options
 ! CHECK-NEXT: -I Add directory to the end of the list of include search paths
+! CHECK-NEXT: -L Add directory to library search path
 ! CHECK-NEXT: -march=  For a list of available architectures for the target use '-mcpu=help'
 ! CHECK-NEXT: -mcpu=   For a list of available CPUs for the target use '-mcpu=help'
 ! CHECK-NEXT: -mllvm=

[clang] 1561495 - [flang][driver] Mark -L as visible in Flang

2023-08-25 Thread Bryan Chan via cfe-commits

Author: Hao Jin
Date: 2023-08-25T13:01:49-04:00
New Revision: 1561495cd128a641b9efcbb9d19d36e5a9c5e952

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

LOG: [flang][driver] Mark -L as visible in Flang

Reviewed By: awarzynski

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
flang/test/Driver/misc-flags.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 49bf5d6621b46f..da2dc934e37cfd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -818,6 +818,7 @@ are searched. If the same directory is in the SYSTEM 
include search
 paths, for example if also specified with -isystem, the -I option
 will be ignored}]>;
 def L : JoinedOrSeparate<["-"], "L">, Flags<[RenderJoined]>, Group,
+Visibility<[ClangOption, FlangOption]>,
 MetaVarName<"">, HelpText<"Add directory to library search path">;
 def MD : Flag<["-"], "MD">, Group,
 HelpText<"Write a depfile containing user and system headers">;

diff  --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 80708a7cfafe4b..7f827026b9203d 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -102,6 +102,7 @@
 ! CHECK-NEXT: --help-hidden   Display help for hidden options
 ! CHECK-NEXT: -help   Display available options
 ! CHECK-NEXT: -I Add directory to the end of the list of 
include search paths
+! CHECK-NEXT: -L Add directory to library search path
 ! CHECK-NEXT: -march=  For a list of available architectures 
for the target use '-mcpu=help'
 ! CHECK-NEXT: -mcpu=   For a list of available CPUs for the 
target use '-mcpu=help'
 ! CHECK-NEXT: -mllvm=Alias for -mllvm

diff  --git a/flang/test/Driver/driver-help.f90 
b/flang/test/Driver/driver-help.f90
index 7e7d127188093f..b1da592ca0bd8a 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -90,6 +90,7 @@
 ! HELP-NEXT: --help-hidden   Display help for hidden options
 ! HELP-NEXT: -help   Display available options
 ! HELP-NEXT: -I Add directory to the end of the list of 
include search paths
+! HELP-NEXT: -L Add directory to library search path
 ! HELP-NEXT: -march=  For a list of available architectures for 
the target use '-mcpu=help'
 ! HELP-NEXT: -mcpu=   For a list of available CPUs for the 
target use '-mcpu=help'
 ! HELP-NEXT: -mllvm=Alias for -mllvm

diff  --git a/flang/test/Driver/misc-flags.f90 
b/flang/test/Driver/misc-flags.f90
index ab5ed7e93dc8a1..61d763c5b64dd2 100644
--- a/flang/test/Driver/misc-flags.f90
+++ b/flang/test/Driver/misc-flags.f90
@@ -7,6 +7,9 @@
 ! Make sure that `-fuse-ld' is "visible" to Flang's driver
 ! RUN: %flang -fuse-ld= -### %s
 
+! Make sure that `-L' is "visible" to Flang's driver
+! RUN: %flang -L/ -### %s
+
 program hello
   write(*,*), "Hello world!"
 end program hello



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


[PATCH] D157547: Arm64EC entry/exit thunks, consolidated.

2023-08-25 Thread Jacek Caban via Phabricator via cfe-commits
jacek added a comment.

I published an initial version of my attempt at documenting this stuff here: 
https://wiki.winehq.org/ARM64ECToolchain.

It's not yet complete, but I hope it's already useful. I plan to extend it in 
the future. If some clarification or more information would be useful, please 
let me know and I will try to improve it or fill the gaps.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157547

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


[PATCH] D158763: [flang][driver] Mark -L as visible in Flang

2023-08-25 Thread Bryan Chan via Phabricator via cfe-commits
bryanpkc added inline comments.



Comment at: clang/include/clang/Driver/Options.td:821
 def L : JoinedOrSeparate<["-"], "L">, Flags<[RenderJoined]>, Group,
+Visibility<[ClangOption, FlangOption]>,
 MetaVarName<"">, HelpText<"Add directory to library search path">;

erjin wrote:
> bryanpkc wrote:
> > Question: How does Clang not give an error for `-L` if this wasn't visible 
> > to Clang?
> If there is no Visibility specified, the default Visibility is the 
> ClangOption. If we want to add an extra option, the visibility needs both.
Thanks for the explanation!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158763

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


[PATCH] D158813: [analyzer] MPIChecker: MPI_Waitall should respect count arg

2023-08-25 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp:195
+  const NonLoc Idx = Ctx.getSValBuilder().makeArrayIndex(i);
+  auto CountReached = SVB.evalBinOp(State, BO_GE, Idx, Count, 
ASTCtx.BoolTy)
+  .getAs();

steakhal wrote:
> In C for example, we might not have a Boot type AFAIK.
> Usually, we use `SVB.getConditionType()` in such cases.
Thanks for this tip.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158813

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


[PATCH] D158813: [analyzer] MPIChecker: MPI_Waitall should respect count arg

2023-08-25 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp:192-198
+SVal Count = CE.getArgSVal(0);
+for (size_t i = 0; i < ArrSize; ++i) {
+  const NonLoc Idx = Ctx.getSValBuilder().makeArrayIndex(i);
+  auto CountReached = SVB.evalBinOp(State, BO_GE, Idx, Count, 
ASTCtx.BoolTy)
+  .getAs();
+  if (CountReached && State->assume(*CountReached, true))
+break;

steakhal wrote:
> It's suspicious to me to compare stuff in the symbolic domain, such as `Idx 
> >= Count` here.
> And let me elaborate on why I think so.
> 
> I'd assume that the first argument of `MPI_Waitall` is usually just a number 
> literal, thus it's gonna be a ConcreteInt, so now we have `Count`.
> The `Index` you just created, obviously is just a ConcreteInt.
> After this, we could simply unwrap them and do the comparison without doing 
> it in the symbolic domain.
> 
> ---
> 
> As a sidenote, `State->assume(*CountReached, true)` would return a state in 
> two cases:
>  1) We can prove that the assumption holds.
>  2) We cannot disprove the assumption, thus it might hold, so we assume it 
> holds.
> This is probably not what you wanted in the first place, but it's probably 
> irrelelevant anyway.
I'll restrict this checker to handle `ConcreteInt` count only.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158813

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


[PATCH] D158813: [analyzer] MPIChecker: MPI_Waitall should respect count arg

2023-08-25 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/test/Analysis/mpichecker.cpp:286-288
+  for (int i = 0; i < 3; ++i)
+MPI_Ireduce(MPI_IN_PLACE, &buf, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD,
+&rs.req[i]);

steakhal wrote:
> This loop here implicitly depends on the fact that we only unroll loops 4 
> times.
> I'd prefer a simpler test where we don't even have a loop.
I'll unroll this loop.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158813

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


[PATCH] D158813: [analyzer] MPIChecker: MPI_Waitall should respect count arg

2023-08-25 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp:189-190
+ASTCtx.getCharWidth();
+const NonLoc MROffset =
+SVB.makeArrayIndex(MR->getAsOffset().getOffset() / ElemSizeInBits);
 

steakhal wrote:
> What implies that `MR->getAsOffset()` succeeds, and also what implies that 
> the `Offset` within that is not symbolic?
> Also, how can you use this without also using the result region?
> Without using that you don't know what is the anchor point, from which this 
> offset represent anything.
> ATM I believe the code assumes that `MR->getRegion()` equals to 
> `SuperRegion`, which might not be always the case.
> This could materialize a problem when you construct the element region later.
I'll restrict the checker to handle non-symbolic offset only.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158813

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


[PATCH] D158813: [analyzer] MPIChecker: MPI_Waitall should respect count arg

2023-08-25 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp:185-188
+CharUnits ElemSizeInChars = ASTCtx.getTypeSizeInChars(ElemType);
+int64_t ElemSizeInBits =
+(ElemSizeInChars.isZero() ? 1 : ElemSizeInChars.getQuantity()) *
+ASTCtx.getCharWidth();

steakhal wrote:
> How can `ElemSizeInChar` be zero?
> If it can be zero, could you demonstrate it by a test?
Type in the wild does not have to be of non-zero size. MPI vendors might choose 
whatever implementation as they want.
We are doing division so non-zero checking is necessary.

https://reviews.llvm.org/D158707 added a few general testcases for zero-sized 
type processing on dynamic extent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158813

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


  1   2   >