[clang] 5b36bf5 - [clang][NFC] Tidy up extension warnings about `_Static_assert`

2024-04-12 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-04-13T08:40:26+03:00
New Revision: 5b36bf549c8c900d0f01451e02abd821f38d4538

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

LOG: [clang][NFC] Tidy up extension warnings about `_Static_assert`

Some tests in `dr6xx.cpp` were using C11 `_Static_assert`, and were expecting 
extension warnings in C++98 mode because of that. This is noise, and we can do 
better than that.

Added: 


Modified: 
clang/test/CXX/drs/dr6xx.cpp

Removed: 




diff  --git a/clang/test/CXX/drs/dr6xx.cpp b/clang/test/CXX/drs/dr6xx.cpp
index d004d5aa4c7917..9d3613ae8589ea 100644
--- a/clang/test/CXX/drs/dr6xx.cpp
+++ b/clang/test/CXX/drs/dr6xx.cpp
@@ -5,6 +5,11 @@
 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,cxx11-20,since-cxx11 
-fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11 -fexceptions 
-fcxx-exceptions -pedantic-errors -fno-spell-checking
 
+#if __cplusplus == 199711L
+#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
+// cxx98-error@-1 {{variadic macros are a C99 feature}}
+#endif
+
 namespace cwg600 { // cwg600: 2.8
 struct S {
   void f(int);
@@ -43,8 +48,7 @@ namespace cwg601 { // cwg601: yes
 #endif
 
 #if __INT_MAX__ == 0x7FFF
-_Static_assert(0x8000 < -1, "0x8000 should be unsigned");
-// expected-error@-1 {{'_Static_assert' is a C11 extension}}
+static_assert(0x8000 < -1, "0x8000 should be unsigned");
 #endif
 
 #if MAX > 0x && 0x8000 < -1
@@ -223,15 +227,12 @@ namespace cwg619 { // cwg619: yes
   struct S { static int x[10]; };
 
   int x[];
-  _Static_assert(sizeof(x) == sizeof(int) * 10, "");
-  // expected-error@-1 {{'_Static_assert' is a C11 extension}}
+  static_assert(sizeof(x) == sizeof(int) * 10, "");
   extern int x[];
-  _Static_assert(sizeof(x) == sizeof(int) * 10, "");
-  // expected-error@-1 {{'_Static_assert' is a C11 extension}}
+  static_assert(sizeof(x) == sizeof(int) * 10, "");
 
   int S::x[];
-  _Static_assert(sizeof(S::x) == sizeof(int) * 10, "");
-  // expected-error@-1 {{'_Static_assert' is a C11 extension}}
+  static_assert(sizeof(S::x) == sizeof(int) * 10, "");
 
   void f() {
 extern int x[];
@@ -325,12 +326,10 @@ const bool MB_EQ_WC =
 ',' == L',' && '\\' == L'\\' && '"' == L'"' && '\'' == L'\'';
 #if __STDC_MB_MIGHT_NEQ_WC__
 #ifndef __FreeBSD__ // PR22208, FreeBSD expects us to give a bad (but 
conforming) answer here.
-_Static_assert(!MB_EQ_WC, "__STDC_MB_MIGHT_NEQ_WC__ but all basic source 
characters have same representation");
-// expected-error@-1 {{'_Static_assert' is a C11 extension}}
+static_assert(!MB_EQ_WC, "__STDC_MB_MIGHT_NEQ_WC__ but all basic source 
characters have same representation");
 #endif
 #else
-_Static_assert(MB_EQ_WC, "!__STDC_MB_MIGHT_NEQ_WC__ but some character 
diff ers");
-// expected-error@-1 {{'_Static_assert' is a C11 extension}}
+static_assert(MB_EQ_WC, "!__STDC_MB_MIGHT_NEQ_WC__ but some character 
diff ers");
 #endif
 }
 
@@ -488,8 +487,7 @@ namespace cwg642 { // cwg642: yes
 const int i = 2;
 {
   char i[i];
-  _Static_assert(sizeof(i) == 2, "");
-  // expected-error@-1 {{'_Static_assert' is a C11 extension}}
+  static_assert(sizeof(i) == 2, "");
 }
   }
 



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


[clang] [modules] allow use of ptrauth module from no_undeclared_includes system modules (PR #88432)

2024-04-12 Thread Ian Anderson via cfe-commits

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


[clang] 4138367 - [modules] allow use of ptrauth module from no_undeclared_includes system modules (#88432)

2024-04-12 Thread via cfe-commits

Author: Ian Anderson
Date: 2024-04-12T22:36:43-07:00
New Revision: 4138367444a2e3431cdfc7ab6e16c9cab5c76ad8

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

LOG: [modules] allow use of ptrauth module from no_undeclared_includes system 
modules (#88432)

Co-authored-by: Alex Lorenz 

Added: 
clang/test/Modules/Inputs/ptrauth-include-from-darwin/module.modulemap
clang/test/Modules/Inputs/ptrauth-include-from-darwin/ptrauth.h
clang/test/Modules/Inputs/ptrauth-include-from-darwin/stddef.h
clang/test/Modules/ptrauth-include-from-darwin.m

Modified: 
clang/lib/Basic/Module.cpp

Removed: 




diff  --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 256365d66bb907..bb212cde878826 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -305,6 +305,10 @@ bool Module::directlyUses(const Module *Requested) {
   if (Requested->fullModuleNameIs({"_Builtin_stddef", "max_align_t"}) ||
   Requested->fullModuleNameIs({"_Builtin_stddef_wint_t"}))
 return true;
+  // Darwin is allowed is to use our builtin 'ptrauth.h' and its accompanying
+  // module.
+  if (!Requested->Parent && Requested->Name == "ptrauth")
+return true;
 
   if (NoUndeclaredIncludes)
 UndeclaredUses.insert(Requested);

diff  --git 
a/clang/test/Modules/Inputs/ptrauth-include-from-darwin/module.modulemap 
b/clang/test/Modules/Inputs/ptrauth-include-from-darwin/module.modulemap
new file mode 100644
index 00..741b9bb1efc54d
--- /dev/null
+++ b/clang/test/Modules/Inputs/ptrauth-include-from-darwin/module.modulemap
@@ -0,0 +1,8 @@
+module libc [no_undeclared_includes] {
+  module stddef { header "stddef.h" export * }
+}
+
+module ptrauth {
+  header "ptrauth.h"
+  export *
+}

diff  --git a/clang/test/Modules/Inputs/ptrauth-include-from-darwin/ptrauth.h 
b/clang/test/Modules/Inputs/ptrauth-include-from-darwin/ptrauth.h
new file mode 100644
index 00..c8620b64b2ceef
--- /dev/null
+++ b/clang/test/Modules/Inputs/ptrauth-include-from-darwin/ptrauth.h
@@ -0,0 +1 @@
+void foo();

diff  --git a/clang/test/Modules/Inputs/ptrauth-include-from-darwin/stddef.h 
b/clang/test/Modules/Inputs/ptrauth-include-from-darwin/stddef.h
new file mode 100644
index 00..777a524fc67110
--- /dev/null
+++ b/clang/test/Modules/Inputs/ptrauth-include-from-darwin/stddef.h
@@ -0,0 +1 @@
+@import ptrauth;

diff  --git a/clang/test/Modules/ptrauth-include-from-darwin.m 
b/clang/test/Modules/ptrauth-include-from-darwin.m
new file mode 100644
index 00..72b0c36e7cb7d3
--- /dev/null
+++ b/clang/test/Modules/ptrauth-include-from-darwin.m
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I 
%S/Inputs/ptrauth-include-from-darwin %s -verify
+// expected-no-diagnostics
+
+@import libc;
+void bar() { foo(); }



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


[clang] 79dca25 - [InstallAPI] Replace std::string -> StringRef

2024-04-12 Thread Cyndy Ishida via cfe-commits

Author: Cyndy Ishida
Date: 2024-04-12T22:05:12-07:00
New Revision: 79dca25f4a0fefd47e9e37d9ce47d84dc0b3bedb

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

LOG: [InstallAPI] Replace std::string -> StringRef

Added: 


Modified: 
clang/tools/clang-installapi/Options.cpp

Removed: 




diff  --git a/clang/tools/clang-installapi/Options.cpp 
b/clang/tools/clang-installapi/Options.cpp
index 120ff3da899868..3dc61476ce09d9 100644
--- a/clang/tools/clang-installapi/Options.cpp
+++ b/clang/tools/clang-installapi/Options.cpp
@@ -372,7 +372,7 @@ bool Options::addFilePaths(InputArgList , PathSeq 
,
   }
   // Sort headers to ensure deterministic behavior.
   sort(*InputHeadersOrErr);
-  for (std::string  : *InputHeadersOrErr)
+  for (StringRef H : *InputHeadersOrErr)
 Headers.emplace_back(std::move(H));
 } else
   Headers.emplace_back(Path);
@@ -690,7 +690,7 @@ InstallAPIContext Options::createContext() {
 FrameworkName = getFrameworkNameFromInstallName(LinkerOpts.InstallName);
 
   // Process inputs.
-  for (const std::string  : DriverOpts.FileLists) {
+  for (const StringRef ListPath : DriverOpts.FileLists) {
 auto Buffer = FM->getBufferForFile(ListPath);
 if (auto Err = Buffer.getError()) {
   Diags->Report(diag::err_cannot_open_file) << ListPath << Err.message();



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


[clang] [clang] Implement `__is_pointer_interconvertible_base_of()` (PR #88473)

2024-04-12 Thread Vlad Serebrennikov via cfe-commits

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


[clang] 6dcb604 - [clang] Implement `__is_pointer_interconvertible_base_of()` (#88473)

2024-04-12 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-04-13T08:55:09+04:00
New Revision: 6dcb60481323c871556a5a14ed887a5867ece114

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

LOG: [clang] Implement `__is_pointer_interconvertible_base_of()` (#88473)

This patch implements intrinsic that supports
`std::is_pointer_interconvertible_base_of` type trait from
[P0466R5](https://wg21.link/p0466r5) "Layout-compatibility and
Pointer-interconvertibility Traits".

Normative wording:
> Comment: If `Base` and Derived are non-union class types and are not
(possibly _cv_-qualified) versions of the same type, `Derived` is a
complete type.
> Condition: `Derived` is unambiguously derived from `Base` without
regard to _cv_-qualifiers, and each object of type `Derived` is
pointer-interconvertible (6.7.2 [basic.compound]) with its `Base`
subobject, or `Base` and `Derived` are not unions and name the same
class type without regard to _cv_-qualifiers.

The paper also express the following intent:
> Note that `is_pointer_interconvertible_base_of_v` is always true
under this wording, even though `T` is not derived from itself.

I find the treatment of unions in the wording contradictory to this
intent, and I'm not able to find anything relevant in minutes or on the
reflector. That said, this patch implements what the wording says, since
it's very explicit about unions.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/TokenKinds.def
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45a9a79739a4eb..399d5ba796d15c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -98,7 +98,8 @@ C++20 Feature Support
   behavior can use the flag '-Xclang -fno-skip-odr-check-in-gmf'.
   (#GH79240).
 
-- Implemented the `__is_layout_compatible` intrinsic to support
+- Implemented the `__is_layout_compatible` and 
`__is_pointer_interconvertible_base_of`
+  intrinsics to support
   `P0466R5: Layout-compatibility and Pointer-interconvertibility Traits 
`_.
 
 - Clang now implements [module.import]p7 fully. Clang now will import module

diff  --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 800af0e6d04480..a27fbed358a60c 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -521,6 +521,7 @@ TYPE_TRAIT_1(__is_union, IsUnion, KEYCXX)
 TYPE_TRAIT_1(__has_unique_object_representations,
  HasUniqueObjectRepresentations, KEYCXX)
 TYPE_TRAIT_2(__is_layout_compatible, IsLayoutCompatible, KEYCXX)
+TYPE_TRAIT_2(__is_pointer_interconvertible_base_of, 
IsPointerInterconvertibleBaseOf, KEYCXX)
 
 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) KEYWORD(__##Trait, KEYCXX)
 #include "clang/Basic/TransformTypeTraits.def"

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6b9789334811ec..3b252f94dcbee7 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1999,6 +1999,8 @@ class Sema final : public SemaBase {
   };
 
   bool IsLayoutCompatible(QualType T1, QualType T2) const;
+  bool IsPointerInterconvertibleBaseOf(const TypeSourceInfo *Base,
+   const TypeSourceInfo *Derived);
 
   bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
  const FunctionProtoType *Proto);

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index abfd9a3031577b..8e21811b67d900 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -19710,6 +19710,27 @@ bool Sema::IsLayoutCompatible(QualType T1, QualType 
T2) const {
   return isLayoutCompatible(getASTContext(), T1, T2);
 }
 
+//===-- Pointer interconvertibility //
+
+bool Sema::IsPointerInterconvertibleBaseOf(const TypeSourceInfo *Base,
+   const TypeSourceInfo *Derived) {
+  QualType BaseT = Base->getType()->getCanonicalTypeUnqualified();
+  QualType DerivedT = Derived->getType()->getCanonicalTypeUnqualified();
+
+  if (BaseT->isStructureOrClassType() && DerivedT->isStructureOrClassType() &&
+  getASTContext().hasSameType(BaseT, DerivedT))
+return true;
+
+  if (!IsDerivedFrom(Derived->getTypeLoc().getBeginLoc(), DerivedT, BaseT))
+return false;
+
+  // Per [basic.compound]/4.3, containing object has to be standard-layout.
+  if (DerivedT->getAsCXXRecordDecl()->isStandardLayout())
+return true;
+
+  return false;
+}
+
 //===--- CHECK: pointer_with_type_tag 

[clang] [clang] Introduce `SemaCUDA` (PR #88559)

2024-04-12 Thread Vlad Serebrennikov via cfe-commits

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


[clang] 94b3c19 - [M68k][clang] Enable frame pointer optimization by default (#87264)

2024-04-12 Thread via cfe-commits

Author: Jim Lin
Date: 2024-04-13T12:39:30+08:00
New Revision: 94b3c192d3468752e6bc2f20957d433bccdb8ff3

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

LOG: [M68k][clang] Enable frame pointer optimization by default (#87264)

Enable frame pointer optimization by default to match it with gcc.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/frame-pointer-elim.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 62a53b85ce098b..f10aa4dfaa9ddd 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -114,6 +114,7 @@ static bool useFramePointerForTargetByDefault(const 
llvm::opt::ArgList ,
   case llvm::Triple::csky:
   case llvm::Triple::loongarch32:
   case llvm::Triple::loongarch64:
+  case llvm::Triple::m68k:
 return !clang::driver::tools::areOptimizationsEnabled(Args);
   default:
 break;

diff  --git a/clang/test/Driver/frame-pointer-elim.c 
b/clang/test/Driver/frame-pointer-elim.c
index 847c5b7b0b01f3..e1b0a468ab8259 100644
--- a/clang/test/Driver/frame-pointer-elim.c
+++ b/clang/test/Driver/frame-pointer-elim.c
@@ -125,6 +125,12 @@
 // RUN: %clang -### -target sparc64 -S -O1 %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=KEEP-NONE %s
 
+// M68k targets omit the frame pointer when optimizations are enabled.
+// RUN: %clang -### -target m68k -S %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-ALL %s
+// RUN: %clang -### -target m68k -S -O1 %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=KEEP-NONE %s
+
 // For AAarch32 (A32, T32) linux targets, default omit frame pointer when
 // optimizations are enabled.
 // RUN: %clang -### -target arm-linux-gnueabihf- -marm -S %s 2>&1 | \



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


[clang] [M68k][clang] Enable frame pointer optimization by default (PR #87264)

2024-04-12 Thread via cfe-commits

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


[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

2024-04-12 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/87130

>From 23422a0b3af3e070fed5ae86ed0f67acec066c0a Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Fri, 29 Mar 2024 17:48:14 -0700
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/lib/Sema/CMakeLists.txt |  1 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 31 +--
 clang/test/AST/ast-dump-attr-json.cpp |  1 +
 clang/test/Sema/alias-unused.c| 30 +-
 4 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index e8bff07ced0cfa..7657536fabd1eb 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -1,5 +1,6 @@
 set(LLVM_LINK_COMPONENTS
   Core
+  Demangle
   FrontendHLSL
   FrontendOpenMP
   MC
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index f25f3afd0f4af2..8ed5242f325e5e 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -42,6 +42,7 @@
 #include "clang/Sema/SemaInternal.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Demangle/Demangle.h"
 #include "llvm/IR/Assumptions.h"
 #include "llvm/MC/MCSectionMachO.h"
 #include "llvm/Support/Error.h"
@@ -1980,6 +1981,23 @@ static void handleWeakRefAttr(Sema , Decl *D, const 
ParsedAttr ) {
   D->addAttr(::new (S.Context) WeakRefAttr(S.Context, AL));
 }
 
+// Mark alias/ifunc target as used. For C++, we look up the demangled name
+// ignoring parameters. This should handle the majority of use cases while
+// leaveing false positives for namespace scope names and false negatives in
+// the presence of overloads.
+static void markUsedForAliasOrIfunc(Sema , Decl *D, const ParsedAttr ,
+StringRef Str) {
+  char *Demangled = llvm::itaniumDemangle(Str, /*ParseParams=*/false);
+  if (Demangled)
+Str = Demangled;
+  const DeclarationNameInfo target((Str), AL.getLoc());
+  LookupResult LR(S, target, Sema::LookupOrdinaryName);
+  if (S.LookupQualifiedName(LR, S.getCurLexicalContext()))
+for (NamedDecl *ND : LR)
+  ND->markUsed(S.Context);
+  free(Demangled);
+}
+
 static void handleIFuncAttr(Sema , Decl *D, const ParsedAttr ) {
   StringRef Str;
   if (!S.checkStringLiteralArgumentAttr(AL, 0, Str))
@@ -1992,6 +2010,7 @@ static void handleIFuncAttr(Sema , Decl *D, const 
ParsedAttr ) {
 return;
   }
 
+  markUsedForAliasOrIfunc(S, D, AL, Str);
   D->addAttr(::new (S.Context) IFuncAttr(S.Context, AL, Str));
 }
 
@@ -2026,17 +2045,7 @@ static void handleAliasAttr(Sema , Decl *D, const 
ParsedAttr ) {
 }
   }
 
-  // Mark target used to prevent unneeded-internal-declaration warnings.
-  if (!S.LangOpts.CPlusPlus) {
-// FIXME: demangle Str for C++, as the attribute refers to the mangled
-// linkage name, not the pre-mangled identifier.
-const DeclarationNameInfo target((Str), AL.getLoc());
-LookupResult LR(S, target, Sema::LookupOrdinaryName);
-if (S.LookupQualifiedName(LR, S.getCurLexicalContext()))
-  for (NamedDecl *ND : LR)
-ND->markUsed(S.Context);
-  }
-
+  markUsedForAliasOrIfunc(S, D, AL, Str);
   D->addAttr(::new (S.Context) AliasAttr(S.Context, AL, Str));
 }
 
diff --git a/clang/test/AST/ast-dump-attr-json.cpp 
b/clang/test/AST/ast-dump-attr-json.cpp
index 051c2956abfdf7..883e584bfedf07 100644
--- a/clang/test/AST/ast-dump-attr-json.cpp
+++ b/clang/test/AST/ast-dump-attr-json.cpp
@@ -46,6 +46,7 @@ __thread __attribute__ ((tls_model ("local-exec"))) int 
tls_model_var;
 // CHECK-NEXT:"tokLen": 11
 // CHECK-NEXT:   }
 // CHECK-NEXT:  },
+// CHECK-NEXT:  "isUsed": true,
 // CHECK-NEXT:  "name": "global_decl",
 // CHECK-NEXT:  "mangledName": "global_decl",
 // CHECK-NEXT:  "type": {
diff --git a/clang/test/Sema/alias-unused.c b/clang/test/Sema/alias-unused.c
index de9fc8cc737662..030b5737a93a21 100644
--- a/clang/test/Sema/alias-unused.c
+++ b/clang/test/Sema/alias-unused.c
@@ -1,7 +1,35 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wunneeded-internal-declaration -x 
c -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wunused -x c -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wunused -x c++ -verify %s
+
+#ifdef __cplusplus
+extern "C" {
+#else
 // expected-no-diagnostics
+#endif
 static int f(void) { return 42; }
 int g(void) __attribute__((alias("f")));
 
 static int foo [] = { 42, 0xDEAD };
 extern typeof(foo) bar __attribute__((unused, alias("foo")));
+
+static int (*resolver(void))(void) { return f; }
+int ifunc(void) __attribute__((ifunc("resolver")));
+
+#ifdef __cplusplus
+}
+
+/// We demangle alias/ifunc target and mark all found functions as used.
+static int f1(int) { return 42; }
+static int f1(void) { return 42; }
+int 

[clang] f22c300 - [test] alias-unused.cpp: set triple to Linux

2024-04-12 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-04-12T20:30:15-07:00
New Revision: f22c30063ddcb7f8e8c4fb0496f515be7f9408b8

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

LOG: [test] alias-unused.cpp: set triple to Linux

Otherwise the test would fail on Darwin and other platforms that use
Itanium ABI but do not support alias/ifunc.

Added: 


Modified: 
clang/test/Sema/alias-unused.cpp

Removed: 




diff  --git a/clang/test/Sema/alias-unused.cpp 
b/clang/test/Sema/alias-unused.cpp
index 509d3e26225d74..dc8e46f072d74d 100644
--- a/clang/test/Sema/alias-unused.cpp
+++ b/clang/test/Sema/alias-unused.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -x c -verify %s
-// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -verify=expected,cxx %s
+// RUN: %clang_cc1 -triple x86_64-linux -Wunused -x c -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux -Wunused -verify=expected,cxx %s
 
 #ifdef __cplusplus
 extern "C" {



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


[clang] [llvm] [llvm][support] Implement tracing virtual file system (PR #88326)

2024-04-12 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/88326

>From 0afe6a50e4faf95769a17a0d2aaf79b272e991b4 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Fri, 12 Apr 2024 10:47:13 -0700
Subject: [PATCH] [llvm][support] Implement tracing virtual file system

---
 .../DependencyScanningFilesystemTest.cpp  | 34 +-
 llvm/include/llvm/Support/VirtualFileSystem.h | 54 
 llvm/lib/Support/VirtualFileSystem.cpp| 13 
 .../Support/VirtualFileSystemTest.cpp | 64 +++
 4 files changed, 134 insertions(+), 31 deletions(-)

diff --git 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
index 87bb67cfd9327c..691cd3641eb045 100644
--- 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
+++ 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
@@ -13,39 +13,11 @@
 
 using namespace clang::tooling::dependencies;
 
-namespace {
-struct InstrumentingFilesystem
-: llvm::RTTIExtends {
-  unsigned NumStatusCalls = 0;
-  unsigned NumGetRealPathCalls = 0;
-  unsigned NumExistsCalls = 0;
-
-  using llvm::RTTIExtends::RTTIExtends;
-
-  llvm::ErrorOr status(const llvm::Twine ) override {
-++NumStatusCalls;
-return ProxyFileSystem::status(Path);
-  }
-
-  std::error_code getRealPath(const llvm::Twine ,
-  llvm::SmallVectorImpl ) override {
-++NumGetRealPathCalls;
-return ProxyFileSystem::getRealPath(Path, Output);
-  }
-
-  bool exists(const llvm::Twine ) override {
-++NumExistsCalls;
-return ProxyFileSystem::exists(Path);
-  }
-};
-} // namespace
-
 TEST(DependencyScanningWorkerFilesystem, CacheStatusFailures) {
   auto InMemoryFS = llvm::makeIntrusiveRefCnt();
 
   auto InstrumentingFS =
-  llvm::makeIntrusiveRefCnt(InMemoryFS);
+  llvm::makeIntrusiveRefCnt(InMemoryFS);
 
   DependencyScanningFilesystemSharedCache SharedCache;
   DependencyScanningWorkerFilesystem DepFS(SharedCache, InstrumentingFS);
@@ -71,7 +43,7 @@ TEST(DependencyScanningFilesystem, CacheGetRealPath) {
   InMemoryFS->addFile("/bar", 0, llvm::MemoryBuffer::getMemBuffer(""));
 
   auto InstrumentingFS =
-  llvm::makeIntrusiveRefCnt(InMemoryFS);
+  llvm::makeIntrusiveRefCnt(InMemoryFS);
 
   DependencyScanningFilesystemSharedCache SharedCache;
   DependencyScanningWorkerFilesystem DepFS(SharedCache, InstrumentingFS);
@@ -157,7 +129,7 @@ TEST(DependencyScanningFilesystem, 
RealPathAndStatusInvariants) {
 TEST(DependencyScanningFilesystem, CacheStatOnExists) {
   auto InMemoryFS = llvm::makeIntrusiveRefCnt();
   auto InstrumentingFS =
-  llvm::makeIntrusiveRefCnt(InMemoryFS);
+  llvm::makeIntrusiveRefCnt(InMemoryFS);
   InMemoryFS->setCurrentWorkingDirectory("/");
   InMemoryFS->addFile("/foo", 0, llvm::MemoryBuffer::getMemBuffer(""));
   InMemoryFS->addFile("/bar", 0, llvm::MemoryBuffer::getMemBuffer(""));
diff --git a/llvm/include/llvm/Support/VirtualFileSystem.h 
b/llvm/include/llvm/Support/VirtualFileSystem.h
index 0113d6b7da25d3..f128c123907ef7 100644
--- a/llvm/include/llvm/Support/VirtualFileSystem.h
+++ b/llvm/include/llvm/Support/VirtualFileSystem.h
@@ -1129,6 +1129,60 @@ class YAMLVFSWriter {
   void write(llvm::raw_ostream );
 };
 
+/// File system that tracks the number of calls to the underlying file system.
+/// This is particularly useful when wrapped around \c RealFileSystem to add
+/// lightweight tracking of expensive syscalls.
+class TracingFileSystem
+: public llvm::RTTIExtends {
+public:
+  static const char ID;
+
+  std::size_t NumStatusCalls = 0;
+  std::size_t NumOpenFileForReadCalls = 0;
+  std::size_t NumDirBeginCalls = 0;
+  std::size_t NumGetRealPathCalls = 0;
+  std::size_t NumExistsCalls = 0;
+  std::size_t NumIsLocalCalls = 0;
+
+  TracingFileSystem(llvm::IntrusiveRefCntPtr FS)
+  : RTTIExtends(std::move(FS)) {}
+
+  ErrorOr status(const Twine ) override {
+++NumStatusCalls;
+return ProxyFileSystem::status(Path);
+  }
+
+  ErrorOr> openFileForRead(const Twine ) override {
+++NumOpenFileForReadCalls;
+return ProxyFileSystem::openFileForRead(Path);
+  }
+
+  directory_iterator dir_begin(const Twine , std::error_code ) override 
{
+++NumDirBeginCalls;
+return ProxyFileSystem::dir_begin(Dir, EC);
+  }
+
+  std::error_code getRealPath(const Twine ,
+  SmallVectorImpl ) override {
+++NumGetRealPathCalls;
+return ProxyFileSystem::getRealPath(Path, Output);
+  }
+
+  bool exists(const Twine ) override {
+++NumExistsCalls;
+return ProxyFileSystem::exists(Path);
+  }
+
+  std::error_code isLocal(const Twine , bool ) override {
+++NumIsLocalCalls;
+return ProxyFileSystem::isLocal(Path, Result);
+  }
+
+protected:
+  void printImpl(raw_ostream , PrintType Type,
+ unsigned IndentLevel) const override;
+};
+
 

[clang] Reapply "[Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (#87541)" (PR #88311)

2024-04-12 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

The expression type need to be set to `ASTContext::DependentTy` (currently, 
it's set to `ASTContext::OverloadTy`) if we find a member of a base class (as 
it is for direct members). Should be an easy fix, so I'm thinking of not 
reverting and just opening a PR that will address this.

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


[clang] [llvm] [llvm][support] Implement tracing virtual file system (PR #88326)

2024-04-12 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/88326

>From 44791e807564e9c6eb489eccdefb1c0f2647a38a Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Fri, 12 Apr 2024 10:47:13 -0700
Subject: [PATCH] [llvm][support] Implement tracing virtual file system

---
 .../DependencyScanningFilesystemTest.cpp  | 34 +-
 llvm/include/llvm/Support/VirtualFileSystem.h | 54 
 llvm/lib/Support/VirtualFileSystem.cpp| 13 
 .../Support/VirtualFileSystemTest.cpp | 64 +++
 4 files changed, 134 insertions(+), 31 deletions(-)

diff --git 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
index 87bb67cfd9327c..691cd3641eb045 100644
--- 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
+++ 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
@@ -13,39 +13,11 @@
 
 using namespace clang::tooling::dependencies;
 
-namespace {
-struct InstrumentingFilesystem
-: llvm::RTTIExtends {
-  unsigned NumStatusCalls = 0;
-  unsigned NumGetRealPathCalls = 0;
-  unsigned NumExistsCalls = 0;
-
-  using llvm::RTTIExtends::RTTIExtends;
-
-  llvm::ErrorOr status(const llvm::Twine ) override {
-++NumStatusCalls;
-return ProxyFileSystem::status(Path);
-  }
-
-  std::error_code getRealPath(const llvm::Twine ,
-  llvm::SmallVectorImpl ) override {
-++NumGetRealPathCalls;
-return ProxyFileSystem::getRealPath(Path, Output);
-  }
-
-  bool exists(const llvm::Twine ) override {
-++NumExistsCalls;
-return ProxyFileSystem::exists(Path);
-  }
-};
-} // namespace
-
 TEST(DependencyScanningWorkerFilesystem, CacheStatusFailures) {
   auto InMemoryFS = llvm::makeIntrusiveRefCnt();
 
   auto InstrumentingFS =
-  llvm::makeIntrusiveRefCnt(InMemoryFS);
+  llvm::makeIntrusiveRefCnt(InMemoryFS);
 
   DependencyScanningFilesystemSharedCache SharedCache;
   DependencyScanningWorkerFilesystem DepFS(SharedCache, InstrumentingFS);
@@ -71,7 +43,7 @@ TEST(DependencyScanningFilesystem, CacheGetRealPath) {
   InMemoryFS->addFile("/bar", 0, llvm::MemoryBuffer::getMemBuffer(""));
 
   auto InstrumentingFS =
-  llvm::makeIntrusiveRefCnt(InMemoryFS);
+  llvm::makeIntrusiveRefCnt(InMemoryFS);
 
   DependencyScanningFilesystemSharedCache SharedCache;
   DependencyScanningWorkerFilesystem DepFS(SharedCache, InstrumentingFS);
@@ -157,7 +129,7 @@ TEST(DependencyScanningFilesystem, 
RealPathAndStatusInvariants) {
 TEST(DependencyScanningFilesystem, CacheStatOnExists) {
   auto InMemoryFS = llvm::makeIntrusiveRefCnt();
   auto InstrumentingFS =
-  llvm::makeIntrusiveRefCnt(InMemoryFS);
+  llvm::makeIntrusiveRefCnt(InMemoryFS);
   InMemoryFS->setCurrentWorkingDirectory("/");
   InMemoryFS->addFile("/foo", 0, llvm::MemoryBuffer::getMemBuffer(""));
   InMemoryFS->addFile("/bar", 0, llvm::MemoryBuffer::getMemBuffer(""));
diff --git a/llvm/include/llvm/Support/VirtualFileSystem.h 
b/llvm/include/llvm/Support/VirtualFileSystem.h
index 0113d6b7da25d3..f128c123907ef7 100644
--- a/llvm/include/llvm/Support/VirtualFileSystem.h
+++ b/llvm/include/llvm/Support/VirtualFileSystem.h
@@ -1129,6 +1129,60 @@ class YAMLVFSWriter {
   void write(llvm::raw_ostream );
 };
 
+/// File system that tracks the number of calls to the underlying file system.
+/// This is particularly useful when wrapped around \c RealFileSystem to add
+/// lightweight tracking of expensive syscalls.
+class TracingFileSystem
+: public llvm::RTTIExtends {
+public:
+  static const char ID;
+
+  std::size_t NumStatusCalls = 0;
+  std::size_t NumOpenFileForReadCalls = 0;
+  std::size_t NumDirBeginCalls = 0;
+  std::size_t NumGetRealPathCalls = 0;
+  std::size_t NumExistsCalls = 0;
+  std::size_t NumIsLocalCalls = 0;
+
+  TracingFileSystem(llvm::IntrusiveRefCntPtr FS)
+  : RTTIExtends(std::move(FS)) {}
+
+  ErrorOr status(const Twine ) override {
+++NumStatusCalls;
+return ProxyFileSystem::status(Path);
+  }
+
+  ErrorOr> openFileForRead(const Twine ) override {
+++NumOpenFileForReadCalls;
+return ProxyFileSystem::openFileForRead(Path);
+  }
+
+  directory_iterator dir_begin(const Twine , std::error_code ) override 
{
+++NumDirBeginCalls;
+return ProxyFileSystem::dir_begin(Dir, EC);
+  }
+
+  std::error_code getRealPath(const Twine ,
+  SmallVectorImpl ) override {
+++NumGetRealPathCalls;
+return ProxyFileSystem::getRealPath(Path, Output);
+  }
+
+  bool exists(const Twine ) override {
+++NumExistsCalls;
+return ProxyFileSystem::exists(Path);
+  }
+
+  std::error_code isLocal(const Twine , bool ) override {
+++NumIsLocalCalls;
+return ProxyFileSystem::isLocal(Path, Result);
+  }
+
+protected:
+  void printImpl(raw_ostream , PrintType Type,
+ unsigned IndentLevel) const override;
+};
+
 

[clang] [clang-scan-deps] Fix contention when updating `TrackingStatistic`s in hot code paths in `FileManager`. (PR #88427)

2024-04-12 Thread Volodymyr Sapsai via cfe-commits

vsapsai wrote:

The bigger idea is that not enabled stats should be negligibly cheap. As for 
me, the problem is in that not being true. Let me check how we have expensive 
stats all the time.

Extra fixes are good but I'm concerned they help only with these specific stats 
while others might still cause problems in different contexts.

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


[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-04-12 Thread Dan Liew via cfe-commits

delcypher wrote:

@rapidsna @bwendling I've put the experimental feature flag for late parsing in 
a separate PR (#88596). I've not updated this PR to be based on that PR yet but 
will do soon. I figured the code for experimental feature flag was large enough 
that it deserved its own PR to make things easier to review.

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


[clang] [Attributes] Support Attributes being declared as only supporting late parsing when passing an experimental feature flag (PR #88596)

2024-04-12 Thread Dan Liew via cfe-commits

https://github.com/delcypher updated 
https://github.com/llvm/llvm-project/pull/88596

>From 554287a724361a510389d7f34f9b57cf434b9657 Mon Sep 17 00:00:00 2001
From: Dan Liew 
Date: Fri, 12 Apr 2024 17:36:19 -0700
Subject: [PATCH] [Attributes] Support Attributes being declared as only
 supporting late parsing when passing an experimental feature flag

This patch changes the `LateParsed` field of `Attr` in `Attr.td` to be
an instantiation of the new `LateAttrParseKind` class. The instation can be one 
of the following:

* `LateAttrParsingNever` - Corresponds with the false value of `LateParsed` 
prior to this patch (the default for an attribute).
* `LateAttrParsingAlways` - Corresponds with the true value of `LateParsed` 
prior to this patch.
* `LateAttrParsingExperimentalOnly` - A new mode described below.

`LateAttrParsingExperimentalOnly` means that the attribute will be late
parsed if the new the `ExperimentalLateParseAttributes` language option (also 
introduced in
this patch) is enabled and will **not** be late parsed if the language
option is disabled.

The new `ExperimentalLateParseAttributes` language option is controlled
by a new driver and frontend flag
(`-fexperimental-late-parse-attributes`). A driver test is included to
check that the driver passes the flag to CC1.

In this patch the `LateAttrParsingExperimentalOnly` is not adopted by
any attribute so `-fexperimental-late-pase-attributes` and the
corresponding language option currently have no effect on compilation.
This is why this patch does not include any test cases that test
`LateAttrParsingExperimentalOnly`'s behavior.

The motivation for this patch is to be able to late parse the new
`counted_by` attribute but only do so when a feature flag is passed.
This was discussed during the [bounds-safety 
RFC](https://discourse.llvm.org/t/rfc-enforcing-bounds-safety-in-c-fbounds-safety/70854/68).

Adoption of `LateAttrParsingExperimentalOnly` for the `counted_by`
attributed will be handled separately in another patch (likely
https://github.com/llvm/llvm-project/pull/87596).
---
 clang/include/clang/Basic/Attr.td |  46 +++---
 clang/include/clang/Basic/LangOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   7 +
 clang/include/clang/Parse/Parser.h|   4 +
 clang/lib/Driver/ToolChains/Clang.cpp |   3 +
 clang/lib/Parse/ParseDecl.cpp |  19 ++-
 .../experimental-late-parse-attributes.c  |  12 ++
 clang/utils/TableGen/ClangAttrEmitter.cpp | 137 --
 8 files changed, 192 insertions(+), 37 deletions(-)
 create mode 100644 clang/test/Driver/experimental-late-parse-attributes.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022dc..da76f807cd676c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -592,6 +592,16 @@ class AttrSubjectMatcherAggregateRule 
{
 
 def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule;
 
+// Late Attribute parsing mode enum
+class LateAttrParseKind  {
+  int Kind = val;
+}
+def LateAttrParsingNever : LateAttrParseKind<0>; // Never late parsed
+def LateAttrParsingAlways: LateAttrParseKind<1>; // Always late parsed
+// Late parsed if `-fexperimental-late-parse-attributes` is on and parsed
+// normally if off.
+def LateAttrParsingExperimentalOnly : LateAttrParseKind<2>;
+
 class Attr {
   // The various ways in which an attribute can be spelled in source
   list Spellings;
@@ -603,8 +613,8 @@ class Attr {
   list Accessors = [];
   // Specify targets for spellings.
   list TargetSpecificSpellings = [];
-  // Set to true for attributes with arguments which require delayed parsing.
-  bit LateParsed = 0;
+  // Specifies the late parsing kind.
+  LateAttrParseKind LateParsed = LateAttrParsingNever;
   // Set to false to prevent an attribute from being propagated from a template
   // to the instantiation.
   bit Clone = 1;
@@ -3173,7 +3183,7 @@ def DiagnoseIf : InheritableAttr {
   BoolArgument<"ArgDependent", 0, /*fake*/ 1>,
   DeclArgument];
   let InheritEvenIfAlreadyPresent = 1;
-  let LateParsed = 1;
+  let LateParsed = LateAttrParsingAlways;
   let AdditionalMembers = [{
 bool isError() const { return diagnosticType == DT_Error; }
 bool isWarning() const { return diagnosticType == DT_Warning; }
@@ -3472,7 +3482,7 @@ def AssertCapability : InheritableAttr {
   let Spellings = [Clang<"assert_capability", 0>,
Clang<"assert_shared_capability", 0>];
   let Subjects = SubjectList<[Function]>;
-  let LateParsed = 1;
+  let LateParsed = LateAttrParsingAlways;
   let TemplateDependent = 1;
   let ParseArgumentsAsUnevaluated = 1;
   let InheritEvenIfAlreadyPresent = 1;
@@ -3488,7 +3498,7 @@ def AcquireCapability : InheritableAttr {
GNU<"exclusive_lock_function">,
GNU<"shared_lock_function">];
   let Subjects = SubjectList<[Function]>;
-  let LateParsed = 1;
+  

[clang] [Attributes] Support Attributes being declared as only supporting late parsing when passing an experimental feature flag (PR #88596)

2024-04-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Dan Liew (delcypher)


Changes

[Attributes] Support Attributes being declared as only supporting late parsing 
when passing an experimental feature flag

This patch changes the `LateParsed` field of `Attr` in `Attr.td` to be an 
instantiation of the new `LateAttrParseKind` class. The instation can be one of 
the following:

* LateAttrParsingNever - Corresponds with the false value of `LateParsed` prior 
to this patch (the default for an attribute).
* LateAttrParsingAlways - Corresponds with the true value of `LateParsed` prior 
to this patch.
* LateAttrParsingExperimentalOnly - A new mode described below.

`LateAttrParsingExperimentalOnly` means that the attribute will be late parsed 
if the new the `ExperimentalLateParseAttributes` language option (also 
introduced in this patch) is enabled and will **not** be late parsed if the 
language option is disabled.

The new `ExperimentalLateParseAttributes` language option is controlled by a 
new driver and frontend flag
(`-fexperimental-late-parse-attributes`). A driver test is included to check 
that the driver passes the flag to CC1.

In this patch the `LateAttrParsingExperimentalOnly` is not adopted by any 
attribute so `-fexperimental-late-pase-attributes` and the corresponding 
language option currently have no effect on compilation. This is why this patch 
does not include any test cases that test `LateAttrParsingExperimentalOnly`'s 
behavior.

The motivation for this patch is to be able to late parse the new `counted_by` 
attribute but only do so when a feature flag is passed. This was discussed 
during the [bounds-safety 
RFC](https://discourse.llvm.org/t/rfc-enforcing-bounds-safety-in-c-fbounds-safety/70854/68).

Adoption of `LateAttrParsingExperimentalOnly` for the `counted_by` attributed 
will be handled separately in another patch (likely 
https://github.com/llvm/llvm-project/pull/87596).

---

Patch is 20.25 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/88596.diff


8 Files Affected:

- (modified) clang/include/clang/Basic/Attr.td (+28-18) 
- (modified) clang/include/clang/Basic/LangOptions.def (+1) 
- (modified) clang/include/clang/Driver/Options.td (+7) 
- (modified) clang/include/clang/Parse/Parser.h (+4) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+3) 
- (modified) clang/lib/Parse/ParseDecl.cpp (+16-3) 
- (added) clang/test/Driver/experimental-late-parse-attributes.c (+12) 
- (modified) clang/utils/TableGen/ClangAttrEmitter.cpp (+121-16) 


``diff
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022dc..da76f807cd676c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -592,6 +592,16 @@ class AttrSubjectMatcherAggregateRule 
{
 
 def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule;
 
+// Late Attribute parsing mode enum
+class LateAttrParseKind  {
+  int Kind = val;
+}
+def LateAttrParsingNever : LateAttrParseKind<0>; // Never late parsed
+def LateAttrParsingAlways: LateAttrParseKind<1>; // Always late parsed
+// Late parsed if `-fexperimental-late-parse-attributes` is on and parsed
+// normally if off.
+def LateAttrParsingExperimentalOnly : LateAttrParseKind<2>;
+
 class Attr {
   // The various ways in which an attribute can be spelled in source
   list Spellings;
@@ -603,8 +613,8 @@ class Attr {
   list Accessors = [];
   // Specify targets for spellings.
   list TargetSpecificSpellings = [];
-  // Set to true for attributes with arguments which require delayed parsing.
-  bit LateParsed = 0;
+  // Specifies the late parsing kind.
+  LateAttrParseKind LateParsed = LateAttrParsingNever;
   // Set to false to prevent an attribute from being propagated from a template
   // to the instantiation.
   bit Clone = 1;
@@ -3173,7 +3183,7 @@ def DiagnoseIf : InheritableAttr {
   BoolArgument<"ArgDependent", 0, /*fake*/ 1>,
   DeclArgument];
   let InheritEvenIfAlreadyPresent = 1;
-  let LateParsed = 1;
+  let LateParsed = LateAttrParsingAlways;
   let AdditionalMembers = [{
 bool isError() const { return diagnosticType == DT_Error; }
 bool isWarning() const { return diagnosticType == DT_Warning; }
@@ -3472,7 +3482,7 @@ def AssertCapability : InheritableAttr {
   let Spellings = [Clang<"assert_capability", 0>,
Clang<"assert_shared_capability", 0>];
   let Subjects = SubjectList<[Function]>;
-  let LateParsed = 1;
+  let LateParsed = LateAttrParsingAlways;
   let TemplateDependent = 1;
   let ParseArgumentsAsUnevaluated = 1;
   let InheritEvenIfAlreadyPresent = 1;
@@ -3488,7 +3498,7 @@ def AcquireCapability : InheritableAttr {
GNU<"exclusive_lock_function">,
GNU<"shared_lock_function">];
   let Subjects = SubjectList<[Function]>;
-  let LateParsed = 1;
+  let LateParsed = LateAttrParsingAlways;
   let TemplateDependent = 1;
   let 

[clang] [Attributes] Support Attributes being declared as only supporting late parsing when passing an experimental feature flag (PR #88596)

2024-04-12 Thread Dan Liew via cfe-commits

https://github.com/delcypher created 
https://github.com/llvm/llvm-project/pull/88596

[Attributes] Support Attributes being declared as only supporting late parsing 
when passing an experimental feature flag

This patch changes the `LateParsed` field of `Attr` in `Attr.td` to be an 
instantiation of the new `LateAttrParseKind` class. The instation can be one of 
the following:

* LateAttrParsingNever - Corresponds with the false value of `LateParsed` prior 
to this patch (the default for an attribute).
* LateAttrParsingAlways - Corresponds with the true value of `LateParsed` prior 
to this patch.
* LateAttrParsingExperimentalOnly - A new mode described below.

`LateAttrParsingExperimentalOnly` means that the attribute will be late parsed 
if the new the `ExperimentalLateParseAttributes` language option (also 
introduced in this patch) is enabled and will **not** be late parsed if the 
language option is disabled.

The new `ExperimentalLateParseAttributes` language option is controlled by a 
new driver and frontend flag
(`-fexperimental-late-parse-attributes`). A driver test is included to check 
that the driver passes the flag to CC1.

In this patch the `LateAttrParsingExperimentalOnly` is not adopted by any 
attribute so `-fexperimental-late-pase-attributes` and the corresponding 
language option currently have no effect on compilation. This is why this patch 
does not include any test cases that test `LateAttrParsingExperimentalOnly`'s 
behavior.

The motivation for this patch is to be able to late parse the new `counted_by` 
attribute but only do so when a feature flag is passed. This was discussed 
during the [bounds-safety 
RFC](https://discourse.llvm.org/t/rfc-enforcing-bounds-safety-in-c-fbounds-safety/70854/68).

Adoption of `LateAttrParsingExperimentalOnly` for the `counted_by` attributed 
will be handled separately in another patch (likely 
https://github.com/llvm/llvm-project/pull/87596).

>From 9e4809533c56431731c1f20a2eb951bc1cc5c60e Mon Sep 17 00:00:00 2001
From: Dan Liew 
Date: Fri, 12 Apr 2024 17:36:19 -0700
Subject: [PATCH] [Attributes] Support Attributes being declared as only
 supporting late parsing when passing an experimental feature flag

This patch changes the `LateParsed` field of `Attr` in `Attr.td` to be
an instantiation of the new `LateAttrParseKind` class. The instation can be one 
of the following:

* LateAttrParsingNever - Corresponds with the false value of `LateParsed` prior 
to this patch (the default for an attribute).
* LateAttrParsingAlways - Corresponds with the true value of `LateParsed` prior 
to this patch.
* LateAttrParsingExperimentalOnly - A new mode described below.

`LateAttrParsingExperimentalOnly` means that the attribute will be late
parsed if the new the `ExperimentalLateParseAttributes` language option (also 
introduced in
this patch) is enabled and will **not** be late parsed if the language
option is disabled.

The new `ExperimentalLateParseAttributes` language option is controlled
by a new driver and frontend flag
(`-fexperimental-late-parse-attributes`). A driver test is included to
check that the driver passes the flag to CC1.

In this patch the `LateAttrParsingExperimentalOnly` is not adopted by
any attribute so `-fexperimental-late-pase-attributes` and the
corresponding language option currently have no effect on compilation.
This is why this patch does not include any test cases that test
`LateAttrParsingExperimentalOnly`'s behavior.

The motivation for this patch is to be able to late parse the new
`counted_by` attribute but only do so when a feature flag is passed.
This was discussed during the [bounds-safety 
RFC](https://discourse.llvm.org/t/rfc-enforcing-bounds-safety-in-c-fbounds-safety/70854/68).

Adoption of `LateAttrParsingExperimentalOnly` for the `counted_by`
attributed will be handled separately in another patch (likely
https://github.com/llvm/llvm-project/pull/87596).
---
 clang/include/clang/Basic/Attr.td |  46 +++---
 clang/include/clang/Basic/LangOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   7 +
 clang/include/clang/Parse/Parser.h|   4 +
 clang/lib/Driver/ToolChains/Clang.cpp |   3 +
 clang/lib/Parse/ParseDecl.cpp |  19 ++-
 .../experimental-late-parse-attributes.c  |  12 ++
 clang/utils/TableGen/ClangAttrEmitter.cpp | 137 --
 8 files changed, 192 insertions(+), 37 deletions(-)
 create mode 100644 clang/test/Driver/experimental-late-parse-attributes.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022dc..da76f807cd676c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -592,6 +592,16 @@ class AttrSubjectMatcherAggregateRule 
{
 
 def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule;
 
+// Late Attribute parsing mode enum
+class LateAttrParseKind  {
+  int Kind = val;
+}
+def LateAttrParsingNever : LateAttrParseKind<0>; // Never late 

[clang] Carving out -Wformat warning about scoped enums into a subwarning (PR #88595)

2024-04-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (ZijunZhaoCCK)


Changes

Make it part of -Wformat-pedantic.

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


3 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2-2) 
- (modified) clang/test/Sema/format-strings-scanf.c (+1-1) 
- (modified) clang/test/Sema/format-strings-signedness.c (+3-3) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 774d2b53a38252..4ba27d62208da4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9827,7 +9827,7 @@ def warn_scanf_nonzero_width : Warning<
 def warn_format_conversion_argument_type_mismatch : Warning<
   "format specifies type %0 but the argument has "
   "%select{type|underlying type}2 %1">,
-  InGroup;
+  InGroup;
 def warn_format_conversion_argument_type_mismatch_pedantic : Extension<
   warn_format_conversion_argument_type_mismatch.Summary>,
   InGroup;
@@ -9840,7 +9840,7 @@ def 
warn_format_conversion_argument_type_mismatch_confusion : Warning<
 def warn_format_argument_needs_cast : Warning<
   "%select{values of type|enum values with underlying type}2 '%0' should not "
   "be used as format arguments; add an explicit cast to %1 instead">,
-  InGroup;
+  InGroup;
 def warn_format_argument_needs_cast_pedantic : Warning<
   warn_format_argument_needs_cast.Summary>,
   InGroup, DefaultIgnore;
diff --git a/clang/test/Sema/format-strings-scanf.c 
b/clang/test/Sema/format-strings-scanf.c
index eb5b8ec36bf7a4..9bdc46bfeebc3b 100644
--- a/clang/test/Sema/format-strings-scanf.c
+++ b/clang/test/Sema/format-strings-scanf.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -std=c11 -fsyntax-only -verify -Wformat-nonliteral %s
 
 // Test that -Wformat=0 works:
-// RUN: %clang_cc1 -std=c11 -fsyntax-only -Werror -Wformat=0 %s
+// RUN: %clang_cc1 -std=c11 -fsyntax-only -Werror -Wformat=0 
-Wno-format-pedantic %s
 
 #include 
 typedef __SIZE_TYPE__ size_t;
diff --git a/clang/test/Sema/format-strings-signedness.c 
b/clang/test/Sema/format-strings-signedness.c
index d5a8140d9ef8a0..ccd4d72c2d2635 100644
--- a/clang/test/Sema/format-strings-signedness.c
+++ b/clang/test/Sema/format-strings-signedness.c
@@ -12,8 +12,8 @@
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -Wformat 
-verify=okay %s
 
 // Verify that -Wformat-signedness with -Wno-format are not reported (gcc 
compat).
-// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wformat-signedness -Wno-format -verify=okay %s
-// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wno-format -Wformat-signedness -verify=okay %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wformat-signedness -Wno-format -verify %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wno-format -Wformat-signedness -verify %s
 // okay-no-diagnostics
 
 int printf(const char *restrict format, ...);
@@ -218,5 +218,5 @@ void test_printf_unsigned_priX16(uint16_t x) {
 void test_suppress(int x)
 {
 #pragma GCC diagnostic ignored "-Wformat"
-printf("%u", x);
+printf("%u", x); // expected-warning{{format specifies type 'unsigned int' 
but the argument has type 'int'}}
 }

``




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


[clang] Carving out -Wformat warning about scoped enums into a subwarning (PR #88595)

2024-04-12 Thread via cfe-commits

https://github.com/ZijunZhaoCCK created 
https://github.com/llvm/llvm-project/pull/88595

Make it part of -Wformat-pedantic.

>From 29d2d19c9dea9e3f818a34c97f95bd7c93b9433b Mon Sep 17 00:00:00 2001
From: Zijun 
Date: Sat, 13 Apr 2024 00:53:38 +
Subject: [PATCH] Carving out -Wformat warning about scoped enums into a
 subwarning

Make it part of -Wformat-pedantic.
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 ++--
 clang/test/Sema/format-strings-scanf.c   | 2 +-
 clang/test/Sema/format-strings-signedness.c  | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 774d2b53a38252..4ba27d62208da4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9827,7 +9827,7 @@ def warn_scanf_nonzero_width : Warning<
 def warn_format_conversion_argument_type_mismatch : Warning<
   "format specifies type %0 but the argument has "
   "%select{type|underlying type}2 %1">,
-  InGroup;
+  InGroup;
 def warn_format_conversion_argument_type_mismatch_pedantic : Extension<
   warn_format_conversion_argument_type_mismatch.Summary>,
   InGroup;
@@ -9840,7 +9840,7 @@ def 
warn_format_conversion_argument_type_mismatch_confusion : Warning<
 def warn_format_argument_needs_cast : Warning<
   "%select{values of type|enum values with underlying type}2 '%0' should not "
   "be used as format arguments; add an explicit cast to %1 instead">,
-  InGroup;
+  InGroup;
 def warn_format_argument_needs_cast_pedantic : Warning<
   warn_format_argument_needs_cast.Summary>,
   InGroup, DefaultIgnore;
diff --git a/clang/test/Sema/format-strings-scanf.c 
b/clang/test/Sema/format-strings-scanf.c
index eb5b8ec36bf7a4..9bdc46bfeebc3b 100644
--- a/clang/test/Sema/format-strings-scanf.c
+++ b/clang/test/Sema/format-strings-scanf.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -std=c11 -fsyntax-only -verify -Wformat-nonliteral %s
 
 // Test that -Wformat=0 works:
-// RUN: %clang_cc1 -std=c11 -fsyntax-only -Werror -Wformat=0 %s
+// RUN: %clang_cc1 -std=c11 -fsyntax-only -Werror -Wformat=0 
-Wno-format-pedantic %s
 
 #include 
 typedef __SIZE_TYPE__ size_t;
diff --git a/clang/test/Sema/format-strings-signedness.c 
b/clang/test/Sema/format-strings-signedness.c
index d5a8140d9ef8a0..ccd4d72c2d2635 100644
--- a/clang/test/Sema/format-strings-signedness.c
+++ b/clang/test/Sema/format-strings-signedness.c
@@ -12,8 +12,8 @@
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only -Wformat 
-verify=okay %s
 
 // Verify that -Wformat-signedness with -Wno-format are not reported (gcc 
compat).
-// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wformat-signedness -Wno-format -verify=okay %s
-// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wno-format -Wformat-signedness -verify=okay %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wformat-signedness -Wno-format -verify %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -std=c11 -fsyntax-only 
-Wno-format -Wformat-signedness -verify %s
 // okay-no-diagnostics
 
 int printf(const char *restrict format, ...);
@@ -218,5 +218,5 @@ void test_printf_unsigned_priX16(uint16_t x) {
 void test_suppress(int x)
 {
 #pragma GCC diagnostic ignored "-Wformat"
-printf("%u", x);
+printf("%u", x); // expected-warning{{format specifies type 'unsigned int' 
but the argument has type 'int'}}
 }

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

2024-04-12 Thread via cfe-commits


@@ -3734,7 +3734,10 @@ void FunctionProtoType::Profile(llvm::FoldingSetNodeID 
, QualType Result,
   // spec because of the leading 'bool' which unambiguously indicates
   // whether the following bool is the EH spec or part of the arguments.
 
+  // TODO: The effect set is variable-length, though prefaced with a size.
+  // Does this create potential ambiguity?

Sirraide wrote:

Just happened to take a look at this commit so I’ll comment on it: You should 
be fine so long as you *always* unconditionally include the size; we also do 
this in other places: if there is no effect set, the size will always be `0`, 
so any ID that has no effect set has `0` in that position; if the size is 
non-zero, then we know that the next size*`n` (where `n` is however many bytes 
it takes to profile an effect, assuming that that’s constant) bytes will be the 
effects. Basically, so long as they never ‘overlap’ w/ anything / so long as 
you can think of a way to ‘reverse’ the profiling (not that we ever do that), 
then it should be fine.

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

2024-04-12 Thread via cfe-commits


@@ -5153,6 +5156,7 @@ bool FunctionEffect::shouldDiagnoseFunctionCall(
 // =
 
 void FunctionEffectSet::Profile(llvm::FoldingSetNodeID ) const {
+  ID.AddInteger(size());
   if (PImpl)
 for (const auto  : *PImpl)
   ID.AddInteger(llvm::to_underlying(Effect.kind()));

Sirraide wrote:

Yeah, so long as this loop always adds exactly `size()` many effects, it should 
be fine.

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

2024-04-12 Thread via cfe-commits


@@ -4429,6 +4433,210 @@ class FunctionNoProtoType : public FunctionType, public 
llvm::FoldingSetNode {
   }
 };
 
+// 
--
+
+class Decl;
+class CXXMethodDecl;
+class FunctionEffectSet;
+
+/// Represents an abstract function effect, using just an enumeration 
describing
+/// its type. Encapsulates its semantic behaviors.
+class FunctionEffect {
+public:
+  /// Identifies the particular effect.
+  enum class Kind : uint8_t {
+None,
+NonBlocking,
+NonAllocating,
+  };
+
+  /// Flags describing some behaviors of the effect.
+  using Flags = unsigned;
+  enum FlagBit : Flags {
+// Can verification inspect callees' implementations? (e.g. nonblocking:
+// yes, tcb+types: no)
+FE_InferrableOnCallees = 0x1,
+
+// Language constructs which effects can diagnose as disallowed.
+FE_ExcludeThrow = 0x2,
+FE_ExcludeCatch = 0x4,
+FE_ExcludeObjCMessageSend = 0x8,
+FE_ExcludeStaticLocalVars = 0x10,
+FE_ExcludeThreadLocalVars = 0x20
+  };
+
+  /// Describes the result of effects differing between a base class's virtual
+  /// method and an overriding method in a subclass.
+  enum class OverrideResult {
+Ignore,
+Warn,
+Merge // Base method's effects are merged with those of the override.
+  };
+
+private:
+  Kind FKind;
+
+  // Expansion: for hypothetical TCB+types, there could be one Kind for TCB,
+  // then ~16(?) bits "SubKind" to map to a specific named TCB. SubKind would
+  // be considered for uniqueness.
+
+public:
+  FunctionEffect() : FKind(Kind::None) {}
+
+  explicit FunctionEffect(Kind T) : FKind(T) {}
+
+  /// The kind of the effect.
+  Kind kind() const { return FKind; }
+
+  /// Return an opaque integer, as a serializable representation.
+  uint32_t getAsOpaqueValue() const { return llvm::to_underlying(FKind); }
+
+  /// Construct from a serialized representation.
+  static FunctionEffect getFromOpaqueValue(uint32_t V) {
+return FunctionEffect(static_cast(V));
+  }
+
+  /// Flags describing some behaviors of the effect.
+  Flags flags() const {
+switch (FKind) {
+case Kind::NonBlocking:
+  return FE_InferrableOnCallees | FE_ExcludeThrow | FE_ExcludeCatch |
+ FE_ExcludeObjCMessageSend | FE_ExcludeStaticLocalVars |
+ FE_ExcludeThreadLocalVars;
+case Kind::NonAllocating:
+  // Same as NonBlocking, except without FE_ExcludeStaticLocalVars
+  return FE_InferrableOnCallees | FE_ExcludeThrow | FE_ExcludeCatch |
+ FE_ExcludeObjCMessageSend | FE_ExcludeThreadLocalVars;
+case Kind::None:
+  break;
+}
+llvm_unreachable("unknown effect kind");
+  }
+
+  /// The description printed in diagnostics, e.g. 'nonblocking'.
+  StringRef name() const;
+
+  /// Return true if adding or removing the effect as part of a type conversion
+  /// should generate a diagnostic.
+  bool shouldDiagnoseConversion(bool Adding, QualType OldType,
+const FunctionEffectSet ,
+QualType NewType,
+const FunctionEffectSet ) const;
+
+  /// Return true if adding or removing the effect in a redeclaration should
+  /// generate a diagnostic.
+  bool shouldDiagnoseRedeclaration(bool Adding, const FunctionDecl 
,
+   const FunctionEffectSet ,
+   const FunctionDecl ,
+   const FunctionEffectSet ) const;
+
+  /// Return true if adding or removing the effect in a C++ virtual method
+  /// override should generate a diagnostic.
+  OverrideResult
+  shouldDiagnoseMethodOverride(bool Adding, const CXXMethodDecl ,
+   const FunctionEffectSet ,
+   const CXXMethodDecl ,
+   const FunctionEffectSet ) const;
+
+  /// Return true if the effect is allowed to be inferred on the callee,
+  /// which is either a FunctionDecl or BlockDecl.
+  /// This is only used if the effect has FE_InferrableOnCallees flag set.
+  /// Example: This allows nonblocking(false) to prevent inference for the
+  /// function.
+  bool canInferOnFunction(const Decl ) const;
+
+  // Return false for success. When true is returned for a direct call, then 
the
+  // FE_InferrableOnCallees flag may trigger inference rather than an immediate
+  // diagnostic. Caller should be assumed to have the effect (it may not have 
it
+  // explicitly when inferring).
+  bool shouldDiagnoseFunctionCall(bool Direct,
+  const FunctionEffectSet ) const;
+
+  friend bool operator==(const FunctionEffect , const FunctionEffect ) 
{
+return LHS.FKind == RHS.FKind;
+  }
+  friend bool operator!=(const FunctionEffect , const FunctionEffect ) 
{
+return LHS.FKind != RHS.FKind;
+  }
+  friend bool operator<(const FunctionEffect , const FunctionEffect ) {
+return LHS.FKind < 

[clang] [codegen] Emit missing cleanups for stmt-expr and coro suspensions [take-2] (PR #85398)

2024-04-12 Thread Alexander Yermolovich via cfe-commits

ayermolo wrote:

I think this commit is causing build failure when building clangd in debug mode 
with clang built in release mode.

```
Instruction does not dominate all uses!
  %K1104 = getelementptr inbounds %"struct.llvm::json::Object::KV", ptr 
%arrayinit.begin1100, i32 0, i32 0, !dbg !93928
  call void @_ZN4llvm4json9ObjectKeyD2Ev(ptr noundef nonnull align 8 
dereferenceable(24) %K1104) #21, !dbg !93937
fatal error: error in backend: Broken module found, compilation aborted!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: 
/home/ayermolo/local/llvm-build-upstream-release/bin/clang++ -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/tools/extra/clangd 
-I/home/ayermolo/local/upstream-llvm/llvm-project/clang-tools-extra/clangd 
-I/home/ayermolo/local/upstream-llvm/llvm-project/clang-tools-extra/clangd/../include-cleaner/include
 -Itools/clang/tools/extra/clangd/../clang-tidy 
-I/home/ayermolo/local/upstream-llvm/llvm-project/clang/include 
-Itools/clang/include -Iinclude 
-I/home/ayermolo/local/upstream-llvm/llvm-project/llvm/include 
-I/home/ayermolo/local/upstream-llvm/llvm-project/clang-tools-extra/pseudo/lib/../include
 
-isystem/home/ayermolo/local/llvm-build-upstream-llvm/build/lib/clang/19/include
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-fno-common -Woverloaded-virtual -Wno-nested-anon-types -g -std=c++17 -MD -MT 
/home/ayermolo/local/llvm-build-upstream-debug/tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o
 -MF 
/home/ayermolo/local/llvm-build-upstream-debug/tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o.d
 -o 
/home/ayermolo/local/llvm-build-upstream-debug/tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o
 -c 
/home/ayermolo/local/upstream-llvm/llvm-project/clang-tools-extra/clangd/ClangdLSPServer.cpp
```

Dropping this commit and running above clang build command makes it pass.
build command for easier reading:
```
COMP=/home/ayermolo/local/llvm-build-upstream-release/bin
$COMP/clang++ -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS \
  -Itools/clang/tools/extra/clangd \
  -I/home/ayermolo/local/upstream-llvm/llvm-project/clang-tools-extra/clangd \
  
-I/home/ayermolo/local/upstream-llvm/llvm-project/clang-tools-extra/clangd/../include-cleaner/include
 \
  -Itools/clang/tools/extra/clangd/../clang-tidy \
  -I/home/ayermolo/local/upstream-llvm/llvm-project/clang/include \
  -Itools/clang/include \
  -Iinclude \
  -I/home/ayermolo/local/upstream-llvm/llvm-project/llvm/include \
  
-I/home/ayermolo/local/upstream-llvm/llvm-project/clang-tools-extra/pseudo/lib/../include
 \
  
-isystem/home/ayermolo/local/llvm-build-upstream-llvm/build/lib/clang/19/include
 \
  -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra \
  -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
-Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi 
\
  -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type 
-Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override \
  -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported 
-fdiagnostics-color -fno-common -Woverloaded-virtual \
  -Wno-nested-anon-types -g -std=c++17 -MD \
  -MT 
/home/ayermolo/local/llvm-build-upstream-debug/tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o
 \
  -MF 
/home/ayermolo/local/llvm-build-upstream-debug/tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o.d
 \
  -o  
/home/ayermolo/local/llvm-build-upstream-debug/tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o
 \
  -c  
/home/ayermolo/local/upstream-llvm/llvm-project/clang-tools-extra/clangd/ClangdLSPServer.cpp
```

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


[clang] [clang][modules] Headers meant to be included multiple times can be completely invisible in clang module builds (PR #83660)

2024-04-12 Thread James Y Knight via cfe-commits

jyknight wrote:

>> The end result should be that #imported and #pragma once-guarded files are 
>> treated the same way as #ifndef-guarded files.

> While I don't necessarily disagree with that goal in principle, it wasn't 
> true before this change either.

Well, yes, I know it isn't true yet -- that's exactly what I've been trying to 
say, and demonstrated with the test -- it's not true _and_ that's a bug.

> Modular headers including non-modular headers is a special problem. If we let 
> every module enter the non-modular header (which Jan's patch does), its 
> declarations will build into multiple modules/pcm files

I'm not really sure what you're getting at in this paragraph. Is there a _new_ 
special problem introduced here?

Yes, a textual header can be built into multiple modules/pcm files -- that's 
the nature of it being textual, right? Certainly it's always be a better to 
modularize headers from the bottom-up, and avoid textually including a header 
into multiple modules. And, yes, the performance cost of duplicating the decls 
into multiple modules' pcm files can be quite significant, depending on the 
size of the header. Yet, sometimes it happens. And, when it does, the 
declaration-merging takes care of it -- for C/C++ clients. This all works (and 
is used) today, with ifndef-guarded header inclusion.

But a textually-included header shouldn't be re-entered if it's been _visibly_ 
included already in the current compilation -- including if that was exported 
from an imported module. It should only be re-entered if the previous include 
is _not_ visible in the current context. Maybe you're saying Jan's patch 
doesn't do that properly yet. (I could see that being the case, since the 
behavior mostly just falls out automatically for the ifndef-guard case, based 
on whether the guard-macro was made visible or not!)

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


[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

2024-04-12 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/87130

>From 23422a0b3af3e070fed5ae86ed0f67acec066c0a Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Fri, 29 Mar 2024 17:48:14 -0700
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/lib/Sema/CMakeLists.txt |  1 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 31 +--
 clang/test/AST/ast-dump-attr-json.cpp |  1 +
 clang/test/Sema/alias-unused.c| 30 +-
 4 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index e8bff07ced0cfa..7657536fabd1eb 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -1,5 +1,6 @@
 set(LLVM_LINK_COMPONENTS
   Core
+  Demangle
   FrontendHLSL
   FrontendOpenMP
   MC
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index f25f3afd0f4af2..8ed5242f325e5e 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -42,6 +42,7 @@
 #include "clang/Sema/SemaInternal.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Demangle/Demangle.h"
 #include "llvm/IR/Assumptions.h"
 #include "llvm/MC/MCSectionMachO.h"
 #include "llvm/Support/Error.h"
@@ -1980,6 +1981,23 @@ static void handleWeakRefAttr(Sema , Decl *D, const 
ParsedAttr ) {
   D->addAttr(::new (S.Context) WeakRefAttr(S.Context, AL));
 }
 
+// Mark alias/ifunc target as used. For C++, we look up the demangled name
+// ignoring parameters. This should handle the majority of use cases while
+// leaveing false positives for namespace scope names and false negatives in
+// the presence of overloads.
+static void markUsedForAliasOrIfunc(Sema , Decl *D, const ParsedAttr ,
+StringRef Str) {
+  char *Demangled = llvm::itaniumDemangle(Str, /*ParseParams=*/false);
+  if (Demangled)
+Str = Demangled;
+  const DeclarationNameInfo target((Str), AL.getLoc());
+  LookupResult LR(S, target, Sema::LookupOrdinaryName);
+  if (S.LookupQualifiedName(LR, S.getCurLexicalContext()))
+for (NamedDecl *ND : LR)
+  ND->markUsed(S.Context);
+  free(Demangled);
+}
+
 static void handleIFuncAttr(Sema , Decl *D, const ParsedAttr ) {
   StringRef Str;
   if (!S.checkStringLiteralArgumentAttr(AL, 0, Str))
@@ -1992,6 +2010,7 @@ static void handleIFuncAttr(Sema , Decl *D, const 
ParsedAttr ) {
 return;
   }
 
+  markUsedForAliasOrIfunc(S, D, AL, Str);
   D->addAttr(::new (S.Context) IFuncAttr(S.Context, AL, Str));
 }
 
@@ -2026,17 +2045,7 @@ static void handleAliasAttr(Sema , Decl *D, const 
ParsedAttr ) {
 }
   }
 
-  // Mark target used to prevent unneeded-internal-declaration warnings.
-  if (!S.LangOpts.CPlusPlus) {
-// FIXME: demangle Str for C++, as the attribute refers to the mangled
-// linkage name, not the pre-mangled identifier.
-const DeclarationNameInfo target((Str), AL.getLoc());
-LookupResult LR(S, target, Sema::LookupOrdinaryName);
-if (S.LookupQualifiedName(LR, S.getCurLexicalContext()))
-  for (NamedDecl *ND : LR)
-ND->markUsed(S.Context);
-  }
-
+  markUsedForAliasOrIfunc(S, D, AL, Str);
   D->addAttr(::new (S.Context) AliasAttr(S.Context, AL, Str));
 }
 
diff --git a/clang/test/AST/ast-dump-attr-json.cpp 
b/clang/test/AST/ast-dump-attr-json.cpp
index 051c2956abfdf7..883e584bfedf07 100644
--- a/clang/test/AST/ast-dump-attr-json.cpp
+++ b/clang/test/AST/ast-dump-attr-json.cpp
@@ -46,6 +46,7 @@ __thread __attribute__ ((tls_model ("local-exec"))) int 
tls_model_var;
 // CHECK-NEXT:"tokLen": 11
 // CHECK-NEXT:   }
 // CHECK-NEXT:  },
+// CHECK-NEXT:  "isUsed": true,
 // CHECK-NEXT:  "name": "global_decl",
 // CHECK-NEXT:  "mangledName": "global_decl",
 // CHECK-NEXT:  "type": {
diff --git a/clang/test/Sema/alias-unused.c b/clang/test/Sema/alias-unused.c
index de9fc8cc737662..030b5737a93a21 100644
--- a/clang/test/Sema/alias-unused.c
+++ b/clang/test/Sema/alias-unused.c
@@ -1,7 +1,35 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wunneeded-internal-declaration -x 
c -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wunused -x c -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wunused -x c++ -verify %s
+
+#ifdef __cplusplus
+extern "C" {
+#else
 // expected-no-diagnostics
+#endif
 static int f(void) { return 42; }
 int g(void) __attribute__((alias("f")));
 
 static int foo [] = { 42, 0xDEAD };
 extern typeof(foo) bar __attribute__((unused, alias("foo")));
+
+static int (*resolver(void))(void) { return f; }
+int ifunc(void) __attribute__((ifunc("resolver")));
+
+#ifdef __cplusplus
+}
+
+/// We demangle alias/ifunc target and mark all found functions as used.
+static int f1(int) { return 42; }
+static int f1(void) { return 42; }
+int 

[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

2024-04-12 Thread Fangrui Song via cfe-commits

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


[clang] b9bed1f - [test] Improve tests for alias/ifunc attributes

2024-04-12 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-04-12T16:44:46-07:00
New Revision: b9bed1f1106e3116e8bea38806c511b57b956929

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

LOG: [test] Improve tests for alias/ifunc attributes

Added: 
clang/test/Sema/alias-unused-win.cpp
clang/test/Sema/alias-unused.cpp

Modified: 


Removed: 
clang/test/Sema/alias-unused.c



diff  --git a/clang/test/Sema/alias-unused-win.cpp 
b/clang/test/Sema/alias-unused-win.cpp
new file mode 100644
index 00..47c96d41175179
--- /dev/null
+++ b/clang/test/Sema/alias-unused-win.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -triple %ms_abi_triple -Wunused -x c -verify %s
+// RUN: %clang_cc1 -triple %ms_abi_triple -Wunused -verify=expected,cxx %s
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+static int f(void) { return 42; } // cxx-warning{{unused function 'f'}}
+int g(void) __attribute__((alias("f")));
+
+static int foo [] = { 42, 0xDEAD }; // cxx-warning{{variable 'foo' is not 
needed and will not be emitted}}
+extern typeof(foo) bar __attribute__((unused, alias("foo")));
+
+static int __attribute__((overloadable)) f0(int x) { return x; } // 
expected-warning{{unused function 'f0'}}
+static float __attribute__((overloadable)) f0(float x) { return x; } // 
expected-warning{{unused function 'f0'}}
+int g0(void) __attribute__((alias("?f0@@YAHH@Z")));
+
+#ifdef __cplusplus
+/// https://github.com/llvm/llvm-project/issues/88593
+/// We report a warning in C++ mode because the internal linkage `resolver` 
gets
+/// mangled as it does not have a language linkage. GCC does not mangle
+/// `resolver` or report a warning.
+static int f1() { return 42; } // cxx-warning{{unused function 'f1'}}
+int g1(void) __attribute__((alias("?f1@@YAHXZ")));
+}
+
+namespace ns {
+static int f3(int) { return 42; } // cxx-warning{{unused function 'f3'}}
+static int f3() { return 42; } // cxx-warning{{unused function 'f3'}}
+int g3() __attribute__((alias("?f3@ns@@YAHXZ")));
+}
+#endif

diff  --git a/clang/test/Sema/alias-unused.c b/clang/test/Sema/alias-unused.c
deleted file mode 100644
index de9fc8cc737662..00
--- a/clang/test/Sema/alias-unused.c
+++ /dev/null
@@ -1,7 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wunneeded-internal-declaration -x 
c -verify %s
-// expected-no-diagnostics
-static int f(void) { return 42; }
-int g(void) __attribute__((alias("f")));
-
-static int foo [] = { 42, 0xDEAD };
-extern typeof(foo) bar __attribute__((unused, alias("foo")));

diff  --git a/clang/test/Sema/alias-unused.cpp 
b/clang/test/Sema/alias-unused.cpp
new file mode 100644
index 00..509d3e26225d74
--- /dev/null
+++ b/clang/test/Sema/alias-unused.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -x c -verify %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -verify=expected,cxx %s
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+static int f(void) { return 42; }
+int g(void) __attribute__((alias("f")));
+
+static int foo [] = { 42, 0xDEAD }; // cxx-warning{{variable 'foo' is not 
needed and will not be emitted}}
+extern typeof(foo) bar __attribute__((unused, alias("foo")));
+
+/// https://github.com/llvm/llvm-project/issues/88593
+/// We report a warning in C++ mode because the internal linkage `resolver` 
gets
+/// mangled as it does not have a language linkage. GCC does not mangle
+/// `resolver` or report a warning.
+static int (*resolver(void))(void) { return f; } // expected-warning{{unused 
function 'resolver'}}
+int ifunc(void) __attribute__((ifunc("resolver")));
+
+static int __attribute__((overloadable)) f0(int x) { return x; } // 
expected-warning{{unused function 'f0'}}
+static float __attribute__((overloadable)) f0(float x) { return x; } // 
expected-warning{{unused function 'f0'}}
+int g0(void) __attribute__((alias("_ZL2f0i")));
+
+#ifdef __cplusplus
+static int f1() { return 42; } // expected-warning{{unused function 'f1'}}
+int g1(void) __attribute__((alias("_ZL2f1v")));
+}
+
+static int f2(int) { return 42; } // expected-warning{{unused function 'f2'}}
+static int f2() { return 42; } // expected-warning{{unused function 'f2'}}
+int g2() __attribute__((alias("_ZL2f2v")));
+
+static int (*resolver1())() { return f; } // expected-warning{{unused function 
'resolver1'}}
+static int (*resolver1(int))() { return f; } // expected-warning{{unused 
function 'resolver1'}}
+int ifunc1() __attribute__((ifunc("_ZL9resolver1i")));
+
+/// TODO: We should report "unused function" for f3(int).
+namespace ns {
+static int f3(int) { return 42; } // cxx-warning{{unused function 'f3'}}
+static int f3() { return 42; } // cxx-warning{{unused function 'f3'}}
+int g3() __attribute__((alias("_ZN2nsL2f3Ev")));
+}
+
+template 
+static void *f4(T) { return nullptr; }
+static void *f4() { return 

[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

2024-04-12 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -x c -verify %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -x c++ 
-verify=expected,cxx %s
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+static int f(void) { return 42; }
+int g(void) __attribute__((alias("f")));

MaskRay wrote:

Created #88593   

But I don't think a TODO applies. Clang's behavior is probably desired. So this 
just records a difference.

This difference probably doesn't make a difference because people rarely use 
`alias` for C++ code.

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


[clang] [ARM64EC] Fix arm_neon.h on ARM64EC. (PR #88572)

2024-04-12 Thread Daniel Paoliello via cfe-commits

https://github.com/dpaoliello approved this pull request.


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


[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-04-12 Thread Dan Liew via cfe-commits

https://github.com/delcypher updated 
https://github.com/llvm/llvm-project/pull/87596

>From af735f3216dd5db9dcaf164892f3f573731701ec Mon Sep 17 00:00:00 2001
From: Yeoul Na 
Date: Wed, 3 Apr 2024 20:58:46 -0700
Subject: [PATCH 1/3] [BoundsSafety] WIP: Make 'counted_by' work for pointer
 fields; late parsing for 'counted_by' on decl attr position

---
 clang/include/clang/Basic/Attr.td |   3 +-
 clang/include/clang/Parse/Parser.h|  11 +-
 clang/include/clang/Sema/Sema.h   |   2 +-
 clang/lib/Parse/ParseDecl.cpp | 108 --
 clang/lib/Parse/ParseObjc.cpp |   6 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  11 +-
 clang/lib/Sema/SemaType.cpp   |   6 +-
 clang/lib/Sema/TreeTransform.h|   2 +-
 clang/test/AST/attr-counted-by-late-parsed.c  |  29 +
 clang/test/Sema/attr-counted-by-late-parsed.c |  54 +
 clang/test/Sema/attr-counted-by.c |   2 +-
 11 files changed, 212 insertions(+), 22 deletions(-)
 create mode 100644 clang/test/AST/attr-counted-by-late-parsed.c
 create mode 100644 clang/test/Sema/attr-counted-by-late-parsed.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 6584460cf5685e..d6caa28938edef 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2197,7 +2197,8 @@ def TypeNullUnspecified : TypeAttr {
 def CountedBy : DeclOrTypeAttr {
   let Spellings = [Clang<"counted_by">];
   let Subjects = SubjectList<[Field], ErrorDiag>;
-  let Args = [ExprArgument<"Count">, IntArgument<"NestedLevel">];
+  let Args = [ExprArgument<"Count">, IntArgument<"NestedLevel", 1>];
+  let LateParsed = 1;
   let ParseArgumentsAsUnevaluated = 1;
   let Documentation = [CountedByDocs];
   let LangOpts = [COnly];
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 580bf2a5d79df5..41fc5d5dc98a6b 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1606,6 +1606,10 @@ class Parser : public CodeCompletionHandler {
bool EnterScope, bool OnDefinition);
   void ParseLexedAttribute(LateParsedAttribute ,
bool EnterScope, bool OnDefinition);
+  void ParseLexedCAttributeList(LateParsedAttrList , bool EnterScope,
+ParsedAttributes *OutAttrs = nullptr);
+  void ParseLexedCAttribute(LateParsedAttribute , bool EnterScope,
+ParsedAttributes *OutAttrs = nullptr);
   void ParseLexedMethodDeclarations(ParsingClass );
   void ParseLexedMethodDeclaration(LateParsedMethodDeclaration );
   void ParseLexedMethodDefs(ParsingClass );
@@ -2497,7 +2501,9 @@ class Parser : public CodeCompletionHandler {
 
   void ParseStructDeclaration(
   ParsingDeclSpec ,
-  llvm::function_ref FieldsCallback);
+  llvm::function_ref
+  FieldsCallback,
+  LateParsedAttrList *LateFieldAttrs = nullptr);
 
   DeclGroupPtrTy ParseTopLevelStmtDecl();
 
@@ -3074,6 +3080,9 @@ class Parser : public CodeCompletionHandler {
  SourceLocation ScopeLoc,
  ParsedAttr::Form Form);
 
+  void DistributeCLateParsedAttrs(Declarator , Decl *Dcl,
+  LateParsedAttrList *LateAttrs);
+
   void ParseBoundsAttribute(IdentifierInfo ,
 SourceLocation AttrNameLoc, ParsedAttributes 
,
 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 8c98d8c7fef7a7..de49f2344f017f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11761,7 +11761,7 @@ class Sema final {
   QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns,
SourceLocation AttrLoc);
 
-  QualType BuildCountAttributedArrayType(QualType WrappedTy, Expr *CountExpr);
+  QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy, Expr 
*CountExpr);
 
   QualType BuildAddressSpaceAttr(QualType , LangAS ASIdx, Expr *AddrSpace,
  SourceLocation AttrLoc);
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 0aa14b0510746b..1c2e6d447cf5d5 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3254,6 +3254,17 @@ void Parser::ParseAlignmentSpecifier(ParsedAttributes 
,
   }
 }
 
+void Parser::DistributeCLateParsedAttrs(Declarator , Decl *Dcl,
+LateParsedAttrList *LateAttrs) {
+  if (!LateAttrs)
+return;
+
+  for (auto *LateAttr : *LateAttrs) {
+if (LateAttr->Decls.empty())
+  LateAttr->addDecl(Dcl);
+  }
+}
+
 /// Bounds attributes (e.g., counted_by):
 ///   AttrName '(' expression ')'
 void Parser::ParseBoundsAttribute(IdentifierInfo ,
@@ -4787,13 +4798,14 @@ 

[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

2024-04-12 Thread Fangrui Song via cfe-commits

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


[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

2024-04-12 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -x c -verify %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -x c++ 
-verify=expected,cxx %s
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+static int f(void) { return 42; }
+int g(void) __attribute__((alias("f")));
+
+static int foo [] = { 42, 0xDEAD }; // cxx-warning{{variable 'foo' is not 
needed and will not be emitted}}
+extern typeof(foo) bar __attribute__((unused, alias("foo")));
+
+static int (*resolver(void))(void) { return f; } // cxx-warning{{unused 
function 'resolver'}}
+int ifunc(void) __attribute__((ifunc("resolver")));
+
+static int __attribute__((overloadable)) f0(int x) { return x; }
+static float __attribute__((overloadable)) f0(float x) { return x; } // 
expected-warning{{unused function 'f0'}}
+int g0(void) __attribute__((alias("_ZL2f0i")));
+
+#ifdef __cplusplus
+static int f1() { return 42; }
+int g1(void) __attribute__((alias("_ZL2f1v")));
+}
+
+/// We demangle alias/ifunc target and mark all found functions as used.
+
+static int f2(int) { return 42; } // cxx-warning{{unused function 'f2'}}
+static int f2() { return 42; }
+int g2() __attribute__((alias("_ZL2f2v")));
+
+static int (*resolver1())() { return f; } // cxx-warning{{unused function 
'resolver1'}}
+static int (*resolver1(int))() { return f; }
+int ifunc1() __attribute__((ifunc("_ZL9resolver1i")));
+
+/// We should report "unused function" for f3(int).
+namespace ns {
+static int f3(int) { return 42; } // cxx-warning{{unused function 'f3'}}
+static int f3() { return 42; } // cxx-warning{{unused function 'f3'}}

MaskRay wrote:

To fully support qualified names in alias/ifunc attributes for the 
`-Wunused-function` diagnostic, it would take a lot of code due to complexity 
of C++ name lookup when namespaces are involved.

This PR intends to address the `ifunc` `-Wunused-function` issue. The C++ 
support is a side product. And it would seem odd to add lots of code to fix a 
`-Wunused-function` false positive related to qualified names (which people 
likely don't use).



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


[clang] [llvm] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-12 Thread Vitaly Buka via cfe-commits


@@ -3233,6 +3233,17 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 if (BuiltinCountZeroBitsGeneric(*this, TheCall))
   return ExprError();
 break;
+
+  case Builtin::BI__builtin_allow_runtime_check: {
+Expr *Arg = TheCall->getArg(0);
+// Check if the argument is a string literal.
+if (!isa(Arg->IgnoreParenImpCasts())) {

vitalybuka wrote:

Resolving in favor of the longer thread above.

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


[clang] [llvm] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-12 Thread Vitaly Buka via cfe-commits

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


[clang] [llvm] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-12 Thread Vitaly Buka via cfe-commits

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


[clang] [llvm] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-12 Thread Vitaly Buka via cfe-commits


@@ -3464,6 +3464,34 @@ Query for this feature with 
``__has_builtin(__builtin_trap)``.
 
 ``__builtin_arm_trap`` is lowered to the ``llvm.aarch64.break`` builtin, and 
then to ``brk #payload``.
 
+``__builtin_allow_runtime_check``

vitalybuka wrote:

Similar __builtin_cpu_is, also works only with literals.

The closest thing I see is c++26 `static_assert` 
https://en.cppreference.com/w/cpp/language/static_assert
And it's parsed in a weird way `EvaluateStaticAssertMessageAsString`
https://godbolt.org/z/Gcf74Ysjs

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


[clang] [llvm] [Clang] Emit DW_TAG_template_alias for template aliases (PR #87623)

2024-04-12 Thread David Blaikie via cfe-commits

dwblaikie wrote:

Re: code: Looks about right.

Bit unfortunate to store template parameters in different ways (in the 
`extraData` for the alias template, but in the `templateParams` for the 
composite types) - but I guess it'd be more invasive to try to represent alias 
templates as composite types?

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


[clang] [llvm] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-12 Thread Vitaly Buka via cfe-commits


@@ -3464,6 +3464,34 @@ Query for this feature with 
``__has_builtin(__builtin_trap)``.
 
 ``__builtin_arm_trap`` is lowered to the ``llvm.aarch64.break`` builtin, and 
then to ``brk #payload``.
 
+``__builtin_allow_runtime_check``

vitalybuka wrote:

Not sure how to do that. I would expected that from `__builtin_nan`, but it 
can't do that:
https://godbolt.org/z/hWx47Gqvn

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


[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

2024-04-12 Thread Nick Desaulniers via cfe-commits


@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple %ms_abi_triple -Wunused -x c -verify %s
+// RUN: %clang_cc1 -triple %ms_abi_triple -Wunused -verify=expected,cxx %s
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+static int f(void) { return 42; } // cxx-warning{{unused function 'f'}}
+int g(void) __attribute__((alias("f")));
+
+static int foo [] = { 42, 0xDEAD };
+extern typeof(foo) bar __attribute__((unused, alias("foo")));
+
+static int __attribute__((overloadable)) f0(int x) { return x; } // 
expected-warning{{unused function 'f0'}}
+static float __attribute__((overloadable)) f0(float x) { return x; } // 
expected-warning{{unused function 'f0'}}
+int g0(void) __attribute__((alias("?f0@@YAHH@Z")));

nickdesaulniers wrote:

got it; please add a TODO that the overload of `f0` that accepts an `int` 
should not warn (similar to the TODO you added in 
clang/test/Sema/alias-unused.cpp for the namespace part.  Same for `g1` and the 
overload of `f3` that accepts no parameters.

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


[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

2024-04-12 Thread Nick Desaulniers via cfe-commits


@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -x c -verify %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -x c++ 
-verify=expected,cxx %s
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+static int f(void) { return 42; }
+int g(void) __attribute__((alias("f")));

nickdesaulniers wrote:

Please file a bug and link to it from a TODO comment in the tests and/or 
sources.

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


[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

2024-04-12 Thread Nick Desaulniers via cfe-commits

https://github.com/nickdesaulniers approved this pull request.

LGTM; though I have a strong preference to get bugs on file and linked to 
regarding:
- issues with non-itanium mangling
- issues with namespaced identifiers.

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


[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

2024-04-12 Thread Nick Desaulniers via cfe-commits


@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -x c -verify %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -x c++ 
-verify=expected,cxx %s
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+static int f(void) { return 42; }
+int g(void) __attribute__((alias("f")));
+
+static int foo [] = { 42, 0xDEAD }; // cxx-warning{{variable 'foo' is not 
needed and will not be emitted}}
+extern typeof(foo) bar __attribute__((unused, alias("foo")));
+
+static int (*resolver(void))(void) { return f; } // cxx-warning{{unused 
function 'resolver'}}
+int ifunc(void) __attribute__((ifunc("resolver")));
+
+static int __attribute__((overloadable)) f0(int x) { return x; }
+static float __attribute__((overloadable)) f0(float x) { return x; } // 
expected-warning{{unused function 'f0'}}
+int g0(void) __attribute__((alias("_ZL2f0i")));
+
+#ifdef __cplusplus
+static int f1() { return 42; }
+int g1(void) __attribute__((alias("_ZL2f1v")));
+}
+
+/// We demangle alias/ifunc target and mark all found functions as used.
+
+static int f2(int) { return 42; } // cxx-warning{{unused function 'f2'}}
+static int f2() { return 42; }
+int g2() __attribute__((alias("_ZL2f2v")));
+
+static int (*resolver1())() { return f; } // cxx-warning{{unused function 
'resolver1'}}
+static int (*resolver1(int))() { return f; }
+int ifunc1() __attribute__((ifunc("_ZL9resolver1i")));
+
+/// We should report "unused function" for f3(int).
+namespace ns {
+static int f3(int) { return 42; } // cxx-warning{{unused function 'f3'}}
+static int f3() { return 42; } // cxx-warning{{unused function 'f3'}}

nickdesaulniers wrote:

> may not fit

?

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


[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

2024-04-12 Thread Nick Desaulniers via cfe-commits

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


[clang] [Clang][Sema] Fix issue on requires expression with templated base class member function (PR #85198)

2024-04-12 Thread Erich Keane via cfe-commits


@@ -7735,7 +7735,8 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, 
NamedDecl *NDecl,
   }
 
   if (CXXMethodDecl *Method = dyn_cast_or_null(FDecl))
-if (Method->isImplicitObjectMemberFunction())
+if (!isa(CurContext) &&

erichkeane wrote:

I still dont think 'implictObjectMemberFunction' is the right thing here.  Why 
does the fact that it is not a 'Explit Object Member Function' matter?  

like:
```
struct S {
void foo(this S){}
};
void bar() {
S::foo();
};
```
??

Or static member functions?  This solution just doesn't seem right to me, and 
your responses dont' make it more clear.

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


[clang] [CMake][Release] Disable PGO (PR #88465)

2024-04-12 Thread via cfe-commits

llvmbot wrote:


Failed to cherry-pick: 0d2bb7f017f13ceae793fab7d83d3e67e8d8d8f8)

https://github.com/llvm/llvm-project/actions/runs/8668528827

Please manually backport the fix and push it to your github fork.  Once this is 
done, please create a [pull 
request](https://github.com/llvm/llvm-project/compare)

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


[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

2024-04-12 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Ping:)

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


[clang] [CMake][Release] Disable PGO (PR #88465)

2024-04-12 Thread Tom Stellard via cfe-commits

tstellar wrote:

/cherry-pick 0d2bb7f017f13ceae793fab7d83d3e67e8d8d8f8)

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


[clang] [CMake][Release] Disable PGO (PR #88465)

2024-04-12 Thread Tom Stellard via cfe-commits

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


[clang] [CMake][Release] Disable PGO (PR #88465)

2024-04-12 Thread Tom Stellard via cfe-commits

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


[clang] 0d2bb7f - [CMake][Release] Disable PGO (#88465)

2024-04-12 Thread via cfe-commits

Author: Tom Stellard
Date: 2024-04-12T15:10:04-07:00
New Revision: 0d2bb7f017f13ceae793fab7d83d3e67e8d8d8f8

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

LOG: [CMake][Release] Disable PGO (#88465)

Running the test-release.sh script with PGO enabled causes build errors
like:

ld.lld: error: Function Import: link error: linking module flags
'ProfileSummary': IDs have conflicting values

I believe this a build system bug due to the PGO profile data being
generated unconditionally. If you run `ninja check-all` and then `ninja
install` like we do in test-release.sh, then the profile data is
regenerated during `ninja install` and some of the clang tools which are
not test dependencies get build during the ninja install step with
different profile data. When these tools link against the LLVM
libraries, like libSupport, we end up with these errors.

Added: 


Modified: 
clang/cmake/caches/Release.cmake

Removed: 




diff  --git a/clang/cmake/caches/Release.cmake 
b/clang/cmake/caches/Release.cmake
index 1ca9138b980731..bd1f688d61a7ea 100644
--- a/clang/cmake/caches/Release.cmake
+++ b/clang/cmake/caches/Release.cmake
@@ -4,7 +4,7 @@
 
 # General Options
 set(LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "")
-set(LLVM_RELEASE_ENABLE_PGO ON CACHE BOOL "")
+set(LLVM_RELEASE_ENABLE_PGO OFF CACHE BOOL "")
 
 set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
 



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


[clang] [clang][modules] Headers meant to be included multiple times can be completely invisible in clang module builds (PR #83660)

2024-04-12 Thread Ian Anderson via cfe-commits

ian-twilightcoder wrote:

> The end result should be that #imported and #pragma once-guarded files are 
> treated the same way as #ifndef-guarded files.

While I don't necessarily disagree with that goal in principle, it wasn't true 
before this change either. There was already some special casing to defeat 
`#import`. This change just adds another special case to the `#import` path. 
`#include` doesn't even go through the modified code that is 
`MaybeReenterImportedFile` (née `TryEnterImported`).

> I know you weren't trying to fix that -- but I'm saying that's the thing that 
> _should_ be fixed, and that doing so would fix the _serious_ part of the 
> problem you described in the initial message.

Modular headers including non-modular headers is a special problem. If we let 
every module enter the non-modular header (which Jan's patch does), its 
declarations will build into multiple modules/pcm files, where they will 1) 
conflict and cause errors in the several cases where type merging can't handle 
them, and 2) come from multiple modules which is undefined behavior for Swift 
(i.e. Swift will see `mod1.type` and `mod2.type` and won't know how to resolve 
un-qualified `type` in code). So I don't think that case really _can_ be fixed.

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


[clang] [C++20] [Modules] Introduce -fexperimental-modules-reduced-bmi (PR #85050)

2024-04-12 Thread David Blaikie via cfe-commits

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


[clang] [C++20] [Modules] Introduce -fexperimental-modules-reduced-bmi (PR #85050)

2024-04-12 Thread David Blaikie via cfe-commits

https://github.com/dwblaikie approved this pull request.

Give it a go

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


[clang] [C++20] [Modules] Introduce -fexperimental-modules-reduced-bmi (PR #85050)

2024-04-12 Thread David Blaikie via cfe-commits


@@ -1061,6 +1070,16 @@ CodeGenAction::CreateASTConsumer(CompilerInstance , 
StringRef InFile) {
 CI.getPreprocessor().addPPCallbacks(std::move(Callbacks));
   }
 
+  if (CI.getFrontendOpts().GenReducedBMI &&
+  !CI.getFrontendOpts().ModuleOutputPath.empty()) {
+std::vector> Consumers{2};
+Consumers[0] = std::make_unique(
+CI.getPreprocessor(), CI.getModuleCache(),
+CI.getFrontendOpts().ModuleOutputPath);
+Consumers[1] = std::move(Result);
+return std::make_unique(std::move(Consumers));
+  }

dwblaikie wrote:

Why is this new code, rather than an alternative codepath of existing code? 
(like some code that was producing the BMI would go from producing the 
unreduced BMI to producing the reduced BMI)

Figuring this out would help me unedrstand why `ModuleOutputPath` is new (this 
patch doesn't add the functionality to output a module to a path - we had that 
already, this just changes the content that goes there)

I guess because maybe this patch is changing the way we output the BMI - or 
that the reduced BMI is being output in a different way than the non-reduced 
BMI?

Should we address that? Make the current full BMI emission work the same way as 
the reduced BMI? (or, more precisely, in a pre-patch, change the full BMI 
emission to use a mechanism that can then be reused for the reduced BMI?)

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


[clang] [clang][modules] Headers meant to be included multiple times can be completely invisible in clang module builds (PR #83660)

2024-04-12 Thread James Y Knight via cfe-commits

jyknight wrote:

> The problem I'm trying to fix is that nobody knows when it's appropriate to 
> use #import vs #include

But you haven't really (and I think cannot) fixed that.

> using header guards or #pragma once is very "un-Objective-C". 

Yes, this is quite unfortunate. The best answer would be to change the 
recommended style, but unfortunately, it's probably 20-30 years too late to do 
so effectively. (I mean, it would be a start if Apple added `#pragma once` to 
all of the SDK headers.)

Your initial comment said:
> Normally this isn't a big problem, [...] However, when clang modules are 
> involved, this can cause the header to be hidden entirely.

And I am basically agreeing with this. The current state of objc 
include/import, while unfortunate, has existed for decades, and is usually not 
a big problem. And, I think that means we shouldn't add more complexity to the 
semantics of `#import` in an attempt to fix it. But the "header is hidden 
entirely" _is_ a big problem, and that part is due to the bug I described -- so 
if that bug is fixed, we're back to "isn't a big problem", without making this 
change in semantics.

> An alternative solution would be @jansvoboda11's 
> https://github.com/llvm/llvm-project/pull/71117, but I believe that will 
> cause issues with non-modular headers building into multiple modules.

I haven't looked at that, but it sounds promising. The end result should be 
that `#import`ed and `#pragma once`-guarded files are treated the same way as 
`#ifndef`-guarded files. I wouldn't expect that to cause issues with 
non-modular headers included in multiple modules, given that works for 
`#ifndef`-guarded files, today.

> Also this change isn't trying to modify #include in any kind of way, only 
> #import. So it's quite intentional that your test behaves the same before and 
> after.

I know you weren't trying to fix that -- but I'm saying that's the thing that 
_should_ be fixed, and that doing so would fix the _serious_ part of the 
problem you described in the initial message.

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


[clang] 03c393d - Fix build failure from a472e6473e69

2024-04-12 Thread via cfe-commits

Author: erichkeane
Date: 2024-04-12T14:48:39-07:00
New Revision: 03c393db1821ef4c362c4c228492c6fb03f8876f

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

LOG: Fix build failure from a472e6473e69

Looks like I forgot to do build CIndex.cpp when validating myself!

Added: 


Modified: 
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index b999750c0f5e32..f304786ff9dffd 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -2783,7 +2783,7 @@ class OpenACCClauseEnqueue : public 
OpenACCClauseVisitor {
   OpenACCClauseEnqueue(EnqueueVisitor ) : Visitor(V) {}
 
 #define VISIT_CLAUSE(CLAUSE_NAME)  
\
-  void VisitOpenACC##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause 
);
+  void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause );
 #include "clang/Basic/OpenACCClauses.def"
 };
 



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


[clang] [llvm] [llvm][support] Implement tracing virtual file system (PR #88326)

2024-04-12 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/88326

>From 665fd1a3fab4730851d14bc879c34341cbfd6a5e Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Fri, 12 Apr 2024 10:47:13 -0700
Subject: [PATCH] [llvm][support] Implement tracing virtual file system

---
 .../DependencyScanningFilesystemTest.cpp  | 32 +---
 llvm/include/llvm/Support/VirtualFileSystem.h | 48 ++
 llvm/lib/Support/VirtualFileSystem.cpp| 13 +
 .../Support/VirtualFileSystemTest.cpp | 50 +++
 4 files changed, 113 insertions(+), 30 deletions(-)

diff --git 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
index 87bb67cfd9327c..bf0ebe58cd35e6 100644
--- 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
+++ 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
@@ -13,39 +13,11 @@
 
 using namespace clang::tooling::dependencies;
 
-namespace {
-struct InstrumentingFilesystem
-: llvm::RTTIExtends {
-  unsigned NumStatusCalls = 0;
-  unsigned NumGetRealPathCalls = 0;
-  unsigned NumExistsCalls = 0;
-
-  using llvm::RTTIExtends::RTTIExtends;
-
-  llvm::ErrorOr status(const llvm::Twine ) override {
-++NumStatusCalls;
-return ProxyFileSystem::status(Path);
-  }
-
-  std::error_code getRealPath(const llvm::Twine ,
-  llvm::SmallVectorImpl ) override {
-++NumGetRealPathCalls;
-return ProxyFileSystem::getRealPath(Path, Output);
-  }
-
-  bool exists(const llvm::Twine ) override {
-++NumExistsCalls;
-return ProxyFileSystem::exists(Path);
-  }
-};
-} // namespace
-
 TEST(DependencyScanningWorkerFilesystem, CacheStatusFailures) {
   auto InMemoryFS = llvm::makeIntrusiveRefCnt();
 
   auto InstrumentingFS =
-  llvm::makeIntrusiveRefCnt(InMemoryFS);
+  llvm::makeIntrusiveRefCnt(InMemoryFS);
 
   DependencyScanningFilesystemSharedCache SharedCache;
   DependencyScanningWorkerFilesystem DepFS(SharedCache, InstrumentingFS);
@@ -71,7 +43,7 @@ TEST(DependencyScanningFilesystem, CacheGetRealPath) {
   InMemoryFS->addFile("/bar", 0, llvm::MemoryBuffer::getMemBuffer(""));
 
   auto InstrumentingFS =
-  llvm::makeIntrusiveRefCnt(InMemoryFS);
+  llvm::makeIntrusiveRefCnt(InMemoryFS);
 
   DependencyScanningFilesystemSharedCache SharedCache;
   DependencyScanningWorkerFilesystem DepFS(SharedCache, InstrumentingFS);
diff --git a/llvm/include/llvm/Support/VirtualFileSystem.h 
b/llvm/include/llvm/Support/VirtualFileSystem.h
index 0113d6b7da25d3..21c810a6d7110d 100644
--- a/llvm/include/llvm/Support/VirtualFileSystem.h
+++ b/llvm/include/llvm/Support/VirtualFileSystem.h
@@ -1129,6 +1129,54 @@ class YAMLVFSWriter {
   void write(llvm::raw_ostream );
 };
 
+/// File system that tracks the number of calls to the underlying file system.
+/// This is particularly useful when wrapped around \c RealFileSystem to add
+/// lightweight tracking of expensive syscalls.
+class TracingFileSystem
+: public llvm::RTTIExtends {
+public:
+  static const char ID;
+
+  std::size_t NumStatusCalls = 0;
+  std::size_t NumOpenFileForReadCalls = 0;
+  std::size_t NumDirBeginCalls = 0;
+  std::size_t NumGetRealPathCalls = 0;
+  std::size_t NumIsLocalCalls = 0;
+
+  TracingFileSystem(llvm::IntrusiveRefCntPtr FS)
+  : RTTIExtends(std::move(FS)) {}
+
+  ErrorOr status(const Twine ) override {
+++NumStatusCalls;
+return ProxyFileSystem::status(Path);
+  }
+
+  ErrorOr> openFileForRead(const Twine ) override {
+++NumOpenFileForReadCalls;
+return ProxyFileSystem::openFileForRead(Path);
+  }
+
+  directory_iterator dir_begin(const Twine , std::error_code ) override 
{
+++NumDirBeginCalls;
+return ProxyFileSystem::dir_begin(Dir, EC);
+  }
+
+  std::error_code getRealPath(const Twine ,
+  SmallVectorImpl ) override {
+++NumGetRealPathCalls;
+return ProxyFileSystem::getRealPath(Path, Output);
+  }
+
+  std::error_code isLocal(const Twine , bool ) override {
+++NumIsLocalCalls;
+return ProxyFileSystem::isLocal(Path, Result);
+  }
+
+protected:
+  void printImpl(raw_ostream , PrintType Type,
+ unsigned IndentLevel) const override;
+};
+
 } // namespace vfs
 } // namespace llvm
 
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp 
b/llvm/lib/Support/VirtualFileSystem.cpp
index 921af30bfcde9f..0c5fe4fdf289d7 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -2933,8 +2933,21 @@ recursive_directory_iterator::increment(std::error_code 
) {
   return *this;
 }
 
+void TracingFileSystem::printImpl(raw_ostream , PrintType Type,
+  unsigned IndentLevel) const {
+  printIndent(OS, IndentLevel);
+  OS << "TracingFileSystem\n";
+  if (Type == PrintType::Summary)
+return;
+
+  if (Type == 

[clang] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-12 Thread via cfe-commits

github-actions[bot] wrote:



@artemcm Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-12 Thread Jan Svoboda via cfe-commits

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


[clang] 779ba60 - [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (#88152)

2024-04-12 Thread via cfe-commits

Author: Artem Chikin
Date: 2024-04-12T14:46:56-07:00
New Revision: 779ba60417b467a6d2d25101b11711c009694315

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

LOG: [clang][deps] Overload `Filesystem::exists` in 
`DependencyScanningFilesystem` to have it use cached `status` (#88152)

As-is, calls to `exists()` fallback on the implementation in
`ProxyFileSystem::exists` which explicitly calls out to the underlying
`FS`, which for the `DependencyScanningFilesystem` (overlay) is the real
underlying filesystem.

Instead, directly overloading `exists` allows us to have it rely on the
cached `status` behavior used elsewhere by the
`DependencyScanningFilesystem`.

Added: 


Modified: 

clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index 8b6f149c7cb266..f7b4510d7f7beb 100644
--- 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -365,6 +365,10 @@ class DependencyScanningWorkerFilesystem
   /// false if not (i.e. this entry is not a file or its scan fails).
   bool ensureDirectiveTokensArePopulated(EntryRef Entry);
 
+  /// Check whether \p Path exists. By default checks cached result of \c
+  /// status(), and falls back on FS if unable to do so.
+  bool exists(const Twine ) override;
+
 private:
   /// For a filename that's not yet associated with any entry in the caches,
   /// uses the underlying filesystem to either look up the entry based in the

diff  --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 84185c931b552c..0cab17a3424406 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -300,6 +300,17 @@ DependencyScanningWorkerFilesystem::status(const Twine 
) {
   return Result->getStatus();
 }
 
+bool DependencyScanningWorkerFilesystem::exists(const Twine ) {
+  // While some VFS overlay filesystems may implement more-efficient
+  // mechanisms for `exists` queries, `DependencyScanningWorkerFilesystem`
+  // typically wraps `RealFileSystem` which does not specialize `exists`,
+  // so it is not likely to benefit from such optimizations. Instead,
+  // it is more-valuable to have this query go through the
+  // cached-`status` code-path of the `DependencyScanningWorkerFilesystem`.
+  llvm::ErrorOr Status = status(Path);
+  return Status && Status->exists();
+}
+
 namespace {
 
 /// The VFS that is used by clang consumes the \c CachedFileSystemEntry using

diff  --git 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
index 697b7d70ff035a..87bb67cfd9327c 100644
--- 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
+++ 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
@@ -18,6 +18,7 @@ struct InstrumentingFilesystem
 : llvm::RTTIExtends {
   unsigned NumStatusCalls = 0;
   unsigned NumGetRealPathCalls = 0;
+  unsigned NumExistsCalls = 0;
 
   using llvm::RTTIExtends::RTTIExtends;
@@ -32,6 +33,11 @@ struct InstrumentingFilesystem
 ++NumGetRealPathCalls;
 return ProxyFileSystem::getRealPath(Path, Output);
   }
+
+  bool exists(const llvm::Twine ) override {
+++NumExistsCalls;
+return ProxyFileSystem::exists(Path);
+  }
 };
 } // namespace
 
@@ -147,3 +153,24 @@ TEST(DependencyScanningFilesystem, 
RealPathAndStatusInvariants) {
 DepFS.status("/bar");
   }
 }
+
+TEST(DependencyScanningFilesystem, CacheStatOnExists) {
+  auto InMemoryFS = llvm::makeIntrusiveRefCnt();
+  auto InstrumentingFS =
+  llvm::makeIntrusiveRefCnt(InMemoryFS);
+  InMemoryFS->setCurrentWorkingDirectory("/");
+  InMemoryFS->addFile("/foo", 0, llvm::MemoryBuffer::getMemBuffer(""));
+  InMemoryFS->addFile("/bar", 0, llvm::MemoryBuffer::getMemBuffer(""));
+  DependencyScanningFilesystemSharedCache SharedCache;
+  DependencyScanningWorkerFilesystem DepFS(SharedCache, InstrumentingFS);
+
+  DepFS.status("/foo");
+  DepFS.status("/foo");
+  DepFS.status("/bar");
+  EXPECT_EQ(InstrumentingFS->NumStatusCalls, 2u);
+
+  DepFS.exists("/foo");
+  DepFS.exists("/bar");
+  EXPECT_EQ(InstrumentingFS->NumStatusCalls, 2u);
+  

[clang] db8e182 - [NFC] Clang-format previous OpenACC Patch

2024-04-12 Thread via cfe-commits

Author: erichkeane
Date: 2024-04-12T14:44:20-07:00
New Revision: db8e182952573fa9198424a6ed1b1bb1676eae62

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

LOG: [NFC] Clang-format previous OpenACC Patch

Added: 


Modified: 
clang/lib/AST/OpenACCClause.cpp
clang/lib/AST/StmtProfile.cpp

Removed: 




diff  --git a/clang/lib/AST/OpenACCClause.cpp b/clang/lib/AST/OpenACCClause.cpp
index 446e4700320471..dcb512cb514179 100644
--- a/clang/lib/AST/OpenACCClause.cpp
+++ b/clang/lib/AST/OpenACCClause.cpp
@@ -65,8 +65,7 @@ OpenACCClause::child_range OpenACCClause::children() {
 
//===--===//
 //  OpenACC clauses printing methods
 
//===--===//
-void OpenACCClausePrinter::VisitDefaultClause(
-const OpenACCDefaultClause ) {
+void OpenACCClausePrinter::VisitDefaultClause(const OpenACCDefaultClause ) {
   OS << "default(" << C.getDefaultClauseKind() << ")";
 }
 

diff  --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index 68ba7475f4ca42..d2aac1e640380f 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -2459,8 +2459,7 @@ class OpenACCClauseProfiler
   }
 
 #define VISIT_CLAUSE(CLAUSE_NAME)  
\
-  void Visit##CLAUSE_NAME##Clause(  \
-  const OpenACC##CLAUSE_NAME##Clause );
+  void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause );
 
 #include "clang/Basic/OpenACCClauses.def"
 };
@@ -2469,8 +2468,7 @@ class OpenACCClauseProfiler
 void OpenACCClauseProfiler::VisitDefaultClause(
 const OpenACCDefaultClause ) {}
 
-void OpenACCClauseProfiler::VisitIfClause(
-const OpenACCIfClause ) {
+void OpenACCClauseProfiler::VisitIfClause(const OpenACCIfClause ) {
   assert(Clause.hasConditionExpr() &&
  "if clause requires a valid condition expr");
   Profiler.VisitStmt(Clause.getConditionExpr());



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


[clang] [clang] MangledSymbol: Added move to Names param in init list (PR #87287)

2024-04-12 Thread Braden Helmer via cfe-commits

https://github.com/bradenhelmer updated 
https://github.com/llvm/llvm-project/pull/87287

>From 4d0290b2dc10705cf229e4c1c3b40dd5155ea61c Mon Sep 17 00:00:00 2001
From: Braden Helmer 
Date: Mon, 1 Apr 2024 18:09:59 -0400
Subject: [PATCH] Added move for Names parameter in MangledSymbol ctor

---
 clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp 
b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
index d58f5bb0919906..81a827dba26b90 100644
--- a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
+++ b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
@@ -33,7 +33,8 @@ class InterfaceStubFunctionsConsumer : public ASTConsumer {
 
 MangledSymbol(const std::string , uint8_t Type, uint8_t Binding,
   std::vector Names)
-: ParentName(ParentName), Type(Type), Binding(Binding), Names(Names) {}
+: ParentName(ParentName), Type(Type), Binding(Binding),
+  Names(std::move(Names)) {}
   };
   using MangledSymbols = std::map;
 

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


[clang] a472e64 - [NFC][OpenACC] Rename visitor functions to omit redundant OpenACC

2024-04-12 Thread via cfe-commits

Author: erichkeane
Date: 2024-04-12T14:42:06-07:00
New Revision: a472e6473e6921f22427d41c3d29e9a26eb4ab32

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

LOG: [NFC][OpenACC] Rename visitor functions to omit redundant OpenACC

While working on a followup patch, it became clear that this extra bit
of 'OpenACC' before each clause name was redundant with the visitors, so
remove it to make this a little less verbose.

Added: 


Modified: 
clang/include/clang/AST/OpenACCClause.h
clang/lib/AST/OpenACCClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/include/clang/AST/OpenACCClause.h 
b/clang/include/clang/AST/OpenACCClause.h
index 712ad46c0f238d..401b8e904a1b7a 100644
--- a/clang/include/clang/AST/OpenACCClause.h
+++ b/clang/include/clang/AST/OpenACCClause.h
@@ -160,10 +160,10 @@ template  class OpenACCClauseVisitor {
 
 switch (C->getClauseKind()) {
 case OpenACCClauseKind::Default:
-  VisitOpenACCDefaultClause(*cast(C));
+  VisitDefaultClause(*cast(C));
   return;
 case OpenACCClauseKind::If:
-  VisitOpenACCIfClause(*cast(C));
+  VisitIfClause(*cast(C));
   return;
 case OpenACCClauseKind::Finalize:
 case OpenACCClauseKind::IfPresent:
@@ -212,9 +212,9 @@ template  class OpenACCClauseVisitor {
   }
 
 #define VISIT_CLAUSE(CLAUSE_NAME)  
\
-  void VisitOpenACC##CLAUSE_NAME##Clause(  
\
+  void Visit##CLAUSE_NAME##Clause( 
\
   const OpenACC##CLAUSE_NAME##Clause ) {
\
-return getDerived().VisitOpenACC##CLAUSE_NAME##Clause(Clause); 
\
+return getDerived().Visit##CLAUSE_NAME##Clause(Clause);
\
   }
 
 #include "clang/Basic/OpenACCClauses.def"
@@ -236,8 +236,7 @@ class OpenACCClausePrinter final
   OpenACCClausePrinter(raw_ostream ) : OS(OS) {}
 
 #define VISIT_CLAUSE(CLAUSE_NAME)  
\
-  void VisitOpenACC##CLAUSE_NAME##Clause(  
\
-  const OpenACC##CLAUSE_NAME##Clause );
+  void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause );
 #include "clang/Basic/OpenACCClauses.def"
 };
 

diff  --git a/clang/lib/AST/OpenACCClause.cpp b/clang/lib/AST/OpenACCClause.cpp
index 2bc8d14fa129b4..446e4700320471 100644
--- a/clang/lib/AST/OpenACCClause.cpp
+++ b/clang/lib/AST/OpenACCClause.cpp
@@ -65,11 +65,11 @@ OpenACCClause::child_range OpenACCClause::children() {
 
//===--===//
 //  OpenACC clauses printing methods
 
//===--===//
-void OpenACCClausePrinter::VisitOpenACCDefaultClause(
+void OpenACCClausePrinter::VisitDefaultClause(
 const OpenACCDefaultClause ) {
   OS << "default(" << C.getDefaultClauseKind() << ")";
 }
 
-void OpenACCClausePrinter::VisitOpenACCIfClause(const OpenACCIfClause ) {
+void OpenACCClausePrinter::VisitIfClause(const OpenACCIfClause ) {
   OS << "if(" << C.getConditionExpr() << ")";
 }

diff  --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index 44b635bfb8433b..68ba7475f4ca42 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -2459,17 +2459,17 @@ class OpenACCClauseProfiler
   }
 
 #define VISIT_CLAUSE(CLAUSE_NAME)  
\
-  void VisitOpenACC##CLAUSE_NAME##Clause(  
\
+  void Visit##CLAUSE_NAME##Clause(  \
   const OpenACC##CLAUSE_NAME##Clause );
 
 #include "clang/Basic/OpenACCClauses.def"
 };
 
 /// Nothing to do here, there are no sub-statements.
-void OpenACCClauseProfiler::VisitOpenACCDefaultClause(
+void OpenACCClauseProfiler::VisitDefaultClause(
 const OpenACCDefaultClause ) {}
 
-void OpenACCClauseProfiler::VisitOpenACCIfClause(
+void OpenACCClauseProfiler::VisitIfClause(
 const OpenACCIfClause ) {
   assert(Clause.hasConditionExpr() &&
  "if clause requires a valid condition expr");

diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 936e8872513ae6..b999750c0f5e32 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -2787,9 +2787,8 @@ class OpenACCClauseEnqueue : public 
OpenACCClauseVisitor {
 #include "clang/Basic/OpenACCClauses.def"
 };
 
-void OpenACCClauseEnqueue::VisitOpenACCDefaultClause(
-const OpenACCDefaultClause ) {}
-void OpenACCClauseEnqueue::VisitOpenACCIfClause(const OpenACCIfClause ) {
+void OpenACCClauseEnqueue::VisitDefaultClause(const OpenACCDefaultClause ) 

[clang] eaa3947 - [NFC] Remove unused type alias in OpenACC

2024-04-12 Thread via cfe-commits

Author: erichkeane
Date: 2024-04-12T14:42:06-07:00
New Revision: eaa3947106e50d6d837e6681fb55cf92c2bb0f9a

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

LOG: [NFC] Remove unused type alias in OpenACC

Leftover from a previous commit, this ends up not being used, so remove
it.

Added: 


Modified: 
clang/include/clang/Parse/Parser.h

Removed: 




diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index db90d38c7dacf8..c719218731c35b 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3611,9 +3611,6 @@ class Parser : public CodeCompletionHandler {
   OpenACCClauseParseResult OpenACCCannotContinue();
   OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause);
 
-  using OpenACCConditionExprParseResult =
-  std::pair;
-
   /// Parses the OpenACC directive (the entire pragma) including the clause
   /// list, but does not produce the main AST node.
   OpenACCDirectiveParseInfo ParseOpenACCDirective();



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


[clang] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-12 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 approved this pull request.

LGTM, thanks a lot!

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


[clang] [clang][modules] Headers meant to be included multiple times can be completely invisible in clang module builds (PR #83660)

2024-04-12 Thread Ian Anderson via cfe-commits

ian-twilightcoder wrote:

Also this change isn't trying to modify `#include` in any kind of way, _only_ 
`#import`. So it's quite intentional that your test behaves the same before and 
after.

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


[clang] [libc] [llvm] Fix typos (PR #88565)

2024-04-12 Thread via cfe-commits

github-actions[bot] wrote:



@ViToni Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] [libc] [llvm] Fix typos (PR #88565)

2024-04-12 Thread Nick Desaulniers via cfe-commits

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


[clang] 900be90 - Fix typos (#88565)

2024-04-12 Thread via cfe-commits

Author: Victor Toni
Date: 2024-04-12T14:33:35-07:00
New Revision: 900be9013fdc3bab9fce906f8a71e59ecd8873b4

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

LOG: Fix typos (#88565)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
libc/src/__support/str_to_float.h
llvm/lib/Analysis/LoopCacheAnalysis.cpp
llvm/lib/Support/APInt.cpp
llvm/lib/Transforms/Scalar/LoopInterchange.cpp
llvm/test/Transforms/JumpThreading/free_instructions.ll
llvm/utils/lint/common_lint.py

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
index 504fd7f05e0f99..c50db1e0e2f863 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -229,7 +229,7 @@ SVal ExprEngine::computeObjectUnderConstruction(
 // We are on the top frame of the analysis. We do not know where is the
 // object returned to. Conjure a symbolic region for the return value.
 // TODO: We probably need a new MemRegion kind to represent the storage
-// of that SymbolicRegion, so that we cound produce a fancy symbol
+// of that SymbolicRegion, so that we could produce a fancy symbol
 // instead of an anonymous conjured symbol.
 // TODO: Do we need to track the region to avoid having it dead
 // too early? It does die too early, at least in C++17, but because

diff  --git a/libc/src/__support/str_to_float.h 
b/libc/src/__support/str_to_float.h
index cd0c07629f8766..fa466ca8492fc4 100644
--- a/libc/src/__support/str_to_float.h
+++ b/libc/src/__support/str_to_float.h
@@ -695,10 +695,10 @@ LIBC_INLINE FloatConvertReturn decimal_exp_to_float(
 // If the mantissa is truncated, then the result may be off by the LSB, so
 // check if rounding the mantissa up changes the result. If not, then it's
 // safe, else use the fallback.
-auto secound_output = eisel_lemire({mantissa + 1, exp10}, round);
-if (secound_output.has_value()) {
-  if (opt_output->mantissa == secound_output->mantissa &&
-  opt_output->exponent == secound_output->exponent) {
+auto second_output = eisel_lemire({mantissa + 1, exp10}, round);
+if (second_output.has_value()) {
+  if (opt_output->mantissa == second_output->mantissa &&
+  opt_output->exponent == second_output->exponent) {
 return {opt_output.value(), 0};
   }
 }

diff  --git a/llvm/lib/Analysis/LoopCacheAnalysis.cpp 
b/llvm/lib/Analysis/LoopCacheAnalysis.cpp
index c3a56639b5c8f8..284d8d16d264e9 100644
--- a/llvm/lib/Analysis/LoopCacheAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopCacheAnalysis.cpp
@@ -315,7 +315,7 @@ CacheCostTy IndexedReference::computeRefCost(const Loop ,
 RefCost = TripCount;
 
 int Index = getSubscriptIndex(L);
-assert(Index >= 0 && "Cound not locate a valid Index");
+assert(Index >= 0 && "Could not locate a valid Index");
 
 for (unsigned I = Index + 1; I < getNumSubscripts() - 1; ++I) {
   const SCEVAddRecExpr *AR = dyn_cast(getSubscript(I));

diff  --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 18feca4c05533c..24e136fcb9c7f7 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -2663,7 +2663,7 @@ int APInt::tcDivide(WordType *lhs, const WordType *rhs,
   return false;
 }
 
-/// Shift a bignum left Cound bits in-place. Shifted in bits are zero. There 
are
+/// Shift a bignum left Count bits in-place. Shifted in bits are zero. There 
are
 /// no restrictions on Count.
 void APInt::tcShiftLeft(WordType *Dst, unsigned Words, unsigned Count) {
   // Don't bother performing a no-op shift.

diff  --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp 
b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index 277f530ee25fc1..400973fd9fc915 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -976,7 +976,7 @@ bool LoopInterchangeLegality::canInterchangeLoops(unsigned 
InnerLoopId,
   }
 
   if (!findInductions(InnerLoop, InnerLoopInductions)) {
-LLVM_DEBUG(dbgs() << "Cound not find inner loop induction variables.\n");
+LLVM_DEBUG(dbgs() << "Could not find inner loop induction variables.\n");
 return false;
   }
 

diff  --git a/llvm/test/Transforms/JumpThreading/free_instructions.ll 
b/llvm/test/Transforms/JumpThreading/free_instructions.ll
index 3485bf8c98da86..48bedc72c2d312 100644
--- a/llvm/test/Transforms/JumpThreading/free_instructions.ll
+++ b/llvm/test/Transforms/JumpThreading/free_instructions.ll
@@ -1,7 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt -S -passes=jump-threading -jump-threading-threshold=3 < %s | 

[clang] [llvm] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-12 Thread Vitaly Buka via cfe-commits

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


[clang] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-12 Thread Artem Chikin via cfe-commits

https://github.com/artemcm updated 
https://github.com/llvm/llvm-project/pull/88152

>From 1989bbbdb1d575e2e938ec319ad9ad23db6af6fc Mon Sep 17 00:00:00 2001
From: Artem Chikin 
Date: Tue, 9 Apr 2024 09:37:09 -0700
Subject: [PATCH] [clang][deps] Overload 'Filesystem::exists' in
 'DependencyScanningFilesystem' to have it use cached `status`

As-is, calls to `exists()` fallback on the implementation in 
'ProxyFileSystem::exists' which explicitly calls out to the underlying `FS`, 
which for the 'DependencyScanningFilesystem' (overlay) is the real underlying 
filesystem.

Instead, directly overloading 'exists' allows us to have it rely on the cached 
`status` behavior used elsewhere by the 'DependencyScanningFilesystem'.
---
 .../DependencyScanningFilesystem.h|  4 +++
 .../DependencyScanningFilesystem.cpp  | 11 
 .../DependencyScanningFilesystemTest.cpp  | 27 +++
 3 files changed, 42 insertions(+)

diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index 8b6f149c7cb266..f7b4510d7f7beb 100644
--- 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -365,6 +365,10 @@ class DependencyScanningWorkerFilesystem
   /// false if not (i.e. this entry is not a file or its scan fails).
   bool ensureDirectiveTokensArePopulated(EntryRef Entry);
 
+  /// Check whether \p Path exists. By default checks cached result of \c
+  /// status(), and falls back on FS if unable to do so.
+  bool exists(const Twine ) override;
+
 private:
   /// For a filename that's not yet associated with any entry in the caches,
   /// uses the underlying filesystem to either look up the entry based in the
diff --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 84185c931b552c..0cab17a3424406 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -300,6 +300,17 @@ DependencyScanningWorkerFilesystem::status(const Twine 
) {
   return Result->getStatus();
 }
 
+bool DependencyScanningWorkerFilesystem::exists(const Twine ) {
+  // While some VFS overlay filesystems may implement more-efficient
+  // mechanisms for `exists` queries, `DependencyScanningWorkerFilesystem`
+  // typically wraps `RealFileSystem` which does not specialize `exists`,
+  // so it is not likely to benefit from such optimizations. Instead,
+  // it is more-valuable to have this query go through the
+  // cached-`status` code-path of the `DependencyScanningWorkerFilesystem`.
+  llvm::ErrorOr Status = status(Path);
+  return Status && Status->exists();
+}
+
 namespace {
 
 /// The VFS that is used by clang consumes the \c CachedFileSystemEntry using
diff --git 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
index 697b7d70ff035a..87bb67cfd9327c 100644
--- 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
+++ 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
@@ -18,6 +18,7 @@ struct InstrumentingFilesystem
 : llvm::RTTIExtends {
   unsigned NumStatusCalls = 0;
   unsigned NumGetRealPathCalls = 0;
+  unsigned NumExistsCalls = 0;
 
   using llvm::RTTIExtends::RTTIExtends;
@@ -32,6 +33,11 @@ struct InstrumentingFilesystem
 ++NumGetRealPathCalls;
 return ProxyFileSystem::getRealPath(Path, Output);
   }
+
+  bool exists(const llvm::Twine ) override {
+++NumExistsCalls;
+return ProxyFileSystem::exists(Path);
+  }
 };
 } // namespace
 
@@ -147,3 +153,24 @@ TEST(DependencyScanningFilesystem, 
RealPathAndStatusInvariants) {
 DepFS.status("/bar");
   }
 }
+
+TEST(DependencyScanningFilesystem, CacheStatOnExists) {
+  auto InMemoryFS = llvm::makeIntrusiveRefCnt();
+  auto InstrumentingFS =
+  llvm::makeIntrusiveRefCnt(InMemoryFS);
+  InMemoryFS->setCurrentWorkingDirectory("/");
+  InMemoryFS->addFile("/foo", 0, llvm::MemoryBuffer::getMemBuffer(""));
+  InMemoryFS->addFile("/bar", 0, llvm::MemoryBuffer::getMemBuffer(""));
+  DependencyScanningFilesystemSharedCache SharedCache;
+  DependencyScanningWorkerFilesystem DepFS(SharedCache, InstrumentingFS);
+
+  DepFS.status("/foo");
+  DepFS.status("/foo");
+  DepFS.status("/bar");
+  EXPECT_EQ(InstrumentingFS->NumStatusCalls, 2u);
+
+  DepFS.exists("/foo");
+  DepFS.exists("/bar");
+  EXPECT_EQ(InstrumentingFS->NumStatusCalls, 2u);
+  EXPECT_EQ(InstrumentingFS->NumExistsCalls, 0u);
+}

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


[clang] [clang][modules] Headers meant to be included multiple times can be completely invisible in clang module builds (PR #83660)

2024-04-12 Thread Ian Anderson via cfe-commits

ian-twilightcoder wrote:

I don't really think it's the same thing. The problem I'm trying to fix is that 
nobody knows when it's appropriate to use `#import` vs `#include`, and the 
unfortunate convention of Objective-C makes it impossible for header owners to 
indicate if they support being included multiple times or not, as using header 
guards or `#pragma once` is very "un-Objective-C". Marking the header as 
`textual` is a fairly reasonable way for header owners to indicate that their 
header is meant to be included multiple times (e.g. stddef.h), even if ObjC 
developers don't know that and used `#import`. (The other use of `textual` that 
I've seen is for headers like `unwind_arm_ehabi.h` that are only allowed to 
have a single includer, and aren't really standalone.) If you don't want the 
header to build with the module, that's what `excluded` is for is it not?

And alternative solution would be @jansvoboda11's 
https://github.com/llvm/llvm-project/pull/71117, but I believe that will cause 
issues with non-modular headers building into multiple modules.

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


[clang] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-12 Thread Artem Chikin via cfe-commits

https://github.com/artemcm updated 
https://github.com/llvm/llvm-project/pull/88152

>From b7c693011abd785bec0a58fe4b6011a84f1ea329 Mon Sep 17 00:00:00 2001
From: Artem Chikin 
Date: Tue, 9 Apr 2024 09:37:09 -0700
Subject: [PATCH] [clang][deps] Overload 'Filesystem::exists' in
 'DependencyScanningFilesystem' to have it use cached `status`

As-is, calls to `exists()` fallback on the implementation in 
'ProxyFileSystem::exists' which explicitly calls out to the underlying `FS`, 
which for the 'DependencyScanningFilesystem' (overlay) is the real underlying 
filesystem.

Instead, directly overloading 'exists' allows us to have it rely on the cached 
`status` behavior used elsewhere by the 'DependencyScanningFilesystem'.
---
 .../DependencyScanningFilesystem.h|  4 +++
 .../DependencyScanningFilesystem.cpp  | 11 +++
 .../DependencyScanningFilesystemTest.cpp  | 30 +++
 3 files changed, 45 insertions(+)

diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index 8b6f149c7cb266..f7b4510d7f7beb 100644
--- 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -365,6 +365,10 @@ class DependencyScanningWorkerFilesystem
   /// false if not (i.e. this entry is not a file or its scan fails).
   bool ensureDirectiveTokensArePopulated(EntryRef Entry);
 
+  /// Check whether \p Path exists. By default checks cached result of \c
+  /// status(), and falls back on FS if unable to do so.
+  bool exists(const Twine ) override;
+
 private:
   /// For a filename that's not yet associated with any entry in the caches,
   /// uses the underlying filesystem to either look up the entry based in the
diff --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 84185c931b552c..0cab17a3424406 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -300,6 +300,17 @@ DependencyScanningWorkerFilesystem::status(const Twine 
) {
   return Result->getStatus();
 }
 
+bool DependencyScanningWorkerFilesystem::exists(const Twine ) {
+  // While some VFS overlay filesystems may implement more-efficient
+  // mechanisms for `exists` queries, `DependencyScanningWorkerFilesystem`
+  // typically wraps `RealFileSystem` which does not specialize `exists`,
+  // so it is not likely to benefit from such optimizations. Instead,
+  // it is more-valuable to have this query go through the
+  // cached-`status` code-path of the `DependencyScanningWorkerFilesystem`.
+  llvm::ErrorOr Status = status(Path);
+  return Status && Status->exists();
+}
+
 namespace {
 
 /// The VFS that is used by clang consumes the \c CachedFileSystemEntry using
diff --git 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
index 697b7d70ff035a..71447f43f1e6ff 100644
--- 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
+++ 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
@@ -18,6 +18,7 @@ struct InstrumentingFilesystem
 : llvm::RTTIExtends {
   unsigned NumStatusCalls = 0;
   unsigned NumGetRealPathCalls = 0;
+  unsigned NumExistsCalls = 0;
 
   using llvm::RTTIExtends::RTTIExtends;
@@ -32,6 +33,11 @@ struct InstrumentingFilesystem
 ++NumGetRealPathCalls;
 return ProxyFileSystem::getRealPath(Path, Output);
   }
+
+  bool exists(const llvm::Twine ) override {
+++NumExistsCalls;
+return ProxyFileSystem::exists(Path);
+  }
 };
 } // namespace
 
@@ -147,3 +153,27 @@ TEST(DependencyScanningFilesystem, 
RealPathAndStatusInvariants) {
 DepFS.status("/bar");
   }
 }
+
+TEST(DependencyScanningFilesystem, CacheStatOnExists) {
+  auto InMemoryFS = llvm::makeIntrusiveRefCnt();
+  auto InstrumentingFS =
+  llvm::makeIntrusiveRefCnt(InMemoryFS);
+  InMemoryFS->setCurrentWorkingDirectory("/");
+  InMemoryFS->addFile("/foo", 0,
+  llvm::MemoryBuffer::getMemBuffer(""));
+  InMemoryFS->addFile("/bar", 0,
+  llvm::MemoryBuffer::getMemBuffer(""));
+  DependencyScanningFilesystemSharedCache SharedCache;
+  DependencyScanningWorkerFilesystem DepFS(SharedCache,
+   InstrumentingFS);
+
+  DepFS.status("/foo");
+  DepFS.status("/foo");
+  DepFS.status("/bar");
+  EXPECT_EQ(InstrumentingFS->NumStatusCalls, 2u);
+
+  DepFS.exists("/foo");
+  DepFS.exists("/bar");
+  EXPECT_EQ(InstrumentingFS->NumStatusCalls, 2u);
+  EXPECT_EQ(InstrumentingFS->NumExistsCalls, 0u);
+}

___
cfe-commits mailing list

[clang] [clang][modules] Headers meant to be included multiple times can be completely invisible in clang module builds (PR #83660)

2024-04-12 Thread James Y Knight via cfe-commits

jyknight wrote:

Oh -- I'd also note that even if this is reverted, ilya-biryukov may want to 
continue to investigate the source-location issue -- it's entirely possible 
that the correct fix will trigger that same problem!

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


[clang] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-12 Thread Artem Chikin via cfe-commits

https://github.com/artemcm updated 
https://github.com/llvm/llvm-project/pull/88152

>From 1dd15b331795daaf2ac70cbd013f56f2d7677041 Mon Sep 17 00:00:00 2001
From: Artem Chikin 
Date: Tue, 9 Apr 2024 09:37:09 -0700
Subject: [PATCH] [clang][deps] Overload 'Filesystem::exists' in
 'DependencyScanningFilesystem' to have it use cached `status`

As-is, calls to `exists()` fallback on the implementation in 
'ProxyFileSystem::exists' which explicitly calls out to the underlying `FS`, 
which for the 'DependencyScanningFilesystem' (overlay) is the real underlying 
filesystem.

Instead, directly overloading 'exists' allows us to have it rely on the cached 
`status` behavior used elsewhere by the 'DependencyScanningFilesystem'.
---
 .../DependencyScanningFilesystem.h|  4 ++
 .../DependencyScanningFilesystem.cpp  | 11 
 .../DependencyScanningFilesystemTest.cpp  | 53 ++-
 3 files changed, 55 insertions(+), 13 deletions(-)

diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index 8b6f149c7cb266..f7b4510d7f7beb 100644
--- 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -365,6 +365,10 @@ class DependencyScanningWorkerFilesystem
   /// false if not (i.e. this entry is not a file or its scan fails).
   bool ensureDirectiveTokensArePopulated(EntryRef Entry);
 
+  /// Check whether \p Path exists. By default checks cached result of \c
+  /// status(), and falls back on FS if unable to do so.
+  bool exists(const Twine ) override;
+
 private:
   /// For a filename that's not yet associated with any entry in the caches,
   /// uses the underlying filesystem to either look up the entry based in the
diff --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 84185c931b552c..0cab17a3424406 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -300,6 +300,17 @@ DependencyScanningWorkerFilesystem::status(const Twine 
) {
   return Result->getStatus();
 }
 
+bool DependencyScanningWorkerFilesystem::exists(const Twine ) {
+  // While some VFS overlay filesystems may implement more-efficient
+  // mechanisms for `exists` queries, `DependencyScanningWorkerFilesystem`
+  // typically wraps `RealFileSystem` which does not specialize `exists`,
+  // so it is not likely to benefit from such optimizations. Instead,
+  // it is more-valuable to have this query go through the
+  // cached-`status` code-path of the `DependencyScanningWorkerFilesystem`.
+  llvm::ErrorOr Status = status(Path);
+  return Status && Status->exists();
+}
+
 namespace {
 
 /// The VFS that is used by clang consumes the \c CachedFileSystemEntry using
diff --git 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
index 697b7d70ff035a..256dd980b2118f 100644
--- 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
+++ 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "gtest/gtest.h"
 
@@ -15,31 +16,36 @@ using namespace clang::tooling::dependencies;
 
 namespace {
 struct InstrumentingFilesystem
-: llvm::RTTIExtends {
+: llvm::RTTIExtends {
   unsigned NumStatusCalls = 0;
   unsigned NumGetRealPathCalls = 0;
+  unsigned NumExistsCalls = 0;
 
   using llvm::RTTIExtends::RTTIExtends;
+  llvm::vfs::InMemoryFileSystem>::RTTIExtends;
 
   llvm::ErrorOr status(const llvm::Twine ) override {
 ++NumStatusCalls;
-return ProxyFileSystem::status(Path);
+return InMemoryFileSystem::status(Path);
   }
 
   std::error_code getRealPath(const llvm::Twine ,
   llvm::SmallVectorImpl ) override {
 ++NumGetRealPathCalls;
-return ProxyFileSystem::getRealPath(Path, Output);
+return InMemoryFileSystem::getRealPath(Path, Output);
+  }
+
+  bool exists(const llvm::Twine ) override {
+++NumExistsCalls;
+return InMemoryFileSystem::exists(Path);
   }
 };
+
 } // namespace
 
 TEST(DependencyScanningWorkerFilesystem, CacheStatusFailures) {
-  auto InMemoryFS = llvm::makeIntrusiveRefCnt();
-
   auto InstrumentingFS =
-  llvm::makeIntrusiveRefCnt(InMemoryFS);
+  llvm::makeIntrusiveRefCnt();
 
   DependencyScanningFilesystemSharedCache SharedCache;
   DependencyScanningWorkerFilesystem DepFS(SharedCache, InstrumentingFS);
@@ -59,13 

[clang] [clang][CodeGen] Add AS for Globals to SPIR & SPIRV datalayouts (PR #88455)

2024-04-12 Thread Alexey Bader via cfe-commits

https://github.com/bader commented:

> I'll emphasise that this is only a problem for things such as implicitly 
> generated globals (e.g. VTables or typeinfo for classes etc.)

I suppose usage of VTables and typeinfo is kind of restricted in GPU 
programming models. Right?

Anyway, I think it's a reasonable change for SPIR target, which fixes mapping 
from `global` address space to `1` LLVM address space.
It's less obvious for SPIR-V, which is not LLVM-based format and mapping 
between SPIR-V and LLVM addresses spaces is technically an implementation 
detail, which can be adjusted.
According to my understanding, today LLVM IR for SPIR-V target just follows 
SPIR target nomenclature.

I'd like Eli/John to give formal approval for this change, but I'm okay with 
it.  Thanks!

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


[clang] [OpenACC] Implement 'if' clause for Compute Constructs (PR #88411)

2024-04-12 Thread Erich Keane via cfe-commits

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


[clang] daa8836 - [OpenACC] Implement 'if' clause for Compute Constructs (#88411)

2024-04-12 Thread via cfe-commits

Author: Erich Keane
Date: 2024-04-12T14:13:31-07:00
New Revision: daa88364df15683bfa0e58d62cc96d33cd49d34b

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

LOG: [OpenACC] Implement 'if' clause for Compute Constructs (#88411)

Like with the 'default' clause, this is being applied to only Compute
Constructs for now. The 'if' clause takes a condition expression which
is used as a runtime value.

This is not a particularly complex semantic implementation, as there
isn't much to this clause, other than its interactions with 'self',
  which will be managed in the patch to implement that.

Added: 
clang/include/clang/Basic/OpenACCClauses.def
clang/test/SemaOpenACC/compute-construct-if-clause.c
clang/test/SemaOpenACC/compute-construct-if-clause.cpp

Modified: 
clang/include/clang/AST/ASTNodeTraverser.h
clang/include/clang/AST/OpenACCClause.h
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/SemaOpenACC.h
clang/lib/AST/OpenACCClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/Parse/ParseOpenACC.cpp
clang/lib/Sema/SemaOpenACC.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/ParserOpenACC/parse-clauses.c
clang/test/SemaOpenACC/compute-construct-clause-ast.cpp
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index a6e3b05b005968..f5c47d8a7c2113 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -243,7 +243,8 @@ class ASTNodeTraverser
   void Visit(const OpenACCClause *C) {
 getNodeDelegate().AddChild([=] {
   getNodeDelegate().Visit(C);
-  // TODO OpenACC: Switch on clauses that have children, and add them.
+  for (const auto *S : C->children())
+Visit(S);
 });
   }
 

diff  --git a/clang/include/clang/AST/OpenACCClause.h 
b/clang/include/clang/AST/OpenACCClause.h
index 27e4e1a12c9837..712ad46c0f238d 100644
--- a/clang/include/clang/AST/OpenACCClause.h
+++ b/clang/include/clang/AST/OpenACCClause.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_AST_OPENACCCLAUSE_H
 #define LLVM_CLANG_AST_OPENACCCLAUSE_H
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/StmtIterator.h"
 #include "clang/Basic/OpenACCKinds.h"
 
 namespace clang {
@@ -34,6 +35,17 @@ class OpenACCClause {
 
   static bool classof(const OpenACCClause *) { return true; }
 
+  using child_iterator = StmtIterator;
+  using const_child_iterator = ConstStmtIterator;
+  using child_range = llvm::iterator_range;
+  using const_child_range = llvm::iterator_range;
+
+  child_range children();
+  const_child_range children() const {
+auto Children = const_cast(this)->children();
+return const_child_range(Children.begin(), Children.end());
+  }
+
   virtual ~OpenACCClause() = default;
 };
 
@@ -49,6 +61,13 @@ class OpenACCClauseWithParams : public OpenACCClause {
 
 public:
   SourceLocation getLParenLoc() const { return LParenLoc; }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+  const_child_range children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
 };
 
 /// A 'default' clause, has the optional 'none' or 'present' argument.
@@ -81,6 +100,51 @@ class OpenACCDefaultClause : public OpenACCClauseWithParams 
{
   SourceLocation EndLoc);
 };
 
+/// Represents one of the handful of classes that has an optional/required
+/// 'condition' expression as an argument.
+class OpenACCClauseWithCondition : public OpenACCClauseWithParams {
+  Expr *ConditionExpr = nullptr;
+
+protected:
+  OpenACCClauseWithCondition(OpenACCClauseKind K, SourceLocation BeginLoc,
+ SourceLocation LParenLoc, Expr *ConditionExpr,
+ SourceLocation EndLoc)
+  : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc),
+ConditionExpr(ConditionExpr) {}
+
+public:
+  bool hasConditionExpr() const { return ConditionExpr; }
+  const Expr *getConditionExpr() const { return ConditionExpr; }
+  Expr *getConditionExpr() { return ConditionExpr; }
+
+  child_range children() {
+if (ConditionExpr)
+  return child_range(reinterpret_cast(),
+ reinterpret_cast( + 1));
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+if (ConditionExpr)
+  return const_child_range(
+  reinterpret_cast(),
+  reinterpret_cast( + 1));
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+};
+
+/// An 

[clang] [libc] [llvm] Fix typos (PR #88565)

2024-04-12 Thread Victor Toni via cfe-commits

ViToni wrote:

@nickdesaulniers Please. I wouldn't assume to have any permissions in this repo.

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


[clang] [clang][modules] Headers meant to be included multiple times can be completely invisible in clang module builds (PR #83660)

2024-04-12 Thread James Y Knight via cfe-commits

jyknight wrote:

I think the bug this change was attempting to fix is actually the same as 
#38554 and related bugs -- which, it appears, was not really fixed.

The underlying problem here is that `#pragma once` should should work 
identically to ifndef guards, as far as what macros/decls are made visible to 
the includer. However, with the current modules implementation, it fails to do 
so. This PR addresses only one _symptom_ of that issue, but does not address 
the underlying problem.

Additionally, I think the semantics change implemented here is a bad idea. It 
significantly complicates the semantics of `#import`, in a way that I think is 
justifiable, especially given that there is a way to fix the identified issue 
in a more principled way.

Yes, `#import` was a bad and confusing idea, and should have been dropped 20 
years ago, but adding more special cases to it does not make it better. A 
header file being marked "textual" in a module-map does _not_ mean a file 
should be be included multiple times -- it simply means that you didn't want to 
build it into a module. Linking these two concepts together ties together 
concepts which have no 

If this PR was the only way to fix the identified issue, maybe it could via an 
assumption that the current buggy `#pragma once` behavior is expected behavior 
which should be preserved.

As such, I would propose this PR ought to be reverted, and work to fix the 
underlying issue be done instead.

Here's a test case which I think demonstrates the actual bug -- it fails both 
before and after this PR. If you modify 'header.h' to use include guards, then 
it passes. This difference in behavior should not exist.
```
// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: %clang_cc1 -std=c17 -fmodules-cache-path=%t/no-lsv -fmodules 
-fimplicit-module-maps -I%t %t/pragma-once-modules.c -verify
// RUN: %clang_cc1 -std=c17 -fmodules-cache-path=%t/lsv -fmodules 
-fimplicit-module-maps -fmodules-local-submodule-visibility -I%t 
%t/pragma-once-modules.c -verify

//--- pragma-once-modules.c
// expected-no-diagnostics
#include "one.h"
#include "header.h"
my_int test(void) {
  return MY_MACRO;
}

//--- module.modulemap
module Submodules {
  module one {
header "one.h"
export *
  }
  module two {
header "two.h"
export *
  }
}

//--- one.h
#ifndef one_h
#define one_h
#endif

//--- two.h
#ifndef two_h
#define two_h
#include "header.h"
#endif

//--- header.h
#pragma once
#define MY_MACRO 5
typedef int my_int;
```

It produces the following unexpected output.
```
error: 'expected-error' diagnostics seen but not expected: 
  [...]/pragma-once-modules.c Line 4: missing '#include "header.h"'; 'my_int' 
must be declared before it is used
  [...]/pragma-once-modules.c Line 5: use of undeclared identifier 'MY_MACRO'
error: 'expected-note' diagnostics seen but not expected: 
  [...]/header.h Line 3: declaration here is not visible
```

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


[clang] [modules] allow use of ptrauth module from no_undeclared_includes system modules (PR #88432)

2024-04-12 Thread Juergen Ributzka via cfe-commits

https://github.com/ributzka approved this pull request.


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


[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-12 Thread Artem Chikin via cfe-commits

artemcm wrote:

> Clang test now looks good to me. Might be nice to drop 
> `InstrumentingInMemoryFilesystem` in favor of the existing 
> `InstrumentingFilesystem` (that I added just moments ago, sorry!) wrapped 
> around a normal `InMemoryFileSystem`, but I'm happy to do that myself in a 
> follow-up commit.

I had to update the commit anyway. Unified on `InstrumentingFilesystem`. 

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


[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-12 Thread Artem Chikin via cfe-commits

https://github.com/artemcm updated 
https://github.com/llvm/llvm-project/pull/88152

>From 8164aaf2e93dde4761789e6d574088d1cb0e97fc Mon Sep 17 00:00:00 2001
From: Artem Chikin 
Date: Tue, 9 Apr 2024 09:37:09 -0700
Subject: [PATCH] [clang][deps] Overload 'Filesystem::exists' in
 'DependencyScanningFilesystem' to have it use cached `status`

As-is, calls to `exists()` fallback on the implementation in 
'ProxyFileSystem::exists' which explicitly calls out to the underlying `FS`, 
which for the 'DependencyScanningFilesystem' (overlay) is the real underlying 
filesystem.

Instead, directly overloading 'exists' allows us to have it rely on the cached 
`status` behavior used elsewhere by the 'DependencyScanningFilesystem'.
---
 .../DependencyScanningFilesystem.h|   4 +
 .../DependencyScanningFilesystem.cpp  |  11 ++
 .../DependencyScanningFilesystemTest.cpp  |  53 +--
 .../Support/VirtualFileSystemTest.cpp | 140 +-
 4 files changed, 125 insertions(+), 83 deletions(-)

diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index 8b6f149c7cb266..f7b4510d7f7beb 100644
--- 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -365,6 +365,10 @@ class DependencyScanningWorkerFilesystem
   /// false if not (i.e. this entry is not a file or its scan fails).
   bool ensureDirectiveTokensArePopulated(EntryRef Entry);
 
+  /// Check whether \p Path exists. By default checks cached result of \c
+  /// status(), and falls back on FS if unable to do so.
+  bool exists(const Twine ) override;
+
 private:
   /// For a filename that's not yet associated with any entry in the caches,
   /// uses the underlying filesystem to either look up the entry based in the
diff --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 84185c931b552c..0cab17a3424406 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -300,6 +300,17 @@ DependencyScanningWorkerFilesystem::status(const Twine 
) {
   return Result->getStatus();
 }
 
+bool DependencyScanningWorkerFilesystem::exists(const Twine ) {
+  // While some VFS overlay filesystems may implement more-efficient
+  // mechanisms for `exists` queries, `DependencyScanningWorkerFilesystem`
+  // typically wraps `RealFileSystem` which does not specialize `exists`,
+  // so it is not likely to benefit from such optimizations. Instead,
+  // it is more-valuable to have this query go through the
+  // cached-`status` code-path of the `DependencyScanningWorkerFilesystem`.
+  llvm::ErrorOr Status = status(Path);
+  return Status && Status->exists();
+}
+
 namespace {
 
 /// The VFS that is used by clang consumes the \c CachedFileSystemEntry using
diff --git 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
index 697b7d70ff035a..256dd980b2118f 100644
--- 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
+++ 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "gtest/gtest.h"
 
@@ -15,31 +16,36 @@ using namespace clang::tooling::dependencies;
 
 namespace {
 struct InstrumentingFilesystem
-: llvm::RTTIExtends {
+: llvm::RTTIExtends {
   unsigned NumStatusCalls = 0;
   unsigned NumGetRealPathCalls = 0;
+  unsigned NumExistsCalls = 0;
 
   using llvm::RTTIExtends::RTTIExtends;
+  llvm::vfs::InMemoryFileSystem>::RTTIExtends;
 
   llvm::ErrorOr status(const llvm::Twine ) override {
 ++NumStatusCalls;
-return ProxyFileSystem::status(Path);
+return InMemoryFileSystem::status(Path);
   }
 
   std::error_code getRealPath(const llvm::Twine ,
   llvm::SmallVectorImpl ) override {
 ++NumGetRealPathCalls;
-return ProxyFileSystem::getRealPath(Path, Output);
+return InMemoryFileSystem::getRealPath(Path, Output);
+  }
+
+  bool exists(const llvm::Twine ) override {
+++NumExistsCalls;
+return InMemoryFileSystem::exists(Path);
   }
 };
+
 } // namespace
 
 TEST(DependencyScanningWorkerFilesystem, CacheStatusFailures) {
-  auto InMemoryFS = llvm::makeIntrusiveRefCnt();
-
   auto InstrumentingFS =
-  llvm::makeIntrusiveRefCnt(InMemoryFS);
+  llvm::makeIntrusiveRefCnt();
 
   DependencyScanningFilesystemSharedCache SharedCache;
   

[clang] [clang] Introduce `SemaCUDA` (PR #88559)

2024-04-12 Thread Artem Belevich via cfe-commits

https://github.com/Artem-B approved this pull request.

LGTM. The changes appear to be mechanical in nature, so `check clang` tests 
should be sufficient to verify we've re-connected things correctly.

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


[clang] [modules] allow use of ptrauth module from no_undeclared_includes system modules (PR #88432)

2024-04-12 Thread Ian Anderson via cfe-commits

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


[clang] allow use of ptrauth module from no_undeclared_includes system modules (PR #88432)

2024-04-12 Thread Ian Anderson via cfe-commits

ian-twilightcoder wrote:

Upstream from Apple, followup for 
https://github.com/llvm/llvm-project/pull/65996. Allows Apple's Darwin module 
to include ptrauth.h without declaring a `use`.

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


[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-12 Thread Artem Chikin via cfe-commits

https://github.com/artemcm updated 
https://github.com/llvm/llvm-project/pull/88152

>From e010a761a34692e5ca1959fc9022d0950e669664 Mon Sep 17 00:00:00 2001
From: Artem Chikin 
Date: Tue, 9 Apr 2024 09:37:09 -0700
Subject: [PATCH] [clang][deps] Overload 'Filesystem::exists' in
 'DependencyScanningFilesystem' to have it use cached `status`

As-is, calls to `exists()` fallback on the implementation in 
'ProxyFileSystem::exists' which explicitly calls out to the underlying `FS`, 
which for the 'DependencyScanningFilesystem' (overlay) is the real underlying 
filesystem.

Instead, directly overloading 'exists' allows us to have it rely on the cached 
`status` behavior used elsewhere by the 'DependencyScanningFilesystem'.
---
 .../DependencyScanningFilesystem.h|   4 +
 .../DependencyScanningFilesystem.cpp  |  11 ++
 .../DependencyScanningFilesystemTest.cpp  |  45 ++
 .../Support/VirtualFileSystemTest.cpp | 140 +-
 4 files changed, 130 insertions(+), 70 deletions(-)

diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index 8b6f149c7cb266..f7b4510d7f7beb 100644
--- 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -365,6 +365,10 @@ class DependencyScanningWorkerFilesystem
   /// false if not (i.e. this entry is not a file or its scan fails).
   bool ensureDirectiveTokensArePopulated(EntryRef Entry);
 
+  /// Check whether \p Path exists. By default checks cached result of \c
+  /// status(), and falls back on FS if unable to do so.
+  bool exists(const Twine ) override;
+
 private:
   /// For a filename that's not yet associated with any entry in the caches,
   /// uses the underlying filesystem to either look up the entry based in the
diff --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 84185c931b552c..0cab17a3424406 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -300,6 +300,17 @@ DependencyScanningWorkerFilesystem::status(const Twine 
) {
   return Result->getStatus();
 }
 
+bool DependencyScanningWorkerFilesystem::exists(const Twine ) {
+  // While some VFS overlay filesystems may implement more-efficient
+  // mechanisms for `exists` queries, `DependencyScanningWorkerFilesystem`
+  // typically wraps `RealFileSystem` which does not specialize `exists`,
+  // so it is not likely to benefit from such optimizations. Instead,
+  // it is more-valuable to have this query go through the
+  // cached-`status` code-path of the `DependencyScanningWorkerFilesystem`.
+  llvm::ErrorOr Status = status(Path);
+  return Status && Status->exists();
+}
+
 namespace {
 
 /// The VFS that is used by clang consumes the \c CachedFileSystemEntry using
diff --git 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
index 697b7d70ff035a..ccc02b7b2f09dd 100644
--- 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
+++ 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "gtest/gtest.h"
 
@@ -33,6 +34,27 @@ struct InstrumentingFilesystem
 return ProxyFileSystem::getRealPath(Path, Output);
   }
 };
+
+struct InstrumentingInMemoryFilesystem
+: llvm::RTTIExtends {
+  unsigned NumStatCalls = 0;
+  unsigned NumExistsCalls = 0;
+
+  using llvm::RTTIExtends::RTTIExtends;
+
+  llvm::ErrorOr status(const llvm::Twine ) override {
+++NumStatCalls;
+return InMemoryFileSystem::status(Path);
+  }
+
+  bool exists(const llvm::Twine ) override {
+++NumExistsCalls;
+return InMemoryFileSystem::exists(Path);
+  }
+};
+
 } // namespace
 
 TEST(DependencyScanningWorkerFilesystem, CacheStatusFailures) {
@@ -147,3 +169,26 @@ TEST(DependencyScanningFilesystem, 
RealPathAndStatusInvariants) {
 DepFS.status("/bar");
   }
 }
+
+TEST(DependencyScanningFilesystem, CacheStatOnExists) {
+  auto InMemoryInstrumentingFS =
+  llvm::makeIntrusiveRefCnt();
+  InMemoryInstrumentingFS->setCurrentWorkingDirectory("/");
+  InMemoryInstrumentingFS->addFile("/foo", 0,
+   llvm::MemoryBuffer::getMemBuffer(""));
+  InMemoryInstrumentingFS->addFile("/bar", 0,
+   llvm::MemoryBuffer::getMemBuffer(""));
+  DependencyScanningFilesystemSharedCache SharedCache;
+  DependencyScanningWorkerFilesystem 

[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-12 Thread Jan Svoboda via cfe-commits

jansvoboda11 wrote:

Clang test now looks good to me. Might be nice to drop 
`InstrumentingInMemoryFilesystem` in favor of the existing 
`InstrumentingFilesystem` (that I added just moments ago, sorry!) wrapped 
around a normal `InMemoryFileSystem`, but I'm happy to do that myself in a 
follow-up commit.

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


[clang] allow use of ptrauth module from no_undeclared_includes system modules (PR #88432)

2024-04-12 Thread Ian Anderson via cfe-commits

https://github.com/ian-twilightcoder updated 
https://github.com/llvm/llvm-project/pull/88432

>From 88da8be7ed10f1ee8e7e992fdd59dce52456b2ce Mon Sep 17 00:00:00 2001
From: Alex Lorenz 
Date: Thu, 9 Jul 2020 15:10:49 -0700
Subject: [PATCH] [modules] allow use of ptrauth module from
 no_undeclared_includes system modules

---
 clang/lib/Basic/Module.cpp| 4 
 .../Inputs/ptrauth-include-from-darwin/module.modulemap   | 8 
 .../Modules/Inputs/ptrauth-include-from-darwin/ptrauth.h  | 1 +
 .../Modules/Inputs/ptrauth-include-from-darwin/stddef.h   | 1 +
 clang/test/Modules/ptrauth-include-from-darwin.m  | 6 ++
 5 files changed, 20 insertions(+)
 create mode 100644 
clang/test/Modules/Inputs/ptrauth-include-from-darwin/module.modulemap
 create mode 100644 
clang/test/Modules/Inputs/ptrauth-include-from-darwin/ptrauth.h
 create mode 100644 
clang/test/Modules/Inputs/ptrauth-include-from-darwin/stddef.h
 create mode 100644 clang/test/Modules/ptrauth-include-from-darwin.m

diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 256365d66bb907..bb212cde878826 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -305,6 +305,10 @@ bool Module::directlyUses(const Module *Requested) {
   if (Requested->fullModuleNameIs({"_Builtin_stddef", "max_align_t"}) ||
   Requested->fullModuleNameIs({"_Builtin_stddef_wint_t"}))
 return true;
+  // Darwin is allowed is to use our builtin 'ptrauth.h' and its accompanying
+  // module.
+  if (!Requested->Parent && Requested->Name == "ptrauth")
+return true;
 
   if (NoUndeclaredIncludes)
 UndeclaredUses.insert(Requested);
diff --git 
a/clang/test/Modules/Inputs/ptrauth-include-from-darwin/module.modulemap 
b/clang/test/Modules/Inputs/ptrauth-include-from-darwin/module.modulemap
new file mode 100644
index 00..741b9bb1efc54d
--- /dev/null
+++ b/clang/test/Modules/Inputs/ptrauth-include-from-darwin/module.modulemap
@@ -0,0 +1,8 @@
+module libc [no_undeclared_includes] {
+  module stddef { header "stddef.h" export * }
+}
+
+module ptrauth {
+  header "ptrauth.h"
+  export *
+}
diff --git a/clang/test/Modules/Inputs/ptrauth-include-from-darwin/ptrauth.h 
b/clang/test/Modules/Inputs/ptrauth-include-from-darwin/ptrauth.h
new file mode 100644
index 00..c8620b64b2ceef
--- /dev/null
+++ b/clang/test/Modules/Inputs/ptrauth-include-from-darwin/ptrauth.h
@@ -0,0 +1 @@
+void foo();
diff --git a/clang/test/Modules/Inputs/ptrauth-include-from-darwin/stddef.h 
b/clang/test/Modules/Inputs/ptrauth-include-from-darwin/stddef.h
new file mode 100644
index 00..777a524fc67110
--- /dev/null
+++ b/clang/test/Modules/Inputs/ptrauth-include-from-darwin/stddef.h
@@ -0,0 +1 @@
+@import ptrauth;
diff --git a/clang/test/Modules/ptrauth-include-from-darwin.m 
b/clang/test/Modules/ptrauth-include-from-darwin.m
new file mode 100644
index 00..72b0c36e7cb7d3
--- /dev/null
+++ b/clang/test/Modules/ptrauth-include-from-darwin.m
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I 
%S/Inputs/ptrauth-include-from-darwin %s -verify
+// expected-no-diagnostics
+
+@import libc;
+void bar() { foo(); }

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


[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-12 Thread Jan Svoboda via cfe-commits




jansvoboda11 wrote:

I assume clang-format was overly eager with this one, as these are just 
whitespace changes. Can we undo that?

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


[clang] Reapply "[Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (#87541)" (PR #88311)

2024-04-12 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

@rupprecht looks like the issue is with non-static members in base classes:
```cpp
struct B
{
int z;
void h(int);
};

template 
struct A : B
{
int y;
void g(int);

template
void f(U); 

template<>
void f(int x)
{
x;
y;
z; // error: reference to overloaded function could not be resolved
g(x);
g(y);
g(z);
g(0);
h(x); // error: call to non-static member function without an object 
argument
h(y);
h(z); // error: no matching function for call to 'h'
h(0); // error: call to non-static member function without an object 
argument
}
};

template struct A; 
```
I'll look into this and see whether it's a trivial fix. If not, I'll revert.

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


[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-12 Thread Artem Chikin via cfe-commits

https://github.com/artemcm updated 
https://github.com/llvm/llvm-project/pull/88152

>From 24e869df273b9d75bb4fdf85f4ee8ab2ddbccc2c Mon Sep 17 00:00:00 2001
From: Artem Chikin 
Date: Tue, 9 Apr 2024 09:37:09 -0700
Subject: [PATCH] [clang][deps] Overload 'Filesystem::exists' in
 'DependencyScanningFilesystem' to have it use cached `status`

As-is, calls to `exists()` fallback on the implementation in 
'ProxyFileSystem::exists' which explicitly calls out to the underlying `FS`, 
which for the 'DependencyScanningFilesystem' (overlay) is the real underlying 
filesystem.

Instead, directly overloading 'exists' allows us to have it rely on the cached 
`status` behavior used elsewhere by the 'DependencyScanningFilesystem'.
---
 .../DependencyScanningFilesystem.h|   4 +
 .../DependencyScanningFilesystem.cpp  |  11 ++
 .../DependencyScanningFilesystemTest.cpp  |  46 ++
 .../Support/VirtualFileSystemTest.cpp | 140 +-
 4 files changed, 131 insertions(+), 70 deletions(-)

diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index 8b6f149c7cb266..f7b4510d7f7beb 100644
--- 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -365,6 +365,10 @@ class DependencyScanningWorkerFilesystem
   /// false if not (i.e. this entry is not a file or its scan fails).
   bool ensureDirectiveTokensArePopulated(EntryRef Entry);
 
+  /// Check whether \p Path exists. By default checks cached result of \c
+  /// status(), and falls back on FS if unable to do so.
+  bool exists(const Twine ) override;
+
 private:
   /// For a filename that's not yet associated with any entry in the caches,
   /// uses the underlying filesystem to either look up the entry based in the
diff --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 84185c931b552c..0cab17a3424406 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -300,6 +300,17 @@ DependencyScanningWorkerFilesystem::status(const Twine 
) {
   return Result->getStatus();
 }
 
+bool DependencyScanningWorkerFilesystem::exists(const Twine ) {
+  // While some VFS overlay filesystems may implement more-efficient
+  // mechanisms for `exists` queries, `DependencyScanningWorkerFilesystem`
+  // typically wraps `RealFileSystem` which does not specialize `exists`,
+  // so it is not likely to benefit from such optimizations. Instead,
+  // it is more-valuable to have this query go through the
+  // cached-`status` code-path of the `DependencyScanningWorkerFilesystem`.
+  llvm::ErrorOr Status = status(Path);
+  return Status && Status->exists();
+}
+
 namespace {
 
 /// The VFS that is used by clang consumes the \c CachedFileSystemEntry using
diff --git 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
index 697b7d70ff035a..67f9ee1a3f97ce 100644
--- 
a/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
+++ 
b/clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "gtest/gtest.h"
 
@@ -33,6 +34,28 @@ struct InstrumentingFilesystem
 return ProxyFileSystem::getRealPath(Path, Output);
   }
 };
+
+
+struct InstrumentingInMemoryFilesystem
+: llvm::RTTIExtends {
+  unsigned NumStatCalls = 0;
+  unsigned NumExistsCalls = 0;
+
+  using llvm::RTTIExtends::RTTIExtends;
+
+  llvm::ErrorOr status(const llvm::Twine ) override {
+++NumStatCalls;
+return InMemoryFileSystem::status(Path);
+  }
+
+  bool exists(const llvm::Twine ) override {
+++NumExistsCalls;
+return InMemoryFileSystem::exists(Path);
+  }
+};
+
 } // namespace
 
 TEST(DependencyScanningWorkerFilesystem, CacheStatusFailures) {
@@ -147,3 +170,26 @@ TEST(DependencyScanningFilesystem, 
RealPathAndStatusInvariants) {
 DepFS.status("/bar");
   }
 }
+
+TEST(DependencyScanningFilesystem, CacheStatOnExists) {
+  auto InMemoryInstrumentingFS =
+  llvm::makeIntrusiveRefCnt();
+  InMemoryInstrumentingFS->setCurrentWorkingDirectory("/");
+  InMemoryInstrumentingFS->addFile("/foo", 0,
+   llvm::MemoryBuffer::getMemBuffer(""));
+  InMemoryInstrumentingFS->addFile("/bar", 0,
+   llvm::MemoryBuffer::getMemBuffer(""));
+  DependencyScanningFilesystemSharedCache SharedCache;
+  

[clang] [clang][CodeGen] Add AS for Globals to SPIR & SPIRV datalayouts (PR #88455)

2024-04-12 Thread Alex Voicu via cfe-commits

AlexVlx wrote:

> The change seems reasonable.
> 
> > CodeGen/LLVM will default to AS0 in this case, which produces Globals that 
> > end up in the private address space for e.g. OCL, HIPSPV or SYCL.
> 
> Can we add a test checking LLVM address space for globals emitted from 
> OCL/HIPSPV/SYCL, please? It's surprising that we need to modify only a 
> datalayout string check.

I can add another one here, but there's a bunch of them coming in #88182, which 
roundabout motivated this change. I'll emphasise that this is only a problem 
for things such as implicitly generated globals (e.g. VTables or typeinfo for 
classes etc.), so it's just a subset of all globals that are impacted (there 
are already some tests covering direct usage AFAICS).

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


[clang] [libc] [llvm] Fix typos (PR #88565)

2024-04-12 Thread Nick Desaulniers via cfe-commits

nickdesaulniers wrote:

Thanks for the patch. Do you need one of us to merge this for you?

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


[clang] [libc] [llvm] Fix typos (PR #88565)

2024-04-12 Thread Nick Desaulniers via cfe-commits

https://github.com/nickdesaulniers approved this pull request.


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


[clang] [llvm] [Clang] Emit DW_TAG_template_alias for template aliases (PR #87623)

2024-04-12 Thread David Blaikie via cfe-commits

dwblaikie wrote:

> > I'm a little uncomfortable with adding a new user-facing option for 
> > template aliases. Even with that in place, we should not warn and refuse to 
> > do what the user asked for, based on DWARF version. -gdwarf-2 -gsplit-dwarf 
> > generates a .dwo file claiming to be v2, for example.
> 
> I don't have strong feelings about the flag setup and am happy to change it. 
> @dwblaikie mentioned that we might not want to have the debugger tuning be 
> the only way of controlling whether or not we emit this DIE, so adding 
> `-gtemplate-alias` which has its default set based on debugger tuning seemed 
> like a reasonable way of doing it. What would be the best way of controlling 
> this feature in your opinion (bearing in mind that GCC doesn't emit it, and 
> GDB and LLDB don't the DIE)?

@pogo59 Hmm - I thought you held a strong preference that debugger tuning never 
be the only way to access a certain feature, and that we should always have 
direct control of these features via flags (but with default (or explicit) 
debugger tuning setting some of these flag defaults based on the preferred 
content for that debugger). Perhaps i'm misremembering?

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


[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-12 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.


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


[clang] [clang][CodeGen] Add AS for Globals to SPIR & SPIRV datalayouts (PR #88455)

2024-04-12 Thread Alexey Bader via cfe-commits

bader wrote:

The change seems reasonable.

> CodeGen/LLVM will default to AS0 in this case, which produces Globals that 
> end up in the private address space for e.g. OCL, HIPSPV or SYCL.

Can we add a test checking LLVM address space for globals emitted from 
OCL/HIPSPV/SYCL, please? It's surprising that we need to modify only a 
datalayout string check.

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


  1   2   3   4   >