[PATCH] D152924: [libLTO][AIX] Respect `-f[no]-integrated-as` on AIX

2023-06-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:700
+CmdArgs.push_back(Args.MakeArgString(
+Twine(PluginOptPrefix) + "-no-integrated-as=" + NoIntegratedAs));
+  else if (!UseIntegratedAs) {

shchenz wrote:
> qiongsiwu1 wrote:
> > shchenz wrote:
> > > qiongsiwu1 wrote:
> > > > shchenz wrote:
> > > > > Seems other options leverage the default value in the back end, for 
> > > > > example the default value for `DisableIntegratedAS` in backend is 
> > > > > false, so when the front end requires integrated-as, maybe we can 
> > > > > save the option here?
> > > > Ah thanks for the comment! 
> > > > 
> > > > > maybe we can save the option here?
> > > > 
> > > > Could you help me understand what we mean by "the option"? Do we mean 
> > > > saving (or using?) the value of `-f[no]-integrated-as` explicitly here 
> > > > somehow instead of relying on `ToolChain.useIntegratedAs()`? How do we 
> > > > intend to use the saved option value? My understanding is that 
> > > > `DisableIntegratedAS` takes its value from the option 
> > > > `-no-integrated-as` if `-no-integrated-as` is specified. As pointed out 
> > > > eariler, `DisableIntegratedAS` is false by default. This code 
> > > > explicitly sets `-no-integrated-as` to `0` or `1`, so for the LTO use 
> > > > case, we overwrite the back end default since the option is always 
> > > > present. 
> > > For example, if front-end requires to use integrated-assembler which is 
> > > same with back-end's default value, we don't need to pass 
> > > `-no-integrated-as=0`? We only pass the option `-no-integrated-as=1` when 
> > > `if (IsOSAIX && !UseIntegratedAs)`.
> > Ah I see! Thanks for the clarification! 
> > 
> > @w2yehia and I discussed this and we preferred setting the option 
> > explicitly regardless of the backend's default. The reason was that we did 
> > not want to leave a hanging case where the option was not passed to the 
> > backend, a case in which we would rely on a non-local 
> > option(`DisableIntegratedAS`)'s default value to control the backend. In 
> > other words, always passing in the option allowed us to reason about this 
> > code locally within this file. @w2yehia feel free to chime in if I am not 
> > describing our discussion correctly. 
> > 
> > Could you help me understand the benefit of not passing in the option for 
> > the default case? 
> > Could you help me understand the benefit of not passing in the option for 
> > the default case?
> 
> Too many options pass from front-end to back-end is a reason. And another 
> reason is: I met one case that there is a back-end option has no default 
> value, so each front-end, like clang and FORTRAN will have to explicitly pass 
> the same option. I was asked to set a default in the back-end, so no need to 
> explicitly set the options in each front-end.
> 
> If what I read is right, some bool type options like `EmulatedTLS`, 
> `EnableStackSizeSection` are only passed when their values are not the same 
> with the back-end's default.
> 
> I am ok to keep it as now if you guys already have an agreement. This is just 
> minor I think.
If you are going to add `-no-integrated-as=0`, I suggest that you rename the 
option to `-integrated-as` and use `-integrated-as=1` instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152924

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


[PATCH] D152924: [libLTO][AIX] Respect `-f[no]-integrated-as` on AIX

2023-06-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:703
+Arg *A = Args.getLastArgNoClaim(options::OPT_fno_integrated_as);
+D.Diag(diag::warn_drv_unsupported_lto_option_for_target)
+<< A->getSpelling() << ToolChain.getTriple().getTriple();

The patch is titled AIX but this would change the Linux behavior. In my 
experience this diagnostic is not useful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152924

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


[clang] ce8ff3f - Remove clang/ModuleInfo.txt

2023-06-16 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-06-16T09:11:11+02:00
New Revision: ce8ff3facc637ae116f0d1c560a602b4dc939deb

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

LOG: Remove clang/ModuleInfo.txt

The script build-for-llvm-top.sh and LLVM's ModuleInfo.txt are gone
since a long time (commit d20ea7dc59 in November 2011), and llvm-top
itself has even been removed from llvm-archive (it can be found here:
https://github.com/llvm/llvm-archive/tree/cab7f8f160f0bd8d20d9a4036aa4083f2bc2740a/llvm-top
) so delete Clang's ModuleInfo.txt as well.

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

Added: 


Modified: 


Removed: 
clang/ModuleInfo.txt



diff  --git a/clang/ModuleInfo.txt b/clang/ModuleInfo.txt
deleted file mode 100644
index 4368ef067aead..0
--- a/clang/ModuleInfo.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-# This file provides information for llvm-top
-DepModule: llvm 
-ConfigCmd:
-ConfigTest:
-BuildCmd:



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


[PATCH] D152995: Remove clang/ModuleInfo.txt

2023-06-16 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGce8ff3facc63: Remove clang/ModuleInfo.txt (authored by 
Hahnfeld).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152995

Files:
  clang/ModuleInfo.txt


Index: clang/ModuleInfo.txt
===
--- clang/ModuleInfo.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-# This file provides information for llvm-top
-DepModule: llvm 
-ConfigCmd:
-ConfigTest:
-BuildCmd:


Index: clang/ModuleInfo.txt
===
--- clang/ModuleInfo.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-# This file provides information for llvm-top
-DepModule: llvm 
-ConfigCmd:
-ConfigTest:
-BuildCmd:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152645: [clangd] Handle DependentNameType in HeuristicResolver::resolveTypeToRecordDecl()

2023-06-16 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 532008.
nridge marked 2 inline comments as done.
nridge added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152645

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

Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -877,6 +877,22 @@
 }
   )cpp";
   EXPECT_DECLS("CXXDependentScopeMemberExpr", "void find()");
+
+  Code = R"cpp(
+template 
+struct Waldo {
+  void find();
+};
+template 
+struct MetaWaldo {
+  using Type = Waldo;
+};
+template 
+void foo(typename MetaWaldo::Type w) {
+  w.[[find]]();
+}
+  )cpp";
+  EXPECT_DECLS("CXXDependentScopeMemberExpr", "void find()");
 }
 
 TEST_F(TargetDeclTest, DependentTypes) {
Index: clang-tools-extra/clangd/HeuristicResolver.h
===
--- clang-tools-extra/clangd/HeuristicResolver.h
+++ clang-tools-extra/clangd/HeuristicResolver.h
@@ -94,6 +94,11 @@
   // `E`.
   const Type *resolveExprToType(const Expr *E) const;
   std::vector resolveExprToDecls(const Expr *E) const;
+
+  // Helper function for HeuristicResolver::resolveDependentMember()
+  // which takes a possibly-dependent type `T` and heuristically
+  // resolves it to a CXXRecordDecl in which we can try name lookup.
+  CXXRecordDecl *resolveTypeToRecordDecl(const Type *T) const;
 };
 
 } // namespace clangd
Index: clang-tools-extra/clangd/HeuristicResolver.cpp
===
--- clang-tools-extra/clangd/HeuristicResolver.cpp
+++ clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/Type.h"
 
 namespace clang {
 namespace clangd {
@@ -29,15 +30,35 @@
   return isa(D);
 };
 
+const Type *resolveDeclsToType(const std::vector &Decls,
+   ASTContext &Ctx) {
+  if (Decls.size() != 1) // Names an overload set -- just bail.
+return nullptr;
+  if (const auto *TD = dyn_cast(Decls[0])) {
+return Ctx.getTypeDeclType(TD).getTypePtr();
+  }
+  if (const auto *VD = dyn_cast(Decls[0])) {
+return VD->getType().getTypePtrOrNull();
+  }
+  return nullptr;
+}
+
 // Helper function for HeuristicResolver::resolveDependentMember()
 // which takes a possibly-dependent type `T` and heuristically
 // resolves it to a CXXRecordDecl in which we can try name lookup.
-CXXRecordDecl *resolveTypeToRecordDecl(const Type *T) {
+CXXRecordDecl *HeuristicResolver::resolveTypeToRecordDecl(const Type *T) const {
   assert(T);
 
   // Unwrap type sugar such as type aliases.
   T = T->getCanonicalTypeInternal().getTypePtr();
 
+  if (const auto *DNT = T->getAs()) {
+T = resolveDeclsToType(resolveDependentNameType(DNT), Ctx);
+if (!T)
+  return nullptr;
+T = T->getCanonicalTypeInternal().getTypePtr();
+  }
+
   if (const auto *RT = T->getAs())
 return dyn_cast(RT->getDecl());
 
@@ -185,18 +206,6 @@
   DTST->getIdentifier(), TemplateFilter);
 }
 
-const Type *resolveDeclsToType(const std::vector &Decls) {
-  if (Decls.size() != 1) // Names an overload set -- just bail.
-return nullptr;
-  if (const auto *TD = dyn_cast(Decls[0])) {
-return TD->getTypeForDecl();
-  }
-  if (const auto *VD = dyn_cast(Decls[0])) {
-return VD->getType().getTypePtrOrNull();
-  }
-  return nullptr;
-}
-
 std::vector
 HeuristicResolver::resolveExprToDecls(const Expr *E) const {
   if (const auto *ME = dyn_cast(E)) {
@@ -220,7 +229,7 @@
 const Type *HeuristicResolver::resolveExprToType(const Expr *E) const {
   std::vector Decls = resolveExprToDecls(E);
   if (!Decls.empty())
-return resolveDeclsToType(Decls);
+return resolveDeclsToType(Decls, Ctx);
 
   return E->getType().getTypePtr();
 }
@@ -239,9 +248,11 @@
   case NestedNameSpecifier::TypeSpecWithTemplate:
 return NNS->getAsType();
   case NestedNameSpecifier::Identifier: {
-return resolveDeclsToType(resolveDependentMember(
-resolveNestedNameSpecifierToType(NNS->getPrefix()),
-NNS->getAsIdentifier(), TypeFilter));
+return resolveDeclsToType(
+resolveDependentMember(
+resolveNestedNameSpecifierToType(NNS->getPrefix()),
+NNS->getAsIdentifier(), TypeFilter),
+Ctx);
   }
   default:
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152645: [clangd] Handle DependentNameType in HeuristicResolver::resolveTypeToRecordDecl()

2023-06-16 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/HeuristicResolver.cpp:56
+  if (const auto *DNT = T->getAs()) {
+T = resolveDeclsToType(resolveDependentNameType(DNT));
+if (!T)

hokein wrote:
> Is the `resolveDeclsToType` call necessary here?  
> The code path we're doing is `dependent-type => Decl* => Type => Decl*`, the 
> later two steps seems redundant, can we just use the Decl result from 
> `resolveDependentNameType()`?
> 
> 
The Decl returned by `resolveDependentNameType()` in this testcase is a 
`TypeAliasDecl`. The function needs to return the `CXXRecordDecl` which is 
named by the target type of the alias.

We could add logic to "desugar" the `TypeAliasDecl`, but it seems easier to 
reuse the existing logic that does the desugaring in type-land.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152645

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


[PATCH] D144457: [clang][Interp] Handle global composite temporaries

2023-06-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144457

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


[clang] 4d0cfa6 - [clang] Don't create import decls without -fmodules

2023-06-16 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-06-16T09:26:45+02:00
New Revision: 4d0cfa6d09e2a84cceb669949d72df58c031a8c5

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

LOG: [clang] Don't create import decls without -fmodules

When modules are disabled, there's no loaded module for these import
decls to point at. This results in crashes when there are modulemap
files but no -fmodules flag (this configuration is used for layering
check violations).

This patch makes sure import declarations are introduced only when
modules are enabled, which makes this case similar to textual headers
(no import decls are created for #include of textual headers from a
modulemap).

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

Added: 
clang/test/Modules/Inputs/modulemaps-nomodules/header.h
clang/test/Modules/Inputs/modulemaps-nomodules/module.modulemap
clang/test/Modules/modulemaps-nomodules.cpp
clang/test/PCH/Inputs/modulemaps-nomodules/header.h
clang/test/PCH/Inputs/modulemaps-nomodules/module.modulemap
clang/test/PCH/modulemaps-nomodules.cpp

Modified: 
clang/lib/Sema/SemaModule.cpp
clang/test/Modules/getSourceDescriptor-crash.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index 67c6556e00ddf..5ce5330b09466 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -636,11 +636,9 @@ void Sema::BuildModuleInclude(SourceLocation DirectiveLoc, 
Module *Mod) {
   TUKind == TU_Module &&
   getSourceManager().isWrittenInMainFile(DirectiveLoc);
 
-  bool ShouldAddImport = !IsInModuleIncludes;
-
-  // If this module import was due to an inclusion directive, create an
-  // implicit import declaration to capture it in the AST.
-  if (ShouldAddImport) {
+  // If we are really importing a module (not just checking layering) due to an
+  // #include in the main file, synthesize an ImportDecl.
+  if (getLangOpts().Modules && !IsInModuleIncludes) {
 TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl();
 ImportDecl *ImportD = ImportDecl::CreateImplicit(getASTContext(), TU,
  DirectiveLoc, Mod,

diff  --git a/clang/test/Modules/Inputs/modulemaps-nomodules/header.h 
b/clang/test/Modules/Inputs/modulemaps-nomodules/header.h
new file mode 100644
index 0..e69de29bb2d1d

diff  --git a/clang/test/Modules/Inputs/modulemaps-nomodules/module.modulemap 
b/clang/test/Modules/Inputs/modulemaps-nomodules/module.modulemap
new file mode 100644
index 0..dcae7e5a37c3a
--- /dev/null
+++ b/clang/test/Modules/Inputs/modulemaps-nomodules/module.modulemap
@@ -0,0 +1,3 @@
+module M {
+  private header "header.h"
+}

diff  --git a/clang/test/Modules/getSourceDescriptor-crash.cpp 
b/clang/test/Modules/getSourceDescriptor-crash.cpp
index 84e527aef91b5..53111786472f7 100644
--- a/clang/test/Modules/getSourceDescriptor-crash.cpp
+++ b/clang/test/Modules/getSourceDescriptor-crash.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -I %S/Inputs/getSourceDescriptor-crash -S -emit-llvm 
-debug-info-kind=limited -debugger-tuning=lldb -fimplicit-module-maps %s -o - | 
FileCheck %s
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -I %S/Inputs/getSourceDescriptor-crash -S -emit-llvm 
-debug-info-kind=limited -debugger-tuning=lldb -fmodules 
-fmodules-cache-path=%t -fimplicit-module-maps %s -o - | FileCheck %s
 
 #include "h1.h"
 #include "h1.h"

diff  --git a/clang/test/Modules/modulemaps-nomodules.cpp 
b/clang/test/Modules/modulemaps-nomodules.cpp
new file mode 100644
index 0..eec024fa24b47
--- /dev/null
+++ b/clang/test/Modules/modulemaps-nomodules.cpp
@@ -0,0 +1,8 @@
+// Make sure we treat includes that are part of modulemaps the same as textual
+// headers when modules are not enabled (e.g do't generate import decls, but
+// still perform layering checks).
+// No need to pass -fno-modules explicitly, absence implies negation for cc1.
+// RUN: %clang_cc1 -I %S/Inputs/modulemaps-nomodules 
-fmodule-map-file=%S/Inputs/modulemaps-nomodules/module.modulemap %s -verify 
-ast-dump | FileCheck %s
+
+#include "header.h" // expected-error{{use of private header from outside its 
module: 'header.h'}}
+// CHECK-NOT: ImportDecl

diff  --git a/clang/test/PCH/Inputs/modulemaps-nomodules/header.h 
b/clang/test/PCH/Inputs/modulemaps-nomodules/header.h
new file mode 100644
index 0..e69de29bb2d1d

diff  --git a/clang/test/PCH/Inputs/modulemaps-nomodules/module.modulemap 
b/clang/test/PCH/Inputs/modulemaps-nomodules/module.modulemap
new file mode 100644
index 0..15b101f4be60e
--- /dev/null
+++ b/clang/test/PCH/Inputs/modulemaps-nomodules/module.modulemap
@@ -0,0 +1,3 @@
+module M {
+  header "header.h"
+}

diff  --git a/clang/test/PCH/modulemaps-n

[PATCH] D152274: [clang] Don't create import decls without -fmodules

2023-06-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4d0cfa6d09e2: [clang] Don't create import decls without 
-fmodules (authored by kadircet).

Changed prior to commit:
  https://reviews.llvm.org/D152274?vs=528863&id=532012#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152274

Files:
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/Inputs/modulemaps-nomodules/header.h
  clang/test/Modules/Inputs/modulemaps-nomodules/module.modulemap
  clang/test/Modules/getSourceDescriptor-crash.cpp
  clang/test/Modules/modulemaps-nomodules.cpp
  clang/test/PCH/Inputs/modulemaps-nomodules/header.h
  clang/test/PCH/Inputs/modulemaps-nomodules/module.modulemap
  clang/test/PCH/modulemaps-nomodules.cpp


Index: clang/test/PCH/modulemaps-nomodules.cpp
===
--- /dev/null
+++ clang/test/PCH/modulemaps-nomodules.cpp
@@ -0,0 +1,6 @@
+// Make sure we don't crash when serializing a PCH with an include from a
+// modulemap file in nomodules mode.
+// No need to pass -fno-modules explicitly, absence implies negation for cc1.
+// RUN: %clang_cc1 -I %S/Inputs/modulemaps-nomodules 
-fmodule-map-file=%S/Inputs/modulemaps-nomodules/module.modulemap %s -emit-pch 
-o /dev/null
+
+#include "header.h"
Index: clang/test/PCH/Inputs/modulemaps-nomodules/module.modulemap
===
--- /dev/null
+++ clang/test/PCH/Inputs/modulemaps-nomodules/module.modulemap
@@ -0,0 +1,3 @@
+module M {
+  header "header.h"
+}
Index: clang/test/Modules/modulemaps-nomodules.cpp
===
--- /dev/null
+++ clang/test/Modules/modulemaps-nomodules.cpp
@@ -0,0 +1,8 @@
+// Make sure we treat includes that are part of modulemaps the same as textual
+// headers when modules are not enabled (e.g do't generate import decls, but
+// still perform layering checks).
+// No need to pass -fno-modules explicitly, absence implies negation for cc1.
+// RUN: %clang_cc1 -I %S/Inputs/modulemaps-nomodules 
-fmodule-map-file=%S/Inputs/modulemaps-nomodules/module.modulemap %s -verify 
-ast-dump | FileCheck %s
+
+#include "header.h" // expected-error{{use of private header from outside its 
module: 'header.h'}}
+// CHECK-NOT: ImportDecl
Index: clang/test/Modules/getSourceDescriptor-crash.cpp
===
--- clang/test/Modules/getSourceDescriptor-crash.cpp
+++ clang/test/Modules/getSourceDescriptor-crash.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -I %S/Inputs/getSourceDescriptor-crash -S -emit-llvm 
-debug-info-kind=limited -debugger-tuning=lldb -fimplicit-module-maps %s -o - | 
FileCheck %s
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -I %S/Inputs/getSourceDescriptor-crash -S -emit-llvm 
-debug-info-kind=limited -debugger-tuning=lldb -fmodules 
-fmodules-cache-path=%t -fimplicit-module-maps %s -o - | FileCheck %s
 
 #include "h1.h"
 #include "h1.h"
Index: clang/test/Modules/Inputs/modulemaps-nomodules/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/modulemaps-nomodules/module.modulemap
@@ -0,0 +1,3 @@
+module M {
+  private header "header.h"
+}
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -636,11 +636,9 @@
   TUKind == TU_Module &&
   getSourceManager().isWrittenInMainFile(DirectiveLoc);
 
-  bool ShouldAddImport = !IsInModuleIncludes;
-
-  // If this module import was due to an inclusion directive, create an
-  // implicit import declaration to capture it in the AST.
-  if (ShouldAddImport) {
+  // If we are really importing a module (not just checking layering) due to an
+  // #include in the main file, synthesize an ImportDecl.
+  if (getLangOpts().Modules && !IsInModuleIncludes) {
 TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl();
 ImportDecl *ImportD = ImportDecl::CreateImplicit(getASTContext(), TU,
  DirectiveLoc, Mod,


Index: clang/test/PCH/modulemaps-nomodules.cpp
===
--- /dev/null
+++ clang/test/PCH/modulemaps-nomodules.cpp
@@ -0,0 +1,6 @@
+// Make sure we don't crash when serializing a PCH with an include from a
+// modulemap file in nomodules mode.
+// No need to pass -fno-modules explicitly, absence implies negation for cc1.
+// RUN: %clang_cc1 -I %S/Inputs/modulemaps-nomodules -fmodule-map-file=%S/Inputs/modulemaps-nomodules/module.modulemap %s -emit-pch -o /dev/null
+
+#include "header.h"
Index: clang/test/PCH/Inputs/modulemaps-nomodules/module.modulemap
=

[PATCH] D153109: [clang-format][NFC] Clean up unit tests

2023-06-16 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, MyDeveloperDay.
owenpan requested review of this revision.

This patch adds a `verifyNoChange` macro to verify code that won't change after 
being formatted. (The code will not be messed up before being formatted.) It 
then replaces `EXPECT_EQ` with `verifyFormat` wherever applicable so that the 
code will be messed up before being formatted. When the replacement fails the 
unit test, `verifyFormat` is replaced with `verifyNoChange`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153109

Files:
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestBase.h
  clang/unittests/Format/FormatTestComments.cpp
  clang/unittests/Format/FormatTestJava.cpp
  clang/unittests/Format/QualifierFixerTest.cpp

Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -116,7 +116,7 @@
   Style.QualifierOrder = {"friend", "inline",   "constexpr", "static",
   "const",  "volatile", "type"};
 
-  verifyFormat("const volatile int a;", "const volatile int a;", Style);
+  verifyFormat("const volatile int a;", Style);
   verifyFormat("const volatile int a;", "volatile const int a;", Style);
   verifyFormat("const volatile int a;", "int const volatile a;", Style);
   verifyFormat("const volatile int a;", "int volatile const a;", Style);
@@ -240,7 +240,7 @@
   verifyFormat("int const *a;", "const int *a;", Style);
   verifyFormat("int const &a;", "const int &a;", Style);
   verifyFormat("foo(int const &a)", "foo(const int &a)", Style);
-  verifyFormat("unsigned char *a;", "unsigned char *a;", Style);
+  verifyFormat("unsigned char *a;", Style);
   verifyFormat("unsigned char const *a;", "const unsigned char *a;", Style);
   verifyFormat("vector args1",
"vector args1", Style);
@@ -283,7 +283,7 @@
Style);
 
   verifyFormat("static int const bat;", "static const int bat;", Style);
-  verifyFormat("static int const bat;", "static int const bat;", Style);
+  verifyFormat("static int const bat;", Style);
 
   // static is not configured, unchanged on the left of the right hand
   // qualifiers.
@@ -303,7 +303,7 @@
   verifyFormat("Foo inline static const;", "const Foo inline static;", Style);
   verifyFormat("Foo inline static const;", "Foo const inline static;", Style);
   verifyFormat("Foo inline static const;", "Foo inline const static;", Style);
-  verifyFormat("Foo inline static const;", "Foo inline static const;", Style);
+  verifyFormat("Foo inline static const;", Style);
 
   verifyFormat("Foo::Bar const volatile A::*;",
"volatile const Foo::Bar A::*;",
@@ -311,11 +311,9 @@
 
   verifyFormat("int const Foo::bat = 0;", "const int Foo::bat = 0;",
Style);
-  verifyFormat("int const Foo::bat = 0;", "int const Foo::bat = 0;",
-   Style);
+  verifyFormat("int const Foo::bat = 0;", Style);
   verifyFormat("void fn(Foo const &i);", "void fn(const Foo &i);", Style);
-  verifyFormat("int const Foo::fn() {", "int const Foo::fn() {",
-   Style);
+  verifyFormat("int const Foo::fn() {", Style);
   verifyFormat("Foo> const *p;", "const Foo> *p;", Style);
   verifyFormat(
   "Foo> const *p = const_cast> const *>(&ffi);",
@@ -384,36 +382,29 @@
Style);
 
   // Don't move past C-style struct/class.
-  verifyFormat("void foo(const struct A a);", "void foo(const struct A a);",
-   Style);
-  verifyFormat("void foo(const class A a);", "void foo(const class A a);",
-   Style);
+  verifyFormat("void foo(const struct A a);", Style);
+  verifyFormat("void foo(const class A a);", Style);
 
   // Don't move past struct/class combined declaration and variable
   // definition.
-  verifyFormat("const struct {\n} var;", "const struct {\n} var;", Style);
-  verifyFormat("struct {\n} const var;", "struct {\n} const var;", Style);
-  verifyFormat("const class {\n} var;", "const class {\n} var;", Style);
-  verifyFormat("class {\n} const var;", "class {\n} const var;", Style);
+  verifyFormat("const struct {\n} var;", Style);
+  verifyFormat("struct {\n} const var;", Style);
+  verifyFormat("const class {\n} var;", Style);
+  verifyFormat("class {\n} const var;", Style);
 
   // Leave left qualifers unchanged for combined declaration and variable
   // definition.
-  verifyFormat("volatile const class {\n} var;",
-   "volatile const class {\n} var;", Style);
-  verifyFormat("const volatile class {\n} var;",
-   "const volatile class {\n} var;", Style);
+  verifyFormat("volatile const class {\n} var;", Style);
+  verifyFormat("const volatile class {\n} var;", Style);
   // Also do no sorting with respect to not-config

[PATCH] D153111: [clang][Serialization][RISCV] Increase the number of reserved predefined type IDs

2023-06-16 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 created this revision.
rogfer01 added reviewers: eopXD, Eugene.Zelenko, craig.topper.
Herald added subscribers: jobnoorman, VincentWu, vkmr, luismarques, 
sameer.abuasal, s.egerton, Jim, benna, psnobl, PkmX, shiva0217, kito-cheng, 
simoncook, arichardson.
Herald added a project: All.
rogfer01 requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

In https://reviews.llvm.org/D152070 we added many new intrinsic types required 
for the RISC-V Vector Extension.

This was crashing when loading the AST as those types are intrinsically added 
to the AST (they don't come from the disk).

  $ touch t.c
  $ clang -cc1 -triple riscv64 -w -emit-pch -o test.pch t.c
  $ clang -cc1 -triple riscv64 -w -x c -include-pch test.pch -ast-dump-all 
/dev/null

The total number required now by clang seems to go far beyond 300 so increasing 
the value to 500 seems to solve the problem. This value was already increased 
in D92715  but I assume this has some impact 
on the on-disk format.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153111

Files:
  clang/include/clang/Serialization/ASTBitCodes.h


Index: clang/include/clang/Serialization/ASTBitCodes.h
===
--- clang/include/clang/Serialization/ASTBitCodes.h
+++ clang/include/clang/Serialization/ASTBitCodes.h
@@ -1106,7 +1106,7 @@
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 300;
+const unsigned NUM_PREDEF_TYPE_IDS = 500;
 
 /// Record codes for each kind of type.
 ///


Index: clang/include/clang/Serialization/ASTBitCodes.h
===
--- clang/include/clang/Serialization/ASTBitCodes.h
+++ clang/include/clang/Serialization/ASTBitCodes.h
@@ -1106,7 +1106,7 @@
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 300;
+const unsigned NUM_PREDEF_TYPE_IDS = 500;
 
 /// Record codes for each kind of type.
 ///
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153018: [include-cleaner] Reorder SymbolReference fields to avoid padding space, NFC

2023-06-16 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo accepted this revision.
VitaNuo added a comment.
This revision is now accepted and ready to land.

thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153018

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


[PATCH] D152070: [2/11][Clang][RISCV] Expand all variants of RVV intrinsic tuple types

2023-06-16 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 added a comment.

It looks like we need to increase `NUM_PREDEF_TYPE_IDS`. Let's continue the 
discussion on D153111 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152070

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


[clang] 461f91b - [clang][Interp] Handle LambdaExprs

2023-06-16 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-06-16T10:05:33+02:00
New Revision: 461f91b1e4ef8bd8a5acc95d2e4badc3b2da5f30

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

LOG: [clang][Interp] Handle LambdaExprs

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

Added: 
clang/test/AST/Interp/lambda.cpp

Modified: 
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/lib/AST/Interp/ByteCodeEmitter.h
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/EvalEmitter.h
clang/lib/AST/Interp/Interp.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index 34ad9bf2b326b..3533559ac3ca4 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -11,6 +11,7 @@
 #include "Floating.h"
 #include "Opcode.h"
 #include "Program.h"
+#include "clang/AST/ASTLambda.h"
 #include "clang/AST/DeclCXX.h"
 #include 
 
@@ -42,11 +43,29 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
   // the 'this' pointer. This parameter is pop()ed from the
   // InterpStack when calling the function.
   bool HasThisPointer = false;
-  if (const auto *MD = dyn_cast(FuncDecl);
-  MD && MD->isInstance()) {
-HasThisPointer = true;
-ParamTypes.push_back(PT_Ptr);
-ParamOffset += align(primSize(PT_Ptr));
+  if (const auto *MD = dyn_cast(FuncDecl)) {
+if (MD->isInstance()) {
+  HasThisPointer = true;
+  ParamTypes.push_back(PT_Ptr);
+  ParamOffset += align(primSize(PT_Ptr));
+}
+
+// Set up lambda capture to closure record field mapping.
+if (isLambdaCallOperator(MD)) {
+  const Record *R = P.getOrCreateRecord(MD->getParent());
+  llvm::DenseMap LC;
+  FieldDecl *LTC;
+
+  MD->getParent()->getCaptureFields(LC, LTC);
+
+  for (auto Cap : LC) {
+unsigned Offset = R->getField(Cap.second)->Offset;
+this->LambdaCaptures[Cap.first] = {
+Offset, Cap.second->getType()->isReferenceType()};
+  }
+  // FIXME: LambdaThisCapture
+  (void)LTC;
+}
   }
 
   // Assign descriptors to all parameters.

diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.h 
b/clang/lib/AST/Interp/ByteCodeEmitter.h
index 30da06b20250f..a184ee071e9df 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.h
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.h
@@ -70,6 +70,10 @@ class ByteCodeEmitter {
 
   /// Parameter indices.
   llvm::DenseMap Params;
+  /// Lambda captures.
+  /// Map from Decl* to [Offset, IsReference] pair.
+  llvm::DenseMap> LambdaCaptures;
+  unsigned LambdaThisCapture;
   /// Local descriptors.
   llvm::SmallVector, 2> Descriptors;
 

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 94db8b868758e..b2a27725307f8 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -895,6 +895,43 @@ bool ByteCodeExprGen::VisitTypeTraitExpr(const 
TypeTraitExpr *E) {
   return this->emitConstBool(E->getValue(), E);
 }
 
+template 
+bool ByteCodeExprGen::VisitLambdaExpr(const LambdaExpr *E) {
+  // XXX We assume here that a pointer-to-initialize is on the stack.
+
+  const Record *R = P.getOrCreateRecord(E->getLambdaClass());
+
+  auto *CaptureInitIt = E->capture_init_begin();
+  // Initialize all fields (which represent lambda captures) of the
+  // record with their initializers.
+  for (const Record::Field &F : R->fields()) {
+const Expr *Init = *CaptureInitIt;
+++CaptureInitIt;
+
+if (std::optional T = classify(Init)) {
+  if (!this->visit(Init))
+return false;
+
+  if (!this->emitSetField(*T, F.Offset, E))
+return false;
+} else {
+  if (!this->emitDupPtr(E))
+return false;
+
+  if (!this->emitGetPtrField(F.Offset, E))
+return false;
+
+  if (!this->visitInitializer(Init))
+return false;
+
+  if (!this->emitPopPtr(E))
+return false;
+}
+  }
+
+  return true;
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;
@@ -1483,6 +1520,8 @@ bool 
ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) {
  dyn_cast(Initializer)) {
 return this->visitConditional(
 ACO, [this](const Expr *E) { return this->visitRecordInitializer(E); 
});
+  } else if (const auto *LE = dyn_cast(Initializer)) {
+return this->VisitLambdaExpr(LE);
   }
 
   return false;
@@ -1980,6 +2019,16 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
 }
   }
 
+  // Handle lambda captures.
+  if (auto It = this->LambdaCaptures.find(D);
+  It != this->LambdaCaptures.end()) {
+auto [Offset, IsReference] = It->seco

[PATCH] D146030: [clang][Interp] Handle LambdaExprs

2023-06-16 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG461f91b1e4ef: [clang][Interp] Handle LambdaExprs (authored 
by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146030

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

Index: clang/test/AST/Interp/lambda.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/lambda.cpp
@@ -0,0 +1,109 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify -std=c++20 %s
+// RUN: %clang_cc1 -verify=ref -std=c++20 %s
+
+constexpr int a = 12;
+constexpr int f = [c = a]() { return c; }();
+static_assert(f == a);
+
+
+constexpr int inc() {
+  int a = 10;
+  auto f = [&a]() {
+++a;
+  };
+
+  f();f();
+
+  return a;
+}
+static_assert(inc() == 12);
+
+constexpr int add(int a, int b) {
+  auto doIt = [a, b](int c) {
+return a + b + c;
+  };
+
+  return doIt(2);
+}
+static_assert(add(4, 5) == 11);
+
+
+constexpr int add2(int a, int b) {
+  auto doIt = [a, b](int c) {
+auto bar = [a]() { return a; };
+auto bar2 = [b]() { return b; };
+
+return bar() + bar2() + c;
+  };
+
+  return doIt(2);
+}
+static_assert(add2(4, 5) == 11);
+
+
+constexpr int div(int a, int b) {
+  auto f = [=]() {
+return a / b; // expected-note {{division by zero}} \
+  // ref-note {{division by zero}}
+  };
+
+  return f(); // expected-note {{in call to '&f->operator()()'}} \
+  // ref-note {{in call to '&f->operator()()'}}
+}
+static_assert(div(8, 2) == 4);
+static_assert(div(8, 0) == 4); // expected-error {{not an integral constant expression}} \
+   // expected-note {{in call to 'div(8, 0)'}} \
+   // ref-error {{not an integral constant expression}} \
+   // ref-note {{in call to 'div(8, 0)'}}
+
+
+struct F {
+  float f;
+};
+
+constexpr float captureStruct() {
+  F someF = {1.0};
+
+  auto p = [someF]() {
+return someF.f;
+  };
+
+  return p();
+}
+
+static_assert(captureStruct() == 1.0);
+
+
+int constexpr FunCase() {
+return [x = 10] {
+   decltype(x) y; // type int b/c not odr use
+  // refers to original init-capture
+   auto &z = x; // type const int & b/c odr use
+ // refers to lambdas copy of x
+y = 10; // Ok
+//z = 10; // Ill-formed
+return y;
+}();
+}
+
+constexpr int WC = FunCase();
+
+
+namespace LambdaParams {
+  template
+  constexpr void callThis(T t) {
+return t();
+  }
+
+  constexpr int foo() {
+int a = 0;
+auto f = [&a]() { ++a; };
+
+callThis(f);
+
+return a;
+  }
+  /// FIXME: This should work in the new interpreter.
+  static_assert(foo() == 1); // expected-error {{not an integral constant expression}}
+}
+
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -840,6 +840,7 @@
   const Pointer &Field = Obj.atField(I);
   if (!CheckStore(S, OpPC, Field))
 return false;
+  Field.initialize();
   Field.deref() = Value;
   return true;
 }
Index: clang/lib/AST/Interp/EvalEmitter.h
===
--- clang/lib/AST/Interp/EvalEmitter.h
+++ clang/lib/AST/Interp/EvalEmitter.h
@@ -76,6 +76,10 @@
 
   /// Parameter indices.
   llvm::DenseMap Params;
+  /// Lambda captures.
+  /// Map from Decl* to [Offset, IsReference] pair.
+  llvm::DenseMap> LambdaCaptures;
+  unsigned LambdaThisCapture;
   /// Local descriptors.
   llvm::SmallVector, 2> Descriptors;
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -93,6 +93,7 @@
   bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
   bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
   bool VisitTypeTraitExpr(const TypeTraitExpr *E);
+  bool VisitLambdaExpr(const LambdaExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -895,6 +895,43 @@
   return this->emitConstBool(E->getValue(), E);
 }
 
+template 
+bool ByteCodeExprGen::VisitLambdaExpr(const LambdaExpr *E) {
+  // XXX We assume here that a pointer-to-initialize is on the stack.
+
+  const Record *R = P.getOrCreateRecord(E->getLambdaClass());
+
+  auto *CaptureI

[PATCH] D153111: [clang][Serialization][RISCV] Increase the number of reserved predefined type IDs

2023-06-16 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 added a comment.

Let me check if I can add a `static_assert` to get a compile-time failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153111

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


[PATCH] D150997: [llvm] Split out DenseMapInfo specialization

2023-06-16 Thread Elliot Goodrich via Phabricator via cfe-commits
IncludeGuardian updated this revision to Diff 532038.
IncludeGuardian added a comment.

Run clang-format over patch


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

https://reviews.llvm.org/D150997

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  flang/include/flang/Optimizer/HLFIR/HLFIROps.h
  llvm/include/llvm/ADT/DenseMapInfo.h
  llvm/include/llvm/ADT/DenseMapInfoVariant.h
  llvm/include/llvm/CodeGen/CallingConvLower.h
  llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
  llvm/include/llvm/Object/DXContainer.h
  llvm/include/llvm/Transforms/Scalar/SROA.h
  llvm/unittests/ADT/DenseMapTest.cpp
  mlir/include/mlir/IR/AsmState.h
  mlir/include/mlir/Transforms/SROA.h

Index: mlir/include/mlir/Transforms/SROA.h
===
--- mlir/include/mlir/Transforms/SROA.h
+++ mlir/include/mlir/Transforms/SROA.h
@@ -13,9 +13,10 @@
 #include "mlir/Interfaces/MemorySlotInterfaces.h"
 #include "mlir/Support/LogicalResult.h"
 #include "llvm/ADT/Statistic.h"
+#include 

 namespace mlir {

 /// Statistics collected while applying SROA.
 struct SROAStatistics {
   /// Total amount of memory slots destructured.
Index: mlir/include/mlir/IR/AsmState.h
===
--- mlir/include/mlir/IR/AsmState.h
+++ mlir/include/mlir/IR/AsmState.h
@@ -20,20 +20,21 @@
 #include "llvm/ADT/StringMap.h"

 #include 
+#include 

 namespace mlir {
 class AsmResourcePrinter;
 class AsmDialectResourceHandle;
 class Operation;

 namespace detail {
 class AsmStateImpl;
 } // namespace detail

 //===--===//
 // Resources
 //===--===//

 /// The following classes enable support for parsing and printing resources
 /// within MLIR assembly formats. Resources are a mechanism by which dialects,
 /// and external clients, may attach additional information when parsing or
Index: llvm/unittests/ADT/DenseMapTest.cpp
===
--- llvm/unittests/ADT/DenseMapTest.cpp
+++ llvm/unittests/ADT/DenseMapTest.cpp
@@ -8,20 +8,21 @@

 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/DenseMapInfoVariant.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
 #include 
 #include 
 #include 

 using namespace llvm;

 namespace {

 uint32_t getTestKey(int i, uint32_t *) { return i; }
 uint32_t getTestValue(int i, uint32_t *) { return 42 + i; }

 uint32_t *getTestKey(int i, uint32_t **) {
   static uint32_t dummy_arr1[8192];
   assert(i < 8192 && "Only support 8192 dummy keys.");
Index: llvm/include/llvm/Transforms/Scalar/SROA.h
===
--- llvm/include/llvm/Transforms/Scalar/SROA.h
+++ llvm/include/llvm/Transforms/Scalar/SROA.h
@@ -21,10 +21,11 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/IR/ValueHandle.h"
+#include 
 #include 

 namespace llvm {

 class AllocaInst;
 class LoadInst;
 class StoreInst;
Index: llvm/include/llvm/Object/DXContainer.h
===
--- llvm/include/llvm/Object/DXContainer.h
+++ llvm/include/llvm/Object/DXContainer.h
@@ -21,13 +21,14 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include "llvm/TargetParser/Triple.h"
+#include 

 namespace llvm {
 namespace object {

 namespace DirectX {
 class PSVRuntimeInfo {

   // This class provides a view into the underlying resource array. The Resource
   // data is little-endian encoded and may not be properly aligned to read
   // directly from. The dereference operator creates a copy of the data and byte
Index: llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
===
--- llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
+++ llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
@@ -22,74 +22,75 @@
 #include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ThreadPool.h"
+#include 

 namespace llvm {
 namespace orc {

 class LLJITBuilderState;
 class LLLazyJITBuilderState;
 class ObjectTransformLayer;
 class ExecutorProcessControl;

 /// A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT.
 ///
 /// Create instances using LLJITBuilder.
 class LLJIT {
   template  friend class LLJITBuilderSetters;

   friend Expected setUpGenericLLVMIRPlatform(LLJIT &J);

 public:
   /// Initializer support for LLJIT.
   class PlatformSupport {
   public:
 virtual ~PlatformSupport();

 virtual Error initialize(JITDylib &JD) = 0;

 virtual Error deinitialize(JITDylib &JD) = 0;

   protected:
 static void setInitTransform(LLJIT &J,
  IRTransformLayer::TransformFunction T);
   };

  

[PATCH] D153015: [clangd] Skip function parameter decls when evaluating variables on hover.

2023-06-16 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 532042.
VitaNuo added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153015

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -22,6 +22,7 @@
 
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -3722,6 +3723,34 @@
   EXPECT_EQ(*HI->Value, "&bar");
 }
 
+TEST(Hover, FunctionParameterDefaulValueNotEvaluatedOnInvalidDecls) {
+  struct {
+const char *const Code;
+const std::optional HoverValue;
+  } Cases[] = {
+  {R"cpp(
+// error-ok testing behavior on invalid decl
+class Foo {};
+void foo(Foo p^aram = nullptr) {}
+)cpp",
+   std::nullopt},
+  {R"cpp(
+class Foo {};
+void foo(Foo *p^aram = nullptr) {}
+)cpp",
+   "nullptr"},
+  };
+
+  for (const auto &C : Cases) {
+Annotations T(C.Code);
+TestTU TU = TestTU::withCode(T.code());
+auto AST = TU.build();
+auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+ASSERT_TRUE(HI);
+ASSERT_EQ(HI->Value, C.HoverValue);
+  }
+}
+
 TEST(Hover, DisableShowAKA) {
   Annotations T(R"cpp(
 using m_int = int;
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -659,7 +659,7 @@
 HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(), Ctx, PP);
 
   // Fill in value with evaluated initializer if possible.
-  if (const auto *Var = dyn_cast(D)) {
+  if (const auto *Var = dyn_cast(D); Var && !Var->isInvalidDecl()) {
 if (const Expr *Init = Var->getInit())
   HI.Value = printExprValue(Init, Ctx);
   } else if (const auto *ECD = dyn_cast(D)) {


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -22,6 +22,7 @@
 
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -3722,6 +3723,34 @@
   EXPECT_EQ(*HI->Value, "&bar");
 }
 
+TEST(Hover, FunctionParameterDefaulValueNotEvaluatedOnInvalidDecls) {
+  struct {
+const char *const Code;
+const std::optional HoverValue;
+  } Cases[] = {
+  {R"cpp(
+// error-ok testing behavior on invalid decl
+class Foo {};
+void foo(Foo p^aram = nullptr) {}
+)cpp",
+   std::nullopt},
+  {R"cpp(
+class Foo {};
+void foo(Foo *p^aram = nullptr) {}
+)cpp",
+   "nullptr"},
+  };
+
+  for (const auto &C : Cases) {
+Annotations T(C.Code);
+TestTU TU = TestTU::withCode(T.code());
+auto AST = TU.build();
+auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+ASSERT_TRUE(HI);
+ASSERT_EQ(HI->Value, C.HoverValue);
+  }
+}
+
 TEST(Hover, DisableShowAKA) {
   Annotations T(R"cpp(
 using m_int = int;
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -659,7 +659,7 @@
 HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(), Ctx, PP);
 
   // Fill in value with evaluated initializer if possible.
-  if (const auto *Var = dyn_cast(D)) {
+  if (const auto *Var = dyn_cast(D); Var && !Var->isInvalidDecl()) {
 if (const Expr *Init = Var->getInit())
   HI.Value = printExprValue(Init, Ctx);
   } else if (const auto *ECD = dyn_cast(D)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153003: [ODRHash] Fix ODR hashing of template names

2023-06-16 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

> For example, the template name with QualifiedTemplate kind has different hash 
> name with the name with DependentTemplate kind. But it is not true after the 
> patch.

Yes, I do understand. However, what I'm asking is why we need to differentiate 
between the two, ie in which cases do we want these two to have a different 
hash?

> No. IsSameEntity is a weaker check. It simply checks whether two named decls 
> refers to the same name.

I'm confused: Hashing always works the way that two "identical" objects hash to 
the same value, while two "non-identical" objects may also hash to the same 
value (hash collision). The way I understand your statement is that two 
"identical" Decls, including `isSame` returning `true`, can have a different 
hashes. This doesn't make sense to me, could you maybe clarify?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153003

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


[clang-tools-extra] 3b59842 - [include-cleaner] Reorder SymbolReference fields to avoid padding space, NFC

2023-06-16 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-06-16T10:21:44+02:00
New Revision: 3b59842a721f0729221347ce0eb20075b1135cc5

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

LOG: [include-cleaner] Reorder SymbolReference fields to avoid padding space, 
NFC

This will bring down the size from 40 bytes to 32 bytes.

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

Added: 


Modified: 
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
clang-tools-extra/include-cleaner/lib/Analysis.cpp
clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
clang-tools-extra/include-cleaner/lib/Record.cpp
clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index 8f1be544bcfa1..dac24bcc7e4d7 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -370,10 +370,9 @@ collectMacroReferences(ParsedAST &AST) {
   continue;
 if (auto DefLoc = Macro->Info->getDefinitionLoc(); DefLoc.isValid())
   Macros.push_back(
-  {Tok.location(),
-   include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok.text(SM)),
+  {include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok.text(SM)),
   DefLoc},
-   include_cleaner::RefType::Explicit});
+   Tok.location(), include_cleaner::RefType::Explicit});
   }
   return Macros;
 }

diff  --git 
a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h 
b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
index 39055db5a8587..0f7fd1cfafa6b 100644
--- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
+++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
@@ -95,10 +95,10 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &, RefType);
 
 /// Indicates that a piece of code refers to a symbol.
 struct SymbolReference {
-  /// The point in the code that refers to the symbol.
-  SourceLocation RefLocation;
   /// The symbol referred to.
   Symbol Target;
+  /// The point in the code that refers to the symbol.
+  SourceLocation RefLocation;
   /// Relation type between the reference location and the target.
   RefType RT;
 };

diff  --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp 
b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
index 2c589ae04412a..3952d10a42334 100644
--- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -45,7 +45,7 @@ void walkUsed(llvm::ArrayRef ASTRoots,
 return;
   // FIXME: Most of the work done here is repetitive. It might be useful to
   // have a cache/batching.
-  SymbolReference SymRef{Loc, ND, RT};
+  SymbolReference SymRef{ND, Loc, RT};
   return CB(SymRef, headersForSymbol(ND, SM, PI));
 });
   }

diff  --git a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp 
b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
index 65b82973c4290..431d4bb211e0d 100644
--- a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
+++ b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
@@ -521,7 +521,7 @@ void writeHTMLReport(FileID File, const 
include_cleaner::Includes &Includes,
 walkAST(*Root, [&](SourceLocation Loc, const NamedDecl &D, RefType T) {
   if(!SM.isWrittenInMainFile(SM.getSpellingLoc(Loc)))
 return;
-  R.addRef(SymbolReference{Loc, D, T});
+  R.addRef(SymbolReference{D, Loc, T});
 });
   for (const SymbolReference &Ref : MacroRefs) {
 if (!SM.isWrittenInMainFile(SM.getSpellingLoc(Ref.RefLocation)))

diff  --git a/clang-tools-extra/include-cleaner/lib/Record.cpp 
b/clang-tools-extra/include-cleaner/lib/Record.cpp
index e36753123392a..dc3192b8baff3 100644
--- a/clang-tools-extra/include-cleaner/lib/Record.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -134,9 +134,9 @@ class PPRecorder : public PPCallbacks {
   RefType RT = RefType::Explicit) {
 if (MI.isBuiltinMacro())
   return; // __FILE__ is not a reference.
-Recorded.MacroReferences.push_back(SymbolReference{
-Tok.getLocation(),
-Macro{Tok.getIdentifierInfo(), MI.getDefinitionLoc()}, RT});
+Recorded.MacroReferences.push_back(
+SymbolReference{Macro{Tok.getIdentifierInfo(), MI.getDefinitionLoc()},
+Tok.getLocation(), RT});
   }
 
   bool Active = false;

diff  --git a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
index 8593d05a1b12d..bad55e1433549 100644
--- a/clang-t

[PATCH] D153018: [include-cleaner] Reorder SymbolReference fields to avoid padding space, NFC

2023-06-16 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3b59842a721f: [include-cleaner] Reorder SymbolReference 
fields to avoid padding space, NFC (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153018

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -182,13 +182,14 @@
   Symbol Answer2 =
   Macro{&Idents.get("ANSWER"), SM.getComposedLoc(HdrID, Hdr.point())};
   EXPECT_THAT(
-  offsetToProviders(AST, SM,
-{SymbolReference{SM.getComposedLoc(SM.getMainFileID(),
-   Code.point("1")),
- Answer1, RefType::Explicit},
- SymbolReference{SM.getComposedLoc(SM.getMainFileID(),
-   Code.point("2")),
- Answer2, RefType::Explicit}}),
+  offsetToProviders(
+  AST, SM,
+  {SymbolReference{
+   Answer1, SM.getComposedLoc(SM.getMainFileID(), Code.point("1")),
+   RefType::Explicit},
+   SymbolReference{
+   Answer2, SM.getComposedLoc(SM.getMainFileID(), Code.point("2")),
+   RefType::Explicit}}),
   UnorderedElementsAre(
   Pair(Code.point("1"), UnorderedElementsAre(HdrFile)),
   Pair(Code.point("2"), UnorderedElementsAre(HdrFile)),
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -134,9 +134,9 @@
   RefType RT = RefType::Explicit) {
 if (MI.isBuiltinMacro())
   return; // __FILE__ is not a reference.
-Recorded.MacroReferences.push_back(SymbolReference{
-Tok.getLocation(),
-Macro{Tok.getIdentifierInfo(), MI.getDefinitionLoc()}, RT});
+Recorded.MacroReferences.push_back(
+SymbolReference{Macro{Tok.getIdentifierInfo(), MI.getDefinitionLoc()},
+Tok.getLocation(), RT});
   }
 
   bool Active = false;
Index: clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
===
--- clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
+++ clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
@@ -521,7 +521,7 @@
 walkAST(*Root, [&](SourceLocation Loc, const NamedDecl &D, RefType T) {
   if(!SM.isWrittenInMainFile(SM.getSpellingLoc(Loc)))
 return;
-  R.addRef(SymbolReference{Loc, D, T});
+  R.addRef(SymbolReference{D, Loc, T});
 });
   for (const SymbolReference &Ref : MacroRefs) {
 if (!SM.isWrittenInMainFile(SM.getSpellingLoc(Ref.RefLocation)))
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -45,7 +45,7 @@
 return;
   // FIXME: Most of the work done here is repetitive. It might be useful to
   // have a cache/batching.
-  SymbolReference SymRef{Loc, ND, RT};
+  SymbolReference SymRef{ND, Loc, RT};
   return CB(SymRef, headersForSymbol(ND, SM, PI));
 });
   }
Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
@@ -95,10 +95,10 @@
 
 /// Indicates that a piece of code refers to a symbol.
 struct SymbolReference {
-  /// The point in the code that refers to the symbol.
-  SourceLocation RefLocation;
   /// The symbol referred to.
   Symbol Target;
+  /// The point in the code that refers to the symbol.
+  SourceLocation RefLocation;
   /// Relation type between the reference location and the target.
   RefType RT;
 };
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -37

[PATCH] D151938: [clang][index] NFCI: Make `CXFile` a `FileEntryRef`

2023-06-16 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D151938#4426106 , @Jake-Egan wrote:

> Hi, there's a test failure on AIX, could you take a look please?
>
> https://lab.llvm.org/buildbot/#/builders/214/builds/8005/steps/6/logs/FAIL__Clang__index-with-module_m

Thanks for notifying me. Interestingly, I didn't receive any notification from 
that bot. Is it possible for me to reproduce this locally on my Mac? If not, 
could you please provide me with the stack trace for the failing call to 
`cantFail()`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151938

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


[PATCH] D153015: [clangd] Skip function parameter decls when evaluating variables on hover.

2023-06-16 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 532044.
VitaNuo marked 2 inline comments as done.
VitaNuo added a comment.

Simplify.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153015

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -22,6 +22,7 @@
 
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -3722,6 +3723,34 @@
   EXPECT_EQ(*HI->Value, "&bar");
 }
 
+TEST(Hover, FunctionParameterDefaulValueNotEvaluatedOnInvalidDecls) {
+  struct {
+const char *const Code;
+const std::optional HoverValue;
+  } Cases[] = {
+  {R"cpp(
+// error-ok testing behavior on invalid decl
+class Foo {};
+void foo(Foo p^aram = nullptr);
+)cpp",
+   std::nullopt},
+  {R"cpp(
+class Foo {};
+void foo(Foo *p^aram = nullptr);
+)cpp",
+   "nullptr"},
+  };
+
+  for (const auto &C : Cases) {
+Annotations T(C.Code);
+TestTU TU = TestTU::withCode(T.code());
+auto AST = TU.build();
+auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+ASSERT_TRUE(HI);
+ASSERT_EQ(HI->Value, C.HoverValue);
+  }
+}
+
 TEST(Hover, DisableShowAKA) {
   Annotations T(R"cpp(
 using m_int = int;
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -659,7 +659,7 @@
 HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(), Ctx, PP);
 
   // Fill in value with evaluated initializer if possible.
-  if (const auto *Var = dyn_cast(D)) {
+  if (const auto *Var = dyn_cast(D); Var && !Var->isInvalidDecl()) {
 if (const Expr *Init = Var->getInit())
   HI.Value = printExprValue(Init, Ctx);
   } else if (const auto *ECD = dyn_cast(D)) {


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -22,6 +22,7 @@
 
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -3722,6 +3723,34 @@
   EXPECT_EQ(*HI->Value, "&bar");
 }
 
+TEST(Hover, FunctionParameterDefaulValueNotEvaluatedOnInvalidDecls) {
+  struct {
+const char *const Code;
+const std::optional HoverValue;
+  } Cases[] = {
+  {R"cpp(
+// error-ok testing behavior on invalid decl
+class Foo {};
+void foo(Foo p^aram = nullptr);
+)cpp",
+   std::nullopt},
+  {R"cpp(
+class Foo {};
+void foo(Foo *p^aram = nullptr);
+)cpp",
+   "nullptr"},
+  };
+
+  for (const auto &C : Cases) {
+Annotations T(C.Code);
+TestTU TU = TestTU::withCode(T.code());
+auto AST = TU.build();
+auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+ASSERT_TRUE(HI);
+ASSERT_EQ(HI->Value, C.HoverValue);
+  }
+}
+
 TEST(Hover, DisableShowAKA) {
   Annotations T(R"cpp(
 using m_int = int;
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -659,7 +659,7 @@
 HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(), Ctx, PP);
 
   // Fill in value with evaluated initializer if possible.
-  if (const auto *Var = dyn_cast(D)) {
+  if (const auto *Var = dyn_cast(D); Var && !Var->isInvalidDecl()) {
 if (const Expr *Init = Var->getInit())
   HI.Value = printExprValue(Init, Ctx);
   } else if (const auto *ECD = dyn_cast(D)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153015: [clangd] Skip function parameter decls when evaluating variables on hover.

2023-06-16 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added a comment.

Thanks for the review!




Comment at: clang-tools-extra/clangd/Hover.cpp:663
+  const auto *Var = dyn_cast(D);
+  if (Var && !llvm::isa(Var)) {
 if (const Expr *Init = Var->getInit())

hokein wrote:
> We're ignoring all `ParmVarDecl` cases, 
> 
> The crash here is for broken code. For the crash case, the AST node looks 
> like 
> 
> ```
> `-ParmVarDecl 0x563b7cc853c0  col:14 invalid param 
> 'Foo':'Foo' cinit
> `-OpaqueValueExpr 0x563b7cc854a0  'Foo':'Foo'
> ```
> 
> One alternative is to exclude invalid `VarDecl`, then the Hover feature still 
> keep working on valid `ParmVarDecl`.
> 
> ```
> if (const auto* Var = dyn_cast(D); Var && !Var->isInvalidDecl()) {
>...
> }
> ```
Why would you do that?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153015

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


[PATCH] D153015: [clangd] Skip function parameter decls when evaluating variables on hover.

2023-06-16 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:663
+  const auto *Var = dyn_cast(D);
+  if (Var && !llvm::isa(Var)) {
 if (const Expr *Init = Var->getInit())

VitaNuo wrote:
> hokein wrote:
> > We're ignoring all `ParmVarDecl` cases, 
> > 
> > The crash here is for broken code. For the crash case, the AST node looks 
> > like 
> > 
> > ```
> > `-ParmVarDecl 0x563b7cc853c0  col:14 invalid param 
> > 'Foo':'Foo' cinit
> > `-OpaqueValueExpr 0x563b7cc854a0  'Foo':'Foo'
> > ```
> > 
> > One alternative is to exclude invalid `VarDecl`, then the Hover feature 
> > still keep working on valid `ParmVarDecl`.
> > 
> > ```
> > if (const auto* Var = dyn_cast(D); Var && !Var->isInvalidDecl()) {
> >...
> > }
> > ```
> Why would you do that?
Sorry this was an unintended comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153015

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


[PATCH] D152900: [clangd] Update symbol collector to use include-cleaner.

2023-06-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:393-395
+const auto *FileEntry = SM.getFileEntryForID(FID);
+for (const auto *Export : PI.getExporters(FileEntry, SM.getFileManager()))
+  return toURI(Export->tryGetRealPathName());

sorry i don't understand what this logic is trying to achieve.

we seem to be prefering "first" exporting header, over the headers that 
directly provide the symbol. Also comment says it's done for objc, but there's 
nothing limiting this logic to ObjC. any chance this is unintended?



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:791
+  include_cleaner::Macro{const_cast(Name), DefLoc},
+  ASTCtx->getSourceManager(), &PI);
+  setSymbolProviders(S, Headers);

s/ASTCtx->getSourceManager()/SM



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:837
+const Symbol &S,
+const llvm::SmallVector &Headers) {
+  if (Opts.CollectIncludePath &&

you can take this by value and `std::move` into the map



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:903
+NewSym = *S;
+if (!IncludeHeader.empty()) {
   NewSym.IncludeHeaders.push_back({IncludeHeader, 1, Directives});

this is using legacy mappings for non-objc symbols too



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:915
+NewSym.IncludeHeaders.push_back(
+{HeaderFileURIs->getIncludeHeader(FID), 1, Directives});
+Symbols.insert(NewSym);

`getIncludeHeader` might return an empty string



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:928
+case include_cleaner::Header::Kind::Verbatim:
+  SymbolIncludeSpelling[SID] = H.verbatim().str();
+  break;

you're iterating over multiple headers, and only keeping references for the 
last one alive.

instead of storing these in the class state, you can have a 
`llvm::DenseMap HeaderToSpelling;` inside this function 
and later on just do:
```
for(const auto& H: It->second) {
  auto [SpellingIt, Inserted] = HeaderToSpelling.try_emplace(H);
  if(Inserted) {
  switch (...) { /* Update *SpellingIt */ }
  }
  NewSym.IncludeHeaders.push_back(*SpellingIt, 1, Directives);
```



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:934-936
+  SymbolIncludeSpelling[SID] = HeaderFileURIs->getIncludeHeader(
+  ASTCtx->getSourceManager().getOrCreateFileID(
+  H.physical(), SrcMgr::CharacteristicKind::C_User));

we actually only want to use `HeaderFileURIs->toURI` here and not the 
`getIncludeHeader`, because:
- We want to make use of mapping logic in include-cleaner solely, and we 
already have all that information in Providers mapping.
- The extra logic we want to apply for ObjC symbols are already applied before 
reaching here.

the way we create a FileID here is a little bit iffy, by using `toURI`, 
hopefully we can avoid that conversion.

the only remaining issue is, we actually still want to use system header 
mappings inside `CanonicalIncludes` until we have better support for them in 
include-cleaner library itself. So I think we should still call 
`Includes->mapHeader(H.physical())` before using `toURI`.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.h:131
+  }
+  void setPreprocessor(Preprocessor &PP) {
+this->PP = &PP;

unfortunately this alternative is called after we've parsed the file, from 
`clangd/index/FileIndex.cpp`, `indexSymbols`. hence attaching `PI` to 
`PPCallbacks` won't have any effect.

This is working unintentionally because we're still populating 
`CanonicalIncludes` with legacy IWYUPragmaHandler in clangd, and using that to 
perform private -> public mappings.

We should instead propagate the `PragmaIncludes` we have in `ParsedAST` and in 
preamble builds here. You should be able to test the new behaviour 
`clang-tools-extra/clangd/unittests/FileIndexTests.cpp` to make sure pragma 
handling through dynamic indexing code paths keep working as expected using an 
`export` pragma.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152900

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


[PATCH] D153003: [ODRHash] Fix ODR hashing of template names

2023-06-16 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

> what I'm asking is why we need to differentiate between the two, ie in which 
> cases do we want these two to have a different hash?

I don't understand. It should a basic requirement for different AST entities to 
have different values.

> The way I understand your statement is that two "identical" Decls, including 
> isSame returning true, can have a different hashes.

I mean when we can't work on ODRHash properly, we can choose that as a 
workaround.

An important node here is that ODRHash is used to check the AST Nodes are 
keeping the same across compilations. There is gap to use ODRHash to check the 
semantical equality.

---

Also I find I missed an important point. The standard says 
https://eel.is/c++draft/basic.def.odr#14.4. So that the example is not valid 
even if they are in global module fragments since they don't have same token 
sequences.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153003

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


[PATCH] D153114: [WIP] [clangd] [C++20] [Modules] Support C++20 modules for clangd

2023-06-16 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu created this revision.
Herald added subscribers: kadircet, arphaman, javed.absar.
Herald added a project: All.
ChuanqiXu requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

https://reviews.llvm.org/D153114

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/clangd/ModulesManager.cpp
  clang-tools-extra/clangd/ModulesManager.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/support/ThreadsafeFS.cpp
  clang-tools-extra/clangd/test/CMakeLists.txt
  clang-tools-extra/clangd/test/modules.test
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/ModulesManagerTests.cpp
  clang-tools-extra/docs/ReleaseNotes.rst

Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -48,6 +48,9 @@
 Improvements to clangd
 --
 
+- Implemented the experimental support for C++20 modules. This can be enabled by
+  `-experimental-modules-support` option.
+
 Inlay hints
 ^^^
 
Index: clang-tools-extra/clangd/unittests/ModulesManagerTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/ModulesManagerTests.cpp
@@ -0,0 +1,353 @@
+//===-- ModulesManagerTests.cpp -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Config.h"
+#include "ModulesManager.h"
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace clang::clangd;
+using namespace llvm;
+
+namespace {
+class ModulesManagerTest : public ::testing::Test {
+  void SetUp() override {
+ASSERT_FALSE(sys::fs::createUniqueDirectory("modules-test", TestDir));
+llvm::errs() << "Created TestDir: " << TestDir << "\n";
+  }
+
+  void TearDown() override {
+// sys::fs::remove_directories(TestDir);
+  }
+
+public:
+  SmallString<256> TestDir;
+
+  // Add files to the working testing directory and repalce all the
+  // `__DIR__` to TestDir.
+  void addFile(StringRef Path, StringRef Contents) {
+ASSERT_FALSE(sys::path::is_absolute(Path));
+
+SmallString<256> AbsPath(TestDir);
+sys::path::append(AbsPath, Path);
+
+ASSERT_FALSE(
+sys::fs::create_directories(llvm::sys::path::parent_path(AbsPath)));
+
+std::error_code EC;
+llvm::raw_fd_ostream OS(AbsPath, EC);
+ASSERT_FALSE(EC);
+
+std::size_t Pos = Contents.find("__DIR__");
+while (Pos != llvm::StringRef::npos) {
+  OS << Contents.take_front(Pos);
+  OS << TestDir;
+  Contents = Contents.drop_front(Pos + sizeof("__DIR__") - 1);
+  Pos = Contents.find("__DIR__");
+}
+
+OS << Contents;
+  }
+
+  // Get the absolute path for file specified by Path under testing working
+  // directory.
+  std::string getFullPath(StringRef Path) {
+SmallString<128> Result(TestDir);
+sys::path::append(Result, Path);
+return Result.str().str();
+  }
+};
+
+TEST_F(ModulesManagerTest, ReplaceCommandsTest) {
+  addFile("build/compile_commands.json", R"cpp(
+[
+{
+  "directory": "__DIR__",
+  "command": "clang++ -std=c++20 __DIR__/M.cppm -c -o __DIR__/M.o -fmodule-file=D=__DIR__/D.pcm",
+  "file": "__DIR__/M.cppm",
+  "output": "__DIR__/M.o"
+}
+]
+  )cpp");
+
+  addFile("M.cppm", R"cpp(
+export module M;
+import D;
+  )cpp");
+
+  RealThreadsafeFS TFS;
+  DirectoryBasedGlobalCompilationDatabase::Options Opts(TFS);
+  DirectoryBasedModulesGlobalCompilationDatabase MCDB(Opts,
+  /*AsyncThreadsCount*/ 4);
+
+  std::optional Cmd =
+  MCDB.getCompileCommand(getFullPath("M.cppm"));
+  EXPECT_TRUE(Cmd);
+  // Since the graph is not built yet. We don't expect to see the mutated
+  // command line for modules.
+  EXPECT_FALSE(any_of(Cmd->CommandLine, [](StringRef Arg) {
+return Arg.count("-fprebuilt-module-path");
+  }));
+  EXPECT_TRUE(any_of(Cmd->CommandLine, [](StringRef Arg) {
+return Arg.count("-fmodule-file=");
+  }));
+
+  ModulesManager *MMgr = MCDB.getModulesManager();
+  EXPECT_TRUE(MMgr);
+  MMgr->UpdateNode(getFullPath("M.

[PATCH] D153114: [WIP] [clangd] [C++20] [Modules] Support C++20 modules for clangd

2023-06-16 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 532056.

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

https://reviews.llvm.org/D153114

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/clangd/ModulesManager.cpp
  clang-tools-extra/clangd/ModulesManager.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/test/CMakeLists.txt
  clang-tools-extra/clangd/test/modules.test
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/ModulesManagerTests.cpp
  clang-tools-extra/docs/ReleaseNotes.rst

Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -48,6 +48,9 @@
 Improvements to clangd
 --
 
+- Implemented the experimental support for C++20 modules. This can be enabled by
+  `-experimental-modules-support` option.
+
 Inlay hints
 ^^^
 
Index: clang-tools-extra/clangd/unittests/ModulesManagerTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/ModulesManagerTests.cpp
@@ -0,0 +1,353 @@
+//===-- ModulesManagerTests.cpp -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Config.h"
+#include "ModulesManager.h"
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace clang::clangd;
+using namespace llvm;
+
+namespace {
+class ModulesManagerTest : public ::testing::Test {
+  void SetUp() override {
+ASSERT_FALSE(sys::fs::createUniqueDirectory("modules-test", TestDir));
+llvm::errs() << "Created TestDir: " << TestDir << "\n";
+  }
+
+  void TearDown() override {
+// sys::fs::remove_directories(TestDir);
+  }
+
+public:
+  SmallString<256> TestDir;
+
+  // Add files to the working testing directory and repalce all the
+  // `__DIR__` to TestDir.
+  void addFile(StringRef Path, StringRef Contents) {
+ASSERT_FALSE(sys::path::is_absolute(Path));
+
+SmallString<256> AbsPath(TestDir);
+sys::path::append(AbsPath, Path);
+
+ASSERT_FALSE(
+sys::fs::create_directories(llvm::sys::path::parent_path(AbsPath)));
+
+std::error_code EC;
+llvm::raw_fd_ostream OS(AbsPath, EC);
+ASSERT_FALSE(EC);
+
+std::size_t Pos = Contents.find("__DIR__");
+while (Pos != llvm::StringRef::npos) {
+  OS << Contents.take_front(Pos);
+  OS << TestDir;
+  Contents = Contents.drop_front(Pos + sizeof("__DIR__") - 1);
+  Pos = Contents.find("__DIR__");
+}
+
+OS << Contents;
+  }
+
+  // Get the absolute path for file specified by Path under testing working
+  // directory.
+  std::string getFullPath(StringRef Path) {
+SmallString<128> Result(TestDir);
+sys::path::append(Result, Path);
+return Result.str().str();
+  }
+};
+
+TEST_F(ModulesManagerTest, ReplaceCommandsTest) {
+  addFile("build/compile_commands.json", R"cpp(
+[
+{
+  "directory": "__DIR__",
+  "command": "clang++ -std=c++20 __DIR__/M.cppm -c -o __DIR__/M.o -fmodule-file=D=__DIR__/D.pcm",
+  "file": "__DIR__/M.cppm",
+  "output": "__DIR__/M.o"
+}
+]
+  )cpp");
+
+  addFile("M.cppm", R"cpp(
+export module M;
+import D;
+  )cpp");
+
+  RealThreadsafeFS TFS;
+  DirectoryBasedGlobalCompilationDatabase::Options Opts(TFS);
+  DirectoryBasedModulesGlobalCompilationDatabase MCDB(Opts,
+  /*AsyncThreadsCount*/ 4);
+
+  std::optional Cmd =
+  MCDB.getCompileCommand(getFullPath("M.cppm"));
+  EXPECT_TRUE(Cmd);
+  // Since the graph is not built yet. We don't expect to see the mutated
+  // command line for modules.
+  EXPECT_FALSE(any_of(Cmd->CommandLine, [](StringRef Arg) {
+return Arg.count("-fprebuilt-module-path");
+  }));
+  EXPECT_TRUE(any_of(Cmd->CommandLine, [](StringRef Arg) {
+return Arg.count("-fmodule-file=");
+  }));
+
+  ModulesManager *MMgr = MCDB.getModulesManager();
+  EXPECT_TRUE(MMgr);
+  MMgr->UpdateNode(getFullPath("M.cppm"));
+
+  MMgr->waitUntilInitialized();
+
+  Cmd = MCDB.getCompileCommand(getFullPath("M.cppm"));
+  EXPECT_TRUE(Cmd);
+  // Since the graph has been built. We expect to see the mutated command line
+  // for modules.
+  EXPECT_TRUE(any_of(Cmd->CommandLine, [](StringRef Arg) {
+retur

[PATCH] D153015: [clangd] Skip function parameter decls when evaluating variables on hover.

2023-06-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks, looks good, just one nit to simplify the unittest.




Comment at: clang-tools-extra/clangd/unittests/HoverTests.cpp:3726
 
+TEST(Hover, FunctionParameterDefaulValueNotEvaluatedOnInvalidDecls) {
+  struct {

nit: instead of creating a completely-new TEST, it seems simpler to just add a 
testcase in the existing `TEST(Hover, All)`.


```
   {R"cpp(// Should not crash on an invalid param decl.
  class Foo {};
  // error-ok
  void foo(Foo [[fo^o]] = nullptr);
  )cpp",
   [](HoverInfo &HI) {
 HI.Name = "foo";
 HI.Type = "Foo";
 HI.Kind = index::SymbolKind::Parameter;
 HI.NamespaceScope = "";
 HI.LocalScope = "foo::";
 HI.Definition = "Foo foo = ";
   }},
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153015

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


[PATCH] D146242: [ARM] Fixing ABI mismatch for packed structs passed as function arguments

2023-06-16 Thread Momchil Velikov via Phabricator via cfe-commits
chill added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:5809
 
-// For alignment adjusted HFAs, cap the argument alignment to 16, leave it
-// default otherwise.
+// For alignment adjusted HFAs, cap the argument alignment to 16, otherwise
+// set it to 8 according to the AAPCS64 document.

No need to "alignment adjusted", just "HFA/HVA"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146242

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


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

2023-06-16 Thread Haohai, Wen via Phabricator via cfe-commits
HaohaiWen updated this revision to Diff 532060.
HaohaiWen marked an inline comment as done.
HaohaiWen added a comment.

Address skan's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152785

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/split-debug.c
  llvm/include/llvm/MC/MCWinCOFFObjectWriter.h
  llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
  llvm/lib/MC/MCAsmBackend.cpp
  llvm/lib/MC/WinCOFFObjectWriter.cpp
  llvm/test/DebugInfo/COFF/dwarf-headers.ll
  llvm/test/DebugInfo/COFF/fission-cu.ll
  llvm/test/DebugInfo/COFF/fission-sections.ll

Index: llvm/test/DebugInfo/COFF/fission-sections.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/fission-sections.ll
@@ -0,0 +1,42 @@
+; RUN: llc -split-dwarf-file=baz.dwo -split-dwarf-output=%t.dwo -O0 %s -mtriple=x86_64-unknown-windows-msvc -filetype=obj -o %t
+; RUN: llvm-objdump -h %t | FileCheck --check-prefix=OBJ %s
+; RUN: llvm-objdump -h %t.dwo | FileCheck --check-prefix=DWO %s
+
+; This test is derived from test/DebugInfo/X86/fission-cu.ll
+; But it checks that the output objects have the expected sections
+
+source_filename = "test/DebugInfo/X86/fission-cu.ll"
+
+@a = common global i32 0, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!4}
+!llvm.module.flags = !{!7}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = !DIGlobalVariable(name: "a", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true)
+!2 = !DIFile(filename: "baz.c", directory: "e:\\llvm-project\\tmp")
+!3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!4 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 3.3 (trunk 169021) (llvm/trunk 169020)", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "baz.dwo", emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5)
+!5 = !{}
+!6 = !{!0}
+!7 = !{i32 1, !"Debug Info Version", i32 3}
+
+; CHECK-LABEL: Sections:
+
+; OBJ: Idx Name
+; OBJ-NEXT:  0 .text
+; OBJ-NEXT:  1 .data
+; OBJ-NEXT:  2 .bss
+; OBJ-NEXT:  3 .debug_abbrev
+; OBJ-NEXT:  4 .debug_info
+; OBJ-NEXT:  5 .debug_str
+; OBJ-NEXT:  6 .debug_addr
+; OBJ-NEXT:  7 .debug_pubnames
+; OBJ-NEXT:  8 .debug_pubtypes
+; OBJ-NEXT:  9 .debug_line
+
+; DWO:  Idx Name
+; DWO-NEXT:   0 .debug_str.dwo
+; DWO-NEXT:   1 .debug_str_offsets.dwo
+; DWO-NEXT:   2 .debug_info.dwo
+; DWO-NEXT:   3 .debug_abbrev.dwo
Index: llvm/test/DebugInfo/COFF/fission-cu.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/fission-cu.ll
@@ -0,0 +1,120 @@
+; RUN: llc -split-dwarf-file=baz.dwo -O0 %s -mtriple=x86_64-unknown-windows-msvc -filetype=obj -o %t
+; RUN: llvm-dwarfdump -v -all %t | FileCheck %s
+; RUN: llvm-readobj --relocations %t | FileCheck --check-prefix=OBJ %s
+; RUN: llvm-objdump -h %t | FileCheck --check-prefix=HDR %s
+
+; This test is derived from test/DebugInfo/X86/fission-cu.ll
+
+source_filename = "test/DebugInfo/X86/fission-cu.ll"
+
+@a = common global i32 0, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!4}
+!llvm.module.flags = !{!7}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = !DIGlobalVariable(name: "a", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true)
+!2 = !DIFile(filename: "baz.c", directory: "e:\\llvm-project\\tmp")
+!3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!4 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 3.3 (trunk 169021) (llvm/trunk 169020)", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "baz.dwo", emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5)
+!5 = !{}
+; Check that the skeleton compile unit contains the proper attributes:
+; This DIE has the following attributes: DW_AT_comp_dir, DW_AT_stmt_list,
+; DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_dwo_name, DW_AT_dwo_id,
+; DW_AT_ranges_base, DW_AT_addr_base.
+
+; CHECK: .debug_abbrev contents:
+; CHECK: Abbrev table for offset: 0x
+; CHECK: [1] DW_TAG_compile_unit DW_CHILDREN_no
+; CHECK: DW_AT_stmt_list DW_FORM_sec_offset
+; CHECK: DW_AT_comp_dir  DW_FORM_strp
+; CHECK: DW_AT_GNU_dwo_name  DW_FORM_strp
+; CHECK: DW_AT_GNU_dwo_idDW_FORM_data8
+
+; Check that we're using the right forms.
+; CHECK: .debug_abbrev.dwo contents:
+; CHECK: Abbrev table for offset: 0x
+; CHECK: [1] DW_TAG_compile_unit DW_CHILDREN_yes
+; CHECK: DW_AT_producer  DW_FORM_GNU_str_index
+; CHECK: DW_AT_language  DW_FORM_data2
+; CHECK: DW_AT_name  DW_FORM_GNU_str_index
+; CHECK: DW_AT_GNU_dwo_name  DW_FORM_GNU_str_index
+; CHECK-NOT: DW_AT_low_pc
+; CHECK-NOT: DW_AT_stmt_list
+; CHECK-NOT: DW_A

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

2023-06-16 Thread Haohai, Wen via Phabricator via cfe-commits
HaohaiWen added inline comments.



Comment at: llvm/lib/DebugInfo/DWARF/DWARFContext.cpp:1896
+// Each section in COFF can directly contain relocations.
+if (isa(&Obj) && Section.relocations().empty())
+  continue;

skan wrote:
> Should we merge the check into line 1894?
It's more elegant to not merge. 



Comment at: llvm/test/DebugInfo/COFF/dwarf-headers.ll:75
+!14 = !{i32 1, !"MaxTLSAlign", i32 65536}
+!15 = !{!"clang version 17.0.0 (https://github.com/llvm/llvm-project.git 
f1106ef6c9d14d5b516ec352279aeee8f9d12818)"}

skan wrote:
> Simplify it to "clang"?
I have attached source code in comments. It's better to save llvm version here 
to help to reproduce it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152785

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


[PATCH] D153111: [clang][Serialization][RISCV] Increase the number of reserved predefined type IDs

2023-06-16 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 updated this revision to Diff 532061.
rogfer01 added a comment.

ChangeLog:

- Add a sentinel and a `static_assert`


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

https://reviews.llvm.org/D153111

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/Serialization/ASTReader.cpp


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -6983,6 +6983,10 @@
   if (Index < NUM_PREDEF_TYPE_IDS) {
 QualType T;
 switch ((PredefinedTypeIDs)Index) {
+case PREDEF_TYPE_LAST_ID:
+  // We should never use this one.
+  llvm_unreachable("Invalid predefined type");
+  break;
 case PREDEF_TYPE_NULL_ID:
   return QualType();
 case PREDEF_TYPE_VOID_ID:
Index: clang/include/clang/Serialization/ASTBitCodes.h
===
--- clang/include/clang/Serialization/ASTBitCodes.h
+++ clang/include/clang/Serialization/ASTBitCodes.h
@@ -1099,6 +1099,8 @@
 // \brief WebAssembly reference types with auto numeration
 #define WASM_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID,
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
+  // Sentinel value. Considered a predefined type but not useable as one.
+  PREDEF_TYPE_LAST_ID
 };
 
 /// The number of predefined type IDs that are reserved for
@@ -1106,7 +1108,13 @@
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 300;
+const unsigned NUM_PREDEF_TYPE_IDS = 500;
+
+// Ensure we do not overrun the predefined types we reserved
+// in the enum PredefinedTypeIDs above.
+static_assert(PREDEF_TYPE_LAST_ID < NUM_PREDEF_TYPE_IDS,
+  "Too many enumerators in PredefinedTypeIDs. Review the value of "
+  "NUM_PREDEF_TYPE_IDS");
 
 /// Record codes for each kind of type.
 ///


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -6983,6 +6983,10 @@
   if (Index < NUM_PREDEF_TYPE_IDS) {
 QualType T;
 switch ((PredefinedTypeIDs)Index) {
+case PREDEF_TYPE_LAST_ID:
+  // We should never use this one.
+  llvm_unreachable("Invalid predefined type");
+  break;
 case PREDEF_TYPE_NULL_ID:
   return QualType();
 case PREDEF_TYPE_VOID_ID:
Index: clang/include/clang/Serialization/ASTBitCodes.h
===
--- clang/include/clang/Serialization/ASTBitCodes.h
+++ clang/include/clang/Serialization/ASTBitCodes.h
@@ -1099,6 +1099,8 @@
 // \brief WebAssembly reference types with auto numeration
 #define WASM_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID,
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
+  // Sentinel value. Considered a predefined type but not useable as one.
+  PREDEF_TYPE_LAST_ID
 };
 
 /// The number of predefined type IDs that are reserved for
@@ -1106,7 +1108,13 @@
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 300;
+const unsigned NUM_PREDEF_TYPE_IDS = 500;
+
+// Ensure we do not overrun the predefined types we reserved
+// in the enum PredefinedTypeIDs above.
+static_assert(PREDEF_TYPE_LAST_ID < NUM_PREDEF_TYPE_IDS,
+  "Too many enumerators in PredefinedTypeIDs. Review the value of "
+  "NUM_PREDEF_TYPE_IDS");
 
 /// Record codes for each kind of type.
 ///
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151696: [x86] Remove CPU_SPECIFIC* MACROs and add getManglingForCPU

2023-06-16 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/test/CodeGen/X86/cpus-intel.ll:8
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium 2>&1 
| FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
-; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium-mmx 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium-mmx 
-mcpu=pentium_mmx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR 
--allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=i686 2>&1 | 
FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty

I meant like this:
```
; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium-mmx 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_mmx 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
```
The idea is to keep RUN lines that test the equivalent cpus together, so its 
easier for any future edits to handle them together


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151696

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


[PATCH] D153003: [ODRHash] Fix ODR hashing of template names

2023-06-16 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In D153003#4427412 , @ChuanqiXu wrote:

> An important node here is that ODRHash is used to check the AST Nodes are 
> keeping the same across compilations. There is gap to use ODRHash to check 
> the semantical equality.

Oh ok... I'm coming from the context of https://reviews.llvm.org/D41416 which 
uses `ODRHash`es to decide which `Decl`s to load. The problem at hand is that 
the hash in the module was computed from a `TemplateName::Template` while the 
instantiating context has a fully qualified template name. I was thinking to 
"solve" this by making them hash to the same value, but I'm hearing that using 
`ODRHash` for this purpose is the wrong approach to begin with?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153003

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


[PATCH] D146242: [ARM] Fixing ABI mismatch for packed structs passed as function arguments

2023-06-16 Thread Momchil Velikov via Phabricator via cfe-commits
chill added inline comments.



Comment at: clang/test/CodeGen/aarch64-ABI-align-packed.c:34
 struct aligned_member_8 {
   uint16x8_t M0 __attribute((aligned (8))); // member alignment 16 since 
__attribute((aligned (n))) sets the minimum alignment
 };

Don't you mean "`__attribute__((aligned(n)))` cannot decrease the minimum 
required alignment" ?




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146242

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


[PATCH] D153111: [clang][Serialization][RISCV] Increase the number of reserved predefined type IDs

2023-06-16 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD accepted this revision.
eopXD added a comment.
This revision is now accepted and ready to land.

This change looks good to me. Weird that the error did not pop out on my side.


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

https://reviews.llvm.org/D153111

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


[PATCH] D152645: [clangd] Handle DependentNameType in HeuristicResolver::resolveTypeToRecordDecl()

2023-06-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/HeuristicResolver.cpp:33
 
+const Type *resolveDeclsToType(const std::vector &Decls,
+   ASTContext &Ctx) {

nit: move this helper function to anonymous namespace.



Comment at: clang-tools-extra/clangd/HeuristicResolver.cpp:56
+  if (const auto *DNT = T->getAs()) {
+T = resolveDeclsToType(resolveDependentNameType(DNT));
+if (!T)

nridge wrote:
> hokein wrote:
> > Is the `resolveDeclsToType` call necessary here?  
> > The code path we're doing is `dependent-type => Decl* => Type => Decl*`, 
> > the later two steps seems redundant, can we just use the Decl result from 
> > `resolveDependentNameType()`?
> > 
> > 
> The Decl returned by `resolveDependentNameType()` in this testcase is a 
> `TypeAliasDecl`. The function needs to return the `CXXRecordDecl` which is 
> named by the target type of the alias.
> 
> We could add logic to "desugar" the `TypeAliasDecl`, but it seems easier to 
> reuse the existing logic that does the desugaring in type-land.
I see, thanks for the explanation (this part of code is a bit hard to follow). 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152645

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


[PATCH] D153003: [ODRHash] Fix ODR hashing of template names

2023-06-16 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

> I was thinking to "solve" this by making them hash to the same value, but I'm 
> hearing that using ODRHash for this purpose is the wrong approach to begin 
> with?

We can't say this abstractly. It should be fine to work in ODRHash for C++20 
modules issues as long as we don't lose informations. And this **was** the 
major issue of the patch. (**Now** the major issue is that the case shouldn't 
be accepted.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153003

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


[PATCH] D146242: [ARM] Fixing ABI mismatch for packed structs passed as function arguments

2023-06-16 Thread Jirui Wu via Phabricator via cfe-commits
JiruiWu marked an inline comment as done.
JiruiWu added inline comments.



Comment at: clang/test/CodeGen/aarch64-ABI-align-packed.c:34
 struct aligned_member_8 {
   uint16x8_t M0 __attribute((aligned (8))); // member alignment 16 since 
__attribute((aligned (n))) sets the minimum alignment
 };

chill wrote:
> Don't you mean "`__attribute__((aligned(n)))` cannot decrease the minimum 
> required alignment" ?
> 
> 
I added this comment to explain that the natural alignment of the struct 
`aligned_member_8` is 16-byte instead of 8-byte. In this test case the 
alignment of  `M0` is 16 bytes, which is above the minimum required alignment 
specified by `__attribute__((aligned(8)))`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146242

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


[PATCH] D146242: [ARM] Fixing ABI mismatch for packed structs passed as function arguments

2023-06-16 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson requested changes to this revision.
tmatheson added a comment.
This revision now requires changes to proceed.

I think the current patch is wrong for a couple of reasons.

Firstly the data types being tested, e.g. `struct S { int8x16_t m; }` etc, are 
not just composite types, but HVAs:
https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#homogeneous-aggregates

> A Homogeneous Aggregate is a composite type where all of the Fundamental Data 
> Types of the members that compose the type are the same. The test for 
> homogeneity is applied after data layout is completed and without regard to 
> access control or other source language restrictions. Note that for 
> short-vector types the fundamental types are 64-bit vector and 128-bit 
> vector; the type of the elements in the short vector does not form part of 
> the test for homogeneity.

So these are HVAs with Fundamental Data Type of 128-bit vector. This explains 
why the alignment changes get applied, because they are scoped to 
`if(isHomogeneousAggregate)` which we would not expect to apply for normal 
composite types.

Since these are HVAs the relevant AAPCS64 rules are different. Specifically 
https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#parameter-passing

> B.3 If the argument type is an HFA or an HVA, then the argument is used 
> unmodified.

would be the "first matching rule" and B6  (the 
"alignment of the copy is either 8 or 16" rule) would not be applied.

If anyone can confirm or correct my reading of the above that would be 
appreciated. The rules are so spread out it's hard to be confident that I've 
taken everything into account.

I haven't checked if the current alignment for these HVA types is correct yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146242

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


[clang] 6408317 - [clang][Sema] Provide source range to several Wunused warnings

2023-06-16 Thread Takuya Shimizu via cfe-commits

Author: Takuya Shimizu
Date: 2023-06-16T19:26:53+09:00
New Revision: 64083172eea26e50c8b22b85697a825be8bda424

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

LOG: [clang][Sema] Provide source range to several Wunused warnings

When the diagnosed function/variable is a template specialization, the source 
range covers the specialization arguments.
e.g.
```
warning: unused function 'func' [-Wunused-function]
template <> int func () {}
^
```
This comes in line with the printed text in the warning message. In the above 
case, `func`

Reviewed By: aaron.ballman

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

Added: 
clang/test/Misc/Inputs/diag-unused-source-ranges.h
clang/test/Misc/diag-unused-source-ranges.cpp

Modified: 
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 09084176cbf41..694e07b46aaf0 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1347,10 +1347,14 @@ void Sema::ActOnEndOfTranslationUnit() {
   DiagD = FD;
 if (DiagD->isDeleted())
   continue; // Deleted functions are supposed to be unused.
+SourceRange DiagRange = DiagD->getLocation();
+if (const ASTTemplateArgumentListInfo *ASTTAL =
+DiagD->getTemplateSpecializationArgsAsWritten())
+  DiagRange.setEnd(ASTTAL->RAngleLoc);
 if (DiagD->isReferenced()) {
   if (isa(DiagD))
 Diag(DiagD->getLocation(), diag::warn_unneeded_member_function)
-<< DiagD;
+<< DiagD << DiagRange;
   else {
 if (FD->getStorageClass() == SC_Static &&
 !FD->isInlineSpecified() &&
@@ -1358,39 +1362,46 @@ void Sema::ActOnEndOfTranslationUnit() {
SourceMgr.getExpansionLoc(FD->getLocation(
   Diag(DiagD->getLocation(),
diag::warn_unneeded_static_internal_decl)
-  << DiagD;
+  << DiagD << DiagRange;
 else
   Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
-  << /*function*/ 0 << DiagD;
+  << /*function*/ 0 << DiagD << DiagRange;
   }
 } else {
   if (FD->getDescribedFunctionTemplate())
 Diag(DiagD->getLocation(), diag::warn_unused_template)
-<< /*function*/ 0 << DiagD;
+<< /*function*/ 0 << DiagD << DiagRange;
   else
 Diag(DiagD->getLocation(), isa(DiagD)
? diag::warn_unused_member_function
: diag::warn_unused_function)
-<< DiagD;
+<< DiagD << DiagRange;
 }
   } else {
 const VarDecl *DiagD = cast(*I)->getDefinition();
 if (!DiagD)
   DiagD = cast(*I);
+SourceRange DiagRange = DiagD->getLocation();
+if (const auto *VTSD = dyn_cast(DiagD)) 
{
+  if (const ASTTemplateArgumentListInfo *ASTTAL =
+  VTSD->getTemplateArgsInfo())
+DiagRange.setEnd(ASTTAL->RAngleLoc);
+}
 if (DiagD->isReferenced()) {
   Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
-  << /*variable*/ 1 << DiagD;
+  << /*variable*/ 1 << DiagD << DiagRange;
 } else if (DiagD->getDescribedVarTemplate()) {
   Diag(DiagD->getLocation(), diag::warn_unused_template)
-  << /*variable*/ 1 << DiagD;
+  << /*variable*/ 1 << DiagD << DiagRange;
 } else if (DiagD->getType().isConstQualified()) {
   const SourceManager &SM = SourceMgr;
   if (SM.getMainFileID() != SM.getFileID(DiagD->getLocation()) ||
   !PP.getLangOpts().IsHeaderFile)
 Diag(DiagD->getLocation(), diag::warn_unused_const_variable)
-<< DiagD;
+<< DiagD << DiagRange;
 } else {
-  Diag(DiagD->getLocation(), diag::warn_unused_variable) << DiagD;
+  Diag(DiagD->getLocation(), diag::warn_unused_variable)
+  << DiagD << DiagRange;
 }
   }
 }

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 757c4c310be3d..e93f86821d846 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2151,7 +2151,8 @@ void Sema::DiagnoseUnusedDecl(const NamedDecl *D, 
DiagReceiverTy DiagReceiver) {
   else
 DiagID = diag::warn_unused_variable;
 
-  DiagReceiver(D->getLocation(), PDiag(DiagID) << D << Hint);
+  SourceLocation DiagLoc = D->getLocation();
+  DiagReceiver(DiagLoc, PDiag(DiagID) << D << Hint << SourceRange(DiagLoc));
 }
 

[PATCH] D152707: [clang][Sema] Provide source range to several Wunused warnings

2023-06-16 Thread Takuya Shimizu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG64083172eea2: [clang][Sema] Provide source range to several 
Wunused warnings (authored by hazohelet).

Changed prior to commit:
  https://reviews.llvm.org/D152707?vs=531266&id=532079#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152707

Files:
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Misc/Inputs/diag-unused-source-ranges.h
  clang/test/Misc/diag-unused-source-ranges.cpp

Index: clang/test/Misc/diag-unused-source-ranges.cpp
===
--- /dev/null
+++ clang/test/Misc/diag-unused-source-ranges.cpp
@@ -0,0 +1,124 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -Wunused -Wunused-template -Wunused-exception-parameter -Wunused-member-function -fdiagnostics-print-source-range-info %s 2>&1 | FileCheck %s --strict-whitespace
+#include "Inputs/diag-unused-source-ranges.h"
+
+#define CAT(a, b) a ## b
+
+// CHECK:  :{55:15-55:20}: warning: unused exception parameter 'param'
+// CHECK-NEXT:   catch (int ¶m) {}
+// CHECK-NEXT:   ^{{$}}
+
+// CHECK:  :{53:7-53:12}: warning: unused variable 'local'
+// CHECK-NEXT:   int local = 0;
+// CHECK-NEXT:   ^{{$}}
+
+// CHECK:  In file included from
+// CHECK-NEXT: :{1:13-1:18}: warning: 'static' function 'thing' declared in header file should be declared 'static inline'
+// CHECK-NEXT:   static void thing(void) {}
+// CHECK-NEXT:   ^{{$}}
+
+namespace {
+class A {
+  // CHECK:  :{[[@LINE+3]]:10-[[@LINE+3]]:14}: warning: member function 'func' is not needed
+  // CHECK-NEXT:   void func() {}
+  // CHECK-NEXT:^~~~{{$}}
+void func() {}
+  // CHECK:  :{[[@LINE+3]]:32-[[@LINE+3]]:37}: warning: unused function template
+  // CHECK-NEXT:   void templ(T) {}
+  // CHECK-NEXT:^{{$}}
+template  void templ(T) {}
+  // CHECK:  :{[[@LINE+3]]:22-[[@LINE+3]]:32}: warning: member function 'templ' is not needed
+  // CHECK-NEXT:   void templ(int) {}
+  // CHECK-NEXT:^~{{$}}
+template <> void templ(int) {}
+  // CHECK:  :{[[@LINE+3]]:22-[[@LINE+3]]:27}: warning: member function 'templ' is not needed
+  // CHECK-NEXT:   void templ(float) {}
+  // CHECK-NEXT:^{{$}}
+template <> void templ(float) {}
+
+  // CHECK:  :{[[@LINE+4]]:10-[[@LINE+4]]:13}: warning: unused function template
+  // CHECK-NEXT:   void foo() {
+  // CHECK-NEXT:^~~{{$}}
+template 
+void foo() {
+  func();
+  templ(0);
+  templ(0.0f);
+  templ(0.0);
+}
+};
+// CHECK:  :{[[@LINE+3]]:12-[[@LINE+3]]:23}: warning: unused function 'unused_func'
+// CHECK-NEXT:   static int unused_func(int aaa, char bbb) {
+// CHECK-NEXT:  ^~~{{$}}
+static int unused_func(int aaa, char bbb) {
+  int local = 0;
+  try{}
+  catch (int ¶m) {}
+  return 0;
+}
+
+// CHECK:  :{[[@LINE+4]]:6-[[@LINE+4]]:16}: warning: unused function template
+// CHECK-NEXT:   auto arrow_decl(T a, T b) ->
+// CHECK-NEXT:^~{{$}}
+template 
+auto arrow_decl(T a, T b) -> decltype(a + b) { thing(); return a + b; }
+
+// CHECK:  :{[[@LINE+4]]:6-[[@LINE+4]]:21}: warning: unused function 'arrow_decl'
+// CHECK-NEXT:   auto arrow_decl(int a, int b) ->
+// CHECK-NEXT:^~~{{$}}
+template <>
+auto arrow_decl(int a, int b) -> int { return a + b; }
+
+
+// CHECK:  :{[[@LINE+4]]:10-[[@LINE+4]]:20}: warning: unused function template
+// CHECK-NEXT:   static T func_templ(int bbb, T ccc) {
+// CHECK-NEXT:^~{{$}}
+template 
+static T func_templ(int bbb, T ccc) {
+  return ccc;
+}
+
+// CHECK:  :{[[@LINE+3]]:17-[[@LINE+3]]:32}: warning: function 'func_templ' is not needed
+// CHECK-NEXT:   int func_templ(int bbb, int ccc) {
+// CHECK-NEXT:   ^~~{{$}}
+template <> int func_templ(int bbb, int ccc) {
+  return bbb;
+}
+
+// CHECK:  :{[[@LINE+3]]:35-[[@LINE+3]]:47}: warning: unused function template
+// CHECK-NEXT:   static void never_called() {
+// CHECK-NEXT:   ^~~~{{$}}
+template  static void never_called() {
+  func_templ(0, 0);
+}
+
+// CHECK:  :{[[@LINE+3]]:22-[[@LINE+3]]:31}: warning: unused variable template
+// CHECK-NEXT:   int var_templ =
+// CHECK-NEXT:   ^{{$}}
+template  int var_templ = n * var_templ;
+// CHECK:  :{[[@LINE+3]]:17-[[@LINE+3]]:29}: warning: variable 'var_templ<0>' is not needed
+// CHECK-NEXT:   int var_templ<0> =
+// CHECK-NEXT:   ^~~~{{$}}
+template <> int var_templ<0> = 1;
+struct {
+// CHECK:  :{[[@LINE+3]]:8-[[@LINE+3]]:11}: warning: unused member function 'fun'
+// CHECK-NEXT:   void fun() {}
+// CHECK-NEXT:^~~{{$}}
+  void fun() {}
+// CHECK:  :{[[@LINE+3]]:3-[[@LINE+3]]:8}: warning: unused variable 'var_x'
+// CHECK-NEXT:   } var_x;
+// CHECK-NEX

[PATCH] D146242: [ARM] Fixing ABI mismatch for packed structs passed as function arguments

2023-06-16 Thread Momchil Velikov via Phabricator via cfe-commits
chill added a comment.

I was just thinking to LGTM it :)

IMHO, the alignment adjustment  happens because of C.4 (B.3 indeed leave the 
HFA/HVA unmodified).

> C.4   If the argument is an HFA, an HVA, a Quad-precision Floating-point or 
> short vector type then the NSAA is rounded up to the next multiple of 8 if 
> its natural alignment is ≤ 8 or the next multiple of 16 if its natural 
> alignment is ≥ 16.

Browsing the AAPCS HFA and HVA seem always treated the same, and looking at 
`bool AArch64ABIInfo::isHomogeneousAggregateBaseType(QualType Ty) const` it
recognized both FP types and 64- and 128- bit vectors, so we have uniform 
treatment there as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146242

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


[PATCH] D146242: [ARM] Fixing ABI mismatch for packed structs passed as function arguments

2023-06-16 Thread Momchil Velikov via Phabricator via cfe-commits
chill added inline comments.



Comment at: clang/test/CodeGen/aarch64-ABI-align-packed.c:34
 struct aligned_member_8 {
   uint16x8_t M0 __attribute((aligned (8))); // member alignment 16 since 
__attribute((aligned (n))) sets the minimum alignment
 };

JiruiWu wrote:
> chill wrote:
> > Don't you mean "`__attribute__((aligned(n)))` cannot decrease the minimum 
> > required alignment" ?
> > 
> > 
> I added this comment to explain that the natural alignment of the struct 
> `aligned_member_8` is 16-byte instead of 8-byte. In this test case the 
> alignment of  `M0` is 16 bytes, which is above the minimum required alignment 
> specified by `__attribute__((aligned(8)))`.
Yes, so the `__attribute__` does not actually set the minimum required 
alignment, 
it sets the member alignment to the maximum of the natural and the specified 
alignment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146242

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


[clang] 835cdcb - [Clang] Fix compare-record.c test on s390x (NFC)

2023-06-16 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2023-06-16T12:43:58+02:00
New Revision: 835cdcb9191fb8036f782ae532594c4e1f456ffc

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

LOG: [Clang] Fix compare-record.c test on s390x (NFC)

s390x looks through pointers when determining the "externally
visible vector ABI". For that reason, the test shows different
behavior just on that platform.

Adjust the test in the reverse direction of what I originall did:
Make sure that the type behind the pointer is always queried, by
dereferencing the pointer.

Added: 


Modified: 
clang/test/Modules/compare-record.c

Removed: 




diff  --git a/clang/test/Modules/compare-record.c 
b/clang/test/Modules/compare-record.c
index c5ce285aa77ee..60998696969e1 100644
--- a/clang/test/Modules/compare-record.c
+++ b/clang/test/Modules/compare-record.c
@@ -423,10 +423,13 @@ struct CompareDifferentFieldInIndirectStruct 
compareIndirectStruct;
 // expected-error@second-nested-struct.h:* 
{{'IndirectStruct::mismatchingField' from module 'Second' is not present in 
definition of 'struct IndirectStruct' in module 'First.Hidden'}}
 // expected-note@first-nested-struct.h:* {{declaration of 'mismatchingField' 
does not match}}
 #elif defined(CASE3)
-// This currently doesn't produce an error, because there is no dependency
-// on the layout of DirectStruct.
-// expected-no-diagnostics
+// expected-error@second-nested-struct.h:* 
{{'IndirectStruct::mismatchingField' from module 'Second' is not present in 
definition of 'struct IndirectStruct' in module 'First.Hidden'}}
+// expected-note@first-nested-struct.h:* {{declaration of 'mismatchingField' 
does not match}}
 struct CompareIndirectStructPointer compareIndirectStructPointer;
+struct DirectStruct test() {
+  // Make sure the type behind the pointer is inspected.
+  return *compareIndirectStructPointer.directFieldPointer;
+}
 #endif
 
 //--- include/first-anonymous.h



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


[PATCH] D153003: [ODRHash] Fix ODR hashing of template names

2023-06-16 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

> We can't say this abstractly. It should be fine to work in ODRHash for C++20 
> modules issues as long as we don't lose informations.

I honestly don't understand this: For the approach to work, we would need to 
hash the two cases of an unqualified and a qualified template to the same 
value. You oppose to this approach because it would lose information. I can 
only conclude that the approach doesn't work with `ODRHash`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153003

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


[clang] 2903a8a - [CGTypes] Remove recursion protection

2023-06-16 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2023-06-16T13:07:14+02:00
New Revision: 2903a8ab07260f9836db82b7e5330f1892830aca

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

LOG: [CGTypes] Remove recursion protection

With opaque pointers, it should no longer be necessary to protect
against recursion when converting Clang types to LLVM types, as
recursion can only be introduced via pointer types.

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenTypes.cpp
clang/lib/CodeGen/CodeGenTypes.h

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index e4836c850a157..30021794a0bb3 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -125,93 +125,9 @@ bool CodeGenTypes::isRecordLayoutComplete(const Type *Ty) 
const {
   return I != RecordDeclTypes.end() && !I->second->isOpaque();
 }
 
-static bool
-isSafeToConvert(QualType T, CodeGenTypes &CGT,
-llvm::SmallPtrSet &AlreadyChecked);
-
-
-/// isSafeToConvert - Return true if it is safe to convert the specified record
-/// decl to IR and lay it out, false if doing so would cause us to get into a
-/// recursive compilation mess.
-static bool
-isSafeToConvert(const RecordDecl *RD, CodeGenTypes &CGT,
-llvm::SmallPtrSet &AlreadyChecked) {
-  // If we have already checked this type (maybe the same type is used by-value
-  // multiple times in multiple structure fields, don't check again.
-  if (!AlreadyChecked.insert(RD).second)
-return true;
-
-  const Type *Key = CGT.getContext().getTagDeclType(RD).getTypePtr();
-
-  // If this type is already laid out, converting it is a noop.
-  if (CGT.isRecordLayoutComplete(Key)) return true;
-
-  // If this type is currently being laid out, we can't recursively compile it.
-  if (CGT.isRecordBeingLaidOut(Key))
-return false;
-
-  // If this type would require laying out bases that are currently being laid
-  // out, don't do it.  This includes virtual base classes which get laid out
-  // when a class is translated, even though they aren't embedded by-value into
-  // the class.
-  if (const CXXRecordDecl *CRD = dyn_cast(RD)) {
-for (const auto &I : CRD->bases())
-  if (!isSafeToConvert(I.getType()->castAs()->getDecl(), CGT,
-   AlreadyChecked))
-return false;
-  }
-
-  // If this type would require laying out members that are currently being 
laid
-  // out, don't do it.
-  for (const auto *I : RD->fields())
-if (!isSafeToConvert(I->getType(), CGT, AlreadyChecked))
-  return false;
-
-  // If there are no problems, lets do it.
-  return true;
-}
-
-/// isSafeToConvert - Return true if it is safe to convert this field type,
-/// which requires the structure elements contained by-value to all be
-/// recursively safe to convert.
-static bool
-isSafeToConvert(QualType T, CodeGenTypes &CGT,
-llvm::SmallPtrSet &AlreadyChecked) {
-  // Strip off atomic type sugar.
-  if (const auto *AT = T->getAs())
-T = AT->getValueType();
-
-  // If this is a record, check it.
-  if (const auto *RT = T->getAs())
-return isSafeToConvert(RT->getDecl(), CGT, AlreadyChecked);
-
-  // If this is an array, check the elements, which are embedded inline.
-  if (const auto *AT = CGT.getContext().getAsArrayType(T))
-return isSafeToConvert(AT->getElementType(), CGT, AlreadyChecked);
-
-  // Otherwise, there is no concern about transforming this.  We only care 
about
-  // things that are contained by-value in a structure that can have another
-  // structure as a member.
-  return true;
-}
-
-
-/// isSafeToConvert - Return true if it is safe to convert the specified record
-/// decl to IR and lay it out, false if doing so would cause us to get into a
-/// recursive compilation mess.
-static bool isSafeToConvert(const RecordDecl *RD, CodeGenTypes &CGT) {
-  // If no structs are being laid out, we can certainly do this one.
-  if (CGT.noRecordsBeingLaidOut()) return true;
-
-  llvm::SmallPtrSet AlreadyChecked;
-  return isSafeToConvert(RD, CGT, AlreadyChecked);
-}
-
 /// isFuncParamTypeConvertible - Return true if the specified type in a
 /// function parameter or result position can be converted to an IR type at 
this
-/// point.  This boils down to being whether it is complete, as well as whether
-/// we've temporarily deferred expanding the type because we're in a recursive
-/// context.
+/// point. This boils down to being whether it is complete.
 bool CodeGenTypes::isFuncParamTypeConvertible(QualType Ty) {
   // Some ABIs cannot have their member pointers represented in IR unless
   // certain circumstances have been reached.
@@ -223,21 +139,7 @@ bool CodeGenTypes::isFuncParamTypeConvertibl

[PATCH] D152999: [CGTypes] Remove recursion protection

2023-06-16 Thread Nikita Popov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2903a8ab0726: [CGTypes] Remove recursion protection 
(authored by nikic).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152999

Files:
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/CodeGenTypes.h

Index: clang/lib/CodeGen/CodeGenTypes.h
===
--- clang/lib/CodeGen/CodeGenTypes.h
+++ clang/lib/CodeGen/CodeGenTypes.h
@@ -78,20 +78,12 @@
   /// Hold memoized CGFunctionInfo results.
   llvm::FoldingSet FunctionInfos{FunctionInfosLog2InitSize};
 
-  /// This set keeps track of records that we're currently converting
-  /// to an IR type.  For example, when converting:
-  /// struct A { struct B { int x; } } when processing 'x', the 'A' and 'B'
-  /// types will be in this set.
-  llvm::SmallPtrSet RecordsBeingLaidOut;
-
   llvm::SmallPtrSet FunctionsBeingProcessed;
 
   /// True if we didn't layout a function due to a being inside
   /// a recursive struct conversion, set this to true.
   bool SkippedLayout;
 
-  SmallVector DeferredRecords;
-
   /// This map keeps cache of llvm::Types and maps clang::Type to
   /// corresponding llvm::Type.
   llvm::DenseMap TypeCache;
@@ -300,12 +292,6 @@
   bool isZeroInitializable(const RecordDecl *RD);
 
   bool isRecordLayoutComplete(const Type *Ty) const;
-  bool noRecordsBeingLaidOut() const {
-return RecordsBeingLaidOut.empty();
-  }
-  bool isRecordBeingLaidOut(const Type *Ty) const {
-return RecordsBeingLaidOut.count(Ty);
-  }
   unsigned getTargetAddressSpace(QualType T) const;
 };
 
Index: clang/lib/CodeGen/CodeGenTypes.cpp
===
--- clang/lib/CodeGen/CodeGenTypes.cpp
+++ clang/lib/CodeGen/CodeGenTypes.cpp
@@ -125,93 +125,9 @@
   return I != RecordDeclTypes.end() && !I->second->isOpaque();
 }
 
-static bool
-isSafeToConvert(QualType T, CodeGenTypes &CGT,
-llvm::SmallPtrSet &AlreadyChecked);
-
-
-/// isSafeToConvert - Return true if it is safe to convert the specified record
-/// decl to IR and lay it out, false if doing so would cause us to get into a
-/// recursive compilation mess.
-static bool
-isSafeToConvert(const RecordDecl *RD, CodeGenTypes &CGT,
-llvm::SmallPtrSet &AlreadyChecked) {
-  // If we have already checked this type (maybe the same type is used by-value
-  // multiple times in multiple structure fields, don't check again.
-  if (!AlreadyChecked.insert(RD).second)
-return true;
-
-  const Type *Key = CGT.getContext().getTagDeclType(RD).getTypePtr();
-
-  // If this type is already laid out, converting it is a noop.
-  if (CGT.isRecordLayoutComplete(Key)) return true;
-
-  // If this type is currently being laid out, we can't recursively compile it.
-  if (CGT.isRecordBeingLaidOut(Key))
-return false;
-
-  // If this type would require laying out bases that are currently being laid
-  // out, don't do it.  This includes virtual base classes which get laid out
-  // when a class is translated, even though they aren't embedded by-value into
-  // the class.
-  if (const CXXRecordDecl *CRD = dyn_cast(RD)) {
-for (const auto &I : CRD->bases())
-  if (!isSafeToConvert(I.getType()->castAs()->getDecl(), CGT,
-   AlreadyChecked))
-return false;
-  }
-
-  // If this type would require laying out members that are currently being laid
-  // out, don't do it.
-  for (const auto *I : RD->fields())
-if (!isSafeToConvert(I->getType(), CGT, AlreadyChecked))
-  return false;
-
-  // If there are no problems, lets do it.
-  return true;
-}
-
-/// isSafeToConvert - Return true if it is safe to convert this field type,
-/// which requires the structure elements contained by-value to all be
-/// recursively safe to convert.
-static bool
-isSafeToConvert(QualType T, CodeGenTypes &CGT,
-llvm::SmallPtrSet &AlreadyChecked) {
-  // Strip off atomic type sugar.
-  if (const auto *AT = T->getAs())
-T = AT->getValueType();
-
-  // If this is a record, check it.
-  if (const auto *RT = T->getAs())
-return isSafeToConvert(RT->getDecl(), CGT, AlreadyChecked);
-
-  // If this is an array, check the elements, which are embedded inline.
-  if (const auto *AT = CGT.getContext().getAsArrayType(T))
-return isSafeToConvert(AT->getElementType(), CGT, AlreadyChecked);
-
-  // Otherwise, there is no concern about transforming this.  We only care about
-  // things that are contained by-value in a structure that can have another
-  // structure as a member.
-  return true;
-}
-
-
-/// isSafeToConvert - Return true if it is safe to convert the specified record
-/// decl to IR and lay it out, false if doing so would cause us to get into a
-/// recursive compilation mess.
-static bool isSafeToCo

[PATCH] D149443: [ARM] add Thumb-1 8-bit movs/adds relocations to LLVM

2023-06-16 Thread John Brawn via Phabricator via cfe-commits
john.brawn accepted this revision.
john.brawn added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149443

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


[PATCH] D153033: [CLANG]Fix potential null pointer dereference bugs

2023-06-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:3368
 
-  VD = VD->getCanonicalDecl();
+  VD = cast(VD->getCanonicalDecl());
   auto I = FunctionGlobalizedDecls.find(CGF.CurFn);

This is unnecessary, `getCanonicalDecl()` can never return a null pointer (it 
will return `this`, at the very least)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153033

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


[PATCH] D153123: Fix diag for read-only target features

2023-06-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: tra, jhuber6, arsenm.
Herald added subscribers: kerbowa, jvesely.
Herald added a project: All.
yaxunl requested review of this revision.
Herald added subscribers: jplehr, sstefan1, wdng.
Herald added a reviewer: jdoerfert.

Currently the diag is emitted even when there is no
target feature specified on command line for OpenMP.
This is because the function to initialize feature map
is also used with cached feature string. The fix is to
only diag when the feature map is initialized with
feature strings from command line options.


https://reviews.llvm.org/D153123

Files:
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets.cpp
  clang/test/OpenMP/driver-openmp-amdgpu.c


Index: clang/test/OpenMP/driver-openmp-amdgpu.c
===
--- /dev/null
+++ clang/test/OpenMP/driver-openmp-amdgpu.c
@@ -0,0 +1,8 @@
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+// REQUIRES: clang-target-64-bits
+
+// Check no warnings about read-only feature emitted.
+// RUN: %clang %s -emit-llvm -S -fopenmp=libomp -nogpulib 
--offload-arch=gfx1030 \
+// RUN:   --offload-device-only -o - 2>&1 | FileCheck --check-prefix=CHECK %s
+// CHECK-NOT: warning: feature flag {{.*}} is ignored since the feature is 
read only
Index: clang/lib/Basic/Targets.cpp
===
--- clang/lib/Basic/Targets.cpp
+++ clang/lib/Basic/Targets.cpp
@@ -42,6 +42,7 @@
 #include "Targets/X86.h"
 #include "Targets/XCore.h"
 #include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticFrontend.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/TargetParser/Triple.h"
 
@@ -816,6 +817,13 @@
 
   // Compute the default target features, we need the target to handle this
   // because features may have dependencies on one another.
+  llvm::erase_if(Opts->FeaturesAsWritten, [&](StringRef Name) {
+if (Target->isReadOnlyFeature(Name.substr(1))) {
+  Diags.Report(diag::warn_fe_backend_readonly_feature_flag) << Name;
+  return true;
+}
+return false;
+  });
   if (!Target->initFeatureMap(Opts->FeatureMap, Diags, Opts->CPU,
   Opts->FeaturesAsWritten))
 return nullptr;
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -528,8 +528,6 @@
 // Apply the feature via the target.
 if (Name[0] != '+' && Name[0] != '-')
   Diags.Report(diag::warn_fe_backend_invalid_feature_flag) << Name;
-else if (isReadOnlyFeature(Name.substr(1)))
-  Diags.Report(diag::warn_fe_backend_readonly_feature_flag) << Name;
 else
   setFeatureEnabled(Features, Name.substr(1), Name[0] == '+');
   }


Index: clang/test/OpenMP/driver-openmp-amdgpu.c
===
--- /dev/null
+++ clang/test/OpenMP/driver-openmp-amdgpu.c
@@ -0,0 +1,8 @@
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+// REQUIRES: clang-target-64-bits
+
+// Check no warnings about read-only feature emitted.
+// RUN: %clang %s -emit-llvm -S -fopenmp=libomp -nogpulib --offload-arch=gfx1030 \
+// RUN:   --offload-device-only -o - 2>&1 | FileCheck --check-prefix=CHECK %s
+// CHECK-NOT: warning: feature flag {{.*}} is ignored since the feature is read only
Index: clang/lib/Basic/Targets.cpp
===
--- clang/lib/Basic/Targets.cpp
+++ clang/lib/Basic/Targets.cpp
@@ -42,6 +42,7 @@
 #include "Targets/X86.h"
 #include "Targets/XCore.h"
 #include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticFrontend.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/TargetParser/Triple.h"
 
@@ -816,6 +817,13 @@
 
   // Compute the default target features, we need the target to handle this
   // because features may have dependencies on one another.
+  llvm::erase_if(Opts->FeaturesAsWritten, [&](StringRef Name) {
+if (Target->isReadOnlyFeature(Name.substr(1))) {
+  Diags.Report(diag::warn_fe_backend_readonly_feature_flag) << Name;
+  return true;
+}
+return false;
+  });
   if (!Target->initFeatureMap(Opts->FeatureMap, Diags, Opts->CPU,
   Opts->FeaturesAsWritten))
 return nullptr;
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -528,8 +528,6 @@
 // Apply the feature via the target.
 if (Name[0] != '+' && Name[0] != '-')
   Diags.Report(diag::warn_fe_backend_invalid_feature_flag) << Name;
-else if (isReadOnlyFeature(Name.substr(1)))
-  Diags.Report(diag::warn_fe_backend_readonly_feature_flag) << Name;
 else
   setFeatureEnabled(Features, Name.substr(1), Name[0] == '+');
   }
___

[PATCH] D152021: [clang][AIX] Fix Overly Strict LTO Option Checking against `data-sections` when `mxcoff-roptr` is in Effect

2023-06-16 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 updated this revision to Diff 532099.
qiongsiwu1 added a comment.

Revert to the DataSections logic. It is better not to change that in this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152021

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/ppc-roptr.c


Index: clang/test/Driver/ppc-roptr.c
===
--- clang/test/Driver/ppc-roptr.c
+++ clang/test/Driver/ppc-roptr.c
@@ -12,7 +12,7 @@
 // RUN: %clang -### --target=powerpc-ibm-aix-xcoff %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=NO_ROPTR
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto %s 
2>&1 | \
-// RUN: FileCheck %s --check-prefixes=ROPTR,LINK,LTO_ROPTR
+// RUN: FileCheck %s 
--check-prefixes=NO_DATA_SECTION_ERR,ROPTR,LINK,LTO_ROPTR
 // RUN: touch %t.o
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %t.o 2>&1 | 
\
 // RUN: FileCheck %s --check-prefix=LINK
@@ -33,14 +33,14 @@
 // RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr 
-flto \
 // RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
 
-// ROPTR: "-mxcoff-roptr"
-// LINK: "-bforceimprw"
-// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
-// NO_ROPTR-NOT: "-mxcoff-roptr"
-// NO_ROPTR-NOT: "-bforceimprw"
-
 // DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with 
-fdata-sections
 // NO_DATA_SECTION_ERR-NOT: error: -mxcoff-roptr is supported only with 
-fdata-sections
 // TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 
'powerpc64le-unknown-linux-gnu'
 // TARGET_NOROPTR_ERR: error: unsupported option '-mno-xcoff-roptr' for target 
'powerpc64le-unknown-linux-gnu'
 // SHARED_ERR: error: -mxcoff-roptr is not supported with -shared
+
+// ROPTR: "-mxcoff-roptr"
+// LINK: "-bforceimprw"
+// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
+// NO_ROPTR-NOT: "-mxcoff-roptr"
+// NO_ROPTR-NOT: "-bforceimprw"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -727,13 +727,16 @@
 CmdArgs.push_back(
 Args.MakeArgString(Twine(PluginOptPrefix) + "-function-sections=0"));
 
+  bool DataSectionsTurnedOff = false;
   if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
UseSeparateSections))
 CmdArgs.push_back(
 Args.MakeArgString(Twine(PluginOptPrefix) + "-data-sections=1"));
-  else if (Args.hasArg(options::OPT_fno_data_sections))
+  else if (Args.hasArg(options::OPT_fno_data_sections)) {
+DataSectionsTurnedOff = true;
 CmdArgs.push_back(
 Args.MakeArgString(Twine(PluginOptPrefix) + "-data-sections=0"));
+  }
 
   if (Args.hasArg(options::OPT_mxcoff_roptr) ||
   Args.hasArg(options::OPT_mno_xcoff_roptr)) {
@@ -746,8 +749,10 @@
   << OptStr << ToolChain.getTriple().str();
 
 if (HasRoptr) {
-  if (!Args.hasFlag(options::OPT_fdata_sections,
-options::OPT_fno_data_sections, UseSeparateSections))
+  // The data sections option is on by default on AIX. We only need to 
error
+  // out when -fno-data-sections is specified explicitly to turn off data
+  // sections.
+  if (DataSectionsTurnedOff)
 D.Diag(diag::err_roptr_requires_data_sections);
 
   CmdArgs.push_back(


Index: clang/test/Driver/ppc-roptr.c
===
--- clang/test/Driver/ppc-roptr.c
+++ clang/test/Driver/ppc-roptr.c
@@ -12,7 +12,7 @@
 // RUN: %clang -### --target=powerpc-ibm-aix-xcoff %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=NO_ROPTR
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto %s 2>&1 | \
-// RUN: FileCheck %s --check-prefixes=ROPTR,LINK,LTO_ROPTR
+// RUN: FileCheck %s --check-prefixes=NO_DATA_SECTION_ERR,ROPTR,LINK,LTO_ROPTR
 // RUN: touch %t.o
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %t.o 2>&1 | \
 // RUN: FileCheck %s --check-prefix=LINK
@@ -33,14 +33,14 @@
 // RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr -flto \
 // RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
 
-// ROPTR: "-mxcoff-roptr"
-// LINK: "-bforceimprw"
-// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
-// NO_ROPTR-NOT: "-mxcoff-roptr"
-// NO_ROPTR-NOT: "-bforceimprw"
-
 // DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with -fdata-sections
 // NO_DATA_SECTION_ERR-NOT: error: -mxcoff-roptr is supported only with -fdata-sections
 // TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
 // TARGET_NOROPTR_ERR: error: unsupported option '-mno-xcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
 // SHARED_ERR: error: -mxcoff-roptr is

[clang-tools-extra] c9888dc - [clangd] Skip function parameter decls when evaluating variables on hover.

2023-06-16 Thread Viktoriia Bakalova via cfe-commits

Author: Viktoriia Bakalova
Date: 2023-06-16T12:09:28Z
New Revision: c9888dce44748bfbf3719351c3feb3359eaba017

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

LOG: [clangd] Skip function parameter decls when evaluating variables on hover.

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

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index d7a249c6bc21f..5184fcbe4b581 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -659,7 +659,7 @@ HoverInfo getHoverContents(const NamedDecl *D, const 
PrintingPolicy &PP,
 HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(), Ctx, PP);
 
   // Fill in value with evaluated initializer if possible.
-  if (const auto *Var = dyn_cast(D)) {
+  if (const auto *Var = dyn_cast(D); Var && !Var->isInvalidDecl()) {
 if (const Expr *Init = Var->getInit())
   HI.Value = printExprValue(Init, Ctx);
   } else if (const auto *ECD = dyn_cast(D)) {

diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 583310f29b63f..5338a680b787a 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -22,6 +22,7 @@
 
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -3722,6 +3723,34 @@ TEST(Hover, ForwardStructNoCrash) {
   EXPECT_EQ(*HI->Value, "&bar");
 }
 
+TEST(Hover, FunctionParameterDefaulValueNotEvaluatedOnInvalidDecls) {
+  struct {
+const char *const Code;
+const std::optional HoverValue;
+  } Cases[] = {
+  {R"cpp(
+// error-ok testing behavior on invalid decl
+class Foo {};
+void foo(Foo p^aram = nullptr);
+)cpp",
+   std::nullopt},
+  {R"cpp(
+class Foo {};
+void foo(Foo *p^aram = nullptr);
+)cpp",
+   "nullptr"},
+  };
+
+  for (const auto &C : Cases) {
+Annotations T(C.Code);
+TestTU TU = TestTU::withCode(T.code());
+auto AST = TU.build();
+auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+ASSERT_TRUE(HI);
+ASSERT_EQ(HI->Value, C.HoverValue);
+  }
+}
+
 TEST(Hover, DisableShowAKA) {
   Annotations T(R"cpp(
 using m_int = int;



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


[PATCH] D153015: [clangd] Skip function parameter decls when evaluating variables on hover.

2023-06-16 Thread Viktoriia Bakalova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
VitaNuo marked an inline comment as done.
Closed by commit rGc9888dce4474: [clangd] Skip function parameter decls when 
evaluating variables on hover. (authored by VitaNuo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153015

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -22,6 +22,7 @@
 
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -3722,6 +3723,34 @@
   EXPECT_EQ(*HI->Value, "&bar");
 }
 
+TEST(Hover, FunctionParameterDefaulValueNotEvaluatedOnInvalidDecls) {
+  struct {
+const char *const Code;
+const std::optional HoverValue;
+  } Cases[] = {
+  {R"cpp(
+// error-ok testing behavior on invalid decl
+class Foo {};
+void foo(Foo p^aram = nullptr);
+)cpp",
+   std::nullopt},
+  {R"cpp(
+class Foo {};
+void foo(Foo *p^aram = nullptr);
+)cpp",
+   "nullptr"},
+  };
+
+  for (const auto &C : Cases) {
+Annotations T(C.Code);
+TestTU TU = TestTU::withCode(T.code());
+auto AST = TU.build();
+auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+ASSERT_TRUE(HI);
+ASSERT_EQ(HI->Value, C.HoverValue);
+  }
+}
+
 TEST(Hover, DisableShowAKA) {
   Annotations T(R"cpp(
 using m_int = int;
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -659,7 +659,7 @@
 HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(), Ctx, PP);
 
   // Fill in value with evaluated initializer if possible.
-  if (const auto *Var = dyn_cast(D)) {
+  if (const auto *Var = dyn_cast(D); Var && !Var->isInvalidDecl()) {
 if (const Expr *Init = Var->getInit())
   HI.Value = printExprValue(Init, Ctx);
   } else if (const auto *ECD = dyn_cast(D)) {


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -22,6 +22,7 @@
 
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -3722,6 +3723,34 @@
   EXPECT_EQ(*HI->Value, "&bar");
 }
 
+TEST(Hover, FunctionParameterDefaulValueNotEvaluatedOnInvalidDecls) {
+  struct {
+const char *const Code;
+const std::optional HoverValue;
+  } Cases[] = {
+  {R"cpp(
+// error-ok testing behavior on invalid decl
+class Foo {};
+void foo(Foo p^aram = nullptr);
+)cpp",
+   std::nullopt},
+  {R"cpp(
+class Foo {};
+void foo(Foo *p^aram = nullptr);
+)cpp",
+   "nullptr"},
+  };
+
+  for (const auto &C : Cases) {
+Annotations T(C.Code);
+TestTU TU = TestTU::withCode(T.code());
+auto AST = TU.build();
+auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+ASSERT_TRUE(HI);
+ASSERT_EQ(HI->Value, C.HoverValue);
+  }
+}
+
 TEST(Hover, DisableShowAKA) {
   Annotations T(R"cpp(
 using m_int = int;
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -659,7 +659,7 @@
 HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(), Ctx, PP);
 
   // Fill in value with evaluated initializer if possible.
-  if (const auto *Var = dyn_cast(D)) {
+  if (const auto *Var = dyn_cast(D); Var && !Var->isInvalidDecl()) {
 if (const Expr *Init = Var->getInit())
   HI.Value = printExprValue(Init, Ctx);
   } else if (const auto *ECD = dyn_cast(D)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153015: [clangd] Skip function parameter decls when evaluating variables on hover.

2023-06-16 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added a comment.

Thanks!




Comment at: clang-tools-extra/clangd/unittests/HoverTests.cpp:3726
 
+TEST(Hover, FunctionParameterDefaulValueNotEvaluatedOnInvalidDecls) {
+  struct {

hokein wrote:
> nit: instead of creating a completely-new TEST, it seems simpler to just add 
> a testcase in the existing `TEST(Hover, All)`.
> 
> 
> ```
>{R"cpp(// Should not crash on an invalid param decl.
>   class Foo {};
>   // error-ok
>   void foo(Foo [[fo^o]] = nullptr);
>   )cpp",
>[](HoverInfo &HI) {
>  HI.Name = "foo";
>  HI.Type = "Foo";
>  HI.Kind = index::SymbolKind::Parameter;
>  HI.NamespaceScope = "";
>  HI.LocalScope = "foo::";
>  HI.Definition = "Foo foo = ";
>}},
> ```
I'm not sure I agree. The `Hover, All` test takes already about 5 seconds to 
scroll through on the screen :)

On top of that, other test cases that are a result of crash fixes seem to be 
separate too.
Therefore, I'd prefer to keep it as a separate test case for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153015

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


[PATCH] D153123: Fix diag for read-only target features

2023-06-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/test/OpenMP/driver-openmp-amdgpu.c:8
+// RUN:   --offload-device-only -o - 2>&1 | FileCheck --check-prefix=CHECK %s
+// CHECK-NOT: warning: feature flag {{.*}} is ignored since the feature is 
read only

Can you use -verify and expected-no-diagnostics? CHECK-NOT is really fragile


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

https://reviews.llvm.org/D153123

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


[PATCH] D146148: Float_t and double_t types shouldn't be modified by #pragma clang fp eval_method

2023-06-16 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added inline comments.



Comment at: clang/include/clang/Basic/IdentifierTable.h:89
+static constexpr int FirstInterestingIdentifierID = LastObjCKeywordID + 1;
+static constexpr int LastInterestingIdentifierID = LastObjCKeywordID + 
tok::NUM_INTERESTING_IDENTIFIERS;
+static constexpr int FirstBuiltinID = LastInterestingIdentifierID + 1;

rjmccall wrote:
> I see that I had a bug in my suggestion: I had meant to write 
> `LastInterestingIdentifierID = FirstInterestingIdentifierID + 
> tok::NUM_INTERESTING_IDENTIFIERS - 2;` but I left it in terms of 
> `LastObjCKeywordID` instead, making the ranges off by 1.  Your math fixes 
> that; sorry about that.  I do think it would be clearer if each of these 
> chained off the last one, the way I meant to have it, though.  So with your 
> ranges (which leave space to explicitly represent `not_interesting`), that 
> would look like `LastInterestingIdentifierID = FirstInterestingIdentifierID + 
> tok::NUM_INTERESTING_IDENTIFIERS - 1;`.
> 
> I'm not going to push you to not represent `not_interesting`, since you seem 
> to have deliberately changed things back that way, and I don't think it 
> matters that much.  Although maybe you did that just because it didn't work 
> in the code I gave you?  It would be more consistent with the other enums to 
> not explicitly represent `not_interesting`.
Sorry @rjmccall, I didn't mean to go against your proposal. It's a 
misunderstanding of my part. I was going through the debugger with an objc test 
case and was under the impression that not_keyword was added. Will make the 
change to not represent not_interesting.


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

https://reviews.llvm.org/D146148

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


[PATCH] D152924: [libLTO][AIX] Respect `-f[no]-integrated-as` on AIX

2023-06-16 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 updated this revision to Diff 532110.
qiongsiwu1 added a comment.

Revising the option processing logic to not pass in `-no-integrated-as=0`. 
Thanks @shchenz and @MaskRay for the feedback!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152924

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/lto-aix.c
  clang/test/Driver/lto.c
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/test/tools/llvm-lto/aix-sys-as.ll
  llvm/test/tools/llvm-lto/aix.ll
  llvm/tools/llc/llc.cpp

Index: llvm/tools/llc/llc.cpp
===
--- llvm/tools/llc/llc.cpp
+++ llvm/tools/llc/llc.cpp
@@ -106,10 +106,6 @@
  "'none' means that all ELF features can be used, "
  "regardless of binutils support"));
 
-static cl::opt
-NoIntegratedAssembler("no-integrated-as", cl::Hidden,
-  cl::desc("Disable integrated assembler"));
-
 static cl::opt
 PreserveComments("preserve-as-comments", cl::Hidden,
  cl::desc("Preserve Comments in outputted assembly"),
@@ -517,7 +513,6 @@
 
 Options.BinutilsVersion =
 TargetMachine::parseBinutilsVersion(BinutilsVersion);
-Options.DisableIntegratedAS = NoIntegratedAssembler;
 Options.MCOptions.ShowMCEncoding = ShowMCEncoding;
 Options.MCOptions.AsmVerbose = AsmVerbose;
 Options.MCOptions.PreserveAsmComments = PreserveComments;
Index: llvm/test/tools/llvm-lto/aix.ll
===
--- llvm/test/tools/llvm-lto/aix.ll
+++ llvm/test/tools/llvm-lto/aix.ll
@@ -1,4 +1,4 @@
-; REQUIRES: system-aix
+; REQUIRES: powerpc-registered-target
 ; RUN: llvm-as < %s > %t1
 ; RUN: llvm-lto %t1 | FileCheck %s
 
Index: llvm/test/tools/llvm-lto/aix-sys-as.ll
===
--- /dev/null
+++ llvm/test/tools/llvm-lto/aix-sys-as.ll
@@ -0,0 +1,12 @@
+; REQUIRES: system-aix
+; RUN: llvm-as < %s > %t1
+; RUN: llvm-lto -no-integrated-as=1 %t1 | FileCheck %s
+
+target triple = "powerpc-ibm-aix"
+
+define i32 @main() {
+entry:
+  ret i32 42
+}
+; CHECK: Wrote native object file
+
Index: llvm/lib/LTO/LTOCodeGenerator.cpp
===
--- llvm/lib/LTO/LTOCodeGenerator.cpp
+++ llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -244,7 +244,7 @@
 
 bool LTOCodeGenerator::useAIXSystemAssembler() {
   const auto &Triple = TargetMach->getTargetTriple();
-  return Triple.isOSAIX();
+  return Triple.isOSAIX() && Config.Options.DisableIntegratedAS;
 }
 
 bool LTOCodeGenerator::runAIXSystemAssembler(SmallString<128> &AssemblyFile) {
Index: llvm/lib/CodeGen/CommandFlags.cpp
===
--- llvm/lib/CodeGen/CommandFlags.cpp
+++ llvm/lib/CodeGen/CommandFlags.cpp
@@ -81,6 +81,7 @@
 CGOPT(bool, StackRealign)
 CGOPT(std::string, TrapFuncName)
 CGOPT(bool, UseCtors)
+CGOPT(bool, DisableIntegratedAS)
 CGOPT(bool, RelaxELFRelocations)
 CGOPT_EXP(bool, DataSections)
 CGOPT_EXP(bool, FunctionSections)
@@ -487,6 +488,11 @@
   cl::init(false));
   CGBINDOPT(XCOFFReadOnlyPointers);
 
+  static cl::opt DisableIntegratedAS(
+  "no-integrated-as", cl::desc("Disable integrated assembler"),
+  cl::init(false));
+  CGBINDOPT(DisableIntegratedAS);
+
 #undef CGBINDOPT
 
   mc::RegisterMCTargetOptionsFlags();
@@ -540,6 +546,7 @@
   Options.GuaranteedTailCallOpt = getEnableGuaranteedTailCallOpt();
   Options.StackSymbolOrdering = getStackSymbolOrdering();
   Options.UseInitArray = !getUseCtors();
+  Options.DisableIntegratedAS = getDisableIntegratedAS();
   Options.RelaxELFRelocations = getRelaxELFRelocations();
   Options.DataSections =
   getExplicitDataSections().value_or(TheTriple.hasDefaultDataSections());
Index: llvm/include/llvm/CodeGen/CommandFlags.h
===
--- llvm/include/llvm/CodeGen/CommandFlags.h
+++ llvm/include/llvm/CodeGen/CommandFlags.h
@@ -94,6 +94,8 @@
 
 bool getUseCtors();
 
+bool getDisableIntegratedAS();
+
 bool getRelaxELFRelocations();
 
 bool getDataSections();
Index: clang/test/Driver/lto.c
===
--- clang/test/Driver/lto.c
+++ clang/test/Driver/lto.c
@@ -105,3 +105,10 @@
 // FLTO-THIN: -flto=thin
 // FLTO-THIN-NOT: "-flto"
 // FLTO-THIN-NOT: -flto=full
+//
+
+// Check that using -fno-integrated-as produces a warning on Linux
+// RUN: %clang --target=x86_64-unknown-linux -### %s -fno-integrated-as \
+// RUN: -flto 2>&1 | FileCheck --check-prefix=NO-INTEGRATED-AS %s
+//
+// NO-INTEGRATED-AS: clang: warning: ignoring '-fno-integrated-as' option as it is not currently supported for target 'x86_64-

[PATCH] D153128: [AArch64][RCPC3] Add Neon intrinsics for LDAP1 and STL2

2023-06-16 Thread Lucas Prates via Phabricator via cfe-commits
pratlucas created this revision.
pratlucas added reviewers: tmatheson, vhscampos, dmgreen.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
pratlucas requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This adds new intrisics to support the LDAP1 and STL1 Advanced SIMD
(Neon) instructions introduced as part of FEAT_LRCPC3.
The new intrinsics `vldap1(q)_lane`/`vstl1(q)_lane` generate IR code
similar to the existing `vld1(q)_lane/st1(q)_lane` ones, but capturing
the difference in the atomic release/acquire memory model.

The LLVM code generation changes to ensure that this instruction pair
is lowered to the correct LDAP1/STL1 instructions will be covered in a
separate commit.

Based on a patch by Sam Elliott.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153128

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-ldst-one-rcpc3.c
  clang/utils/TableGen/NeonEmitter.cpp

Index: clang/utils/TableGen/NeonEmitter.cpp
===
--- clang/utils/TableGen/NeonEmitter.cpp
+++ clang/utils/TableGen/NeonEmitter.cpp
@@ -2086,12 +2086,13 @@
 
 std::string Name = Def->getName();
 // Omit type checking for the pointer arguments of vld1_lane, vld1_dup,
-// and vst1_lane intrinsics.  Using a pointer to the vector element
-// type with one of those operations causes codegen to select an aligned
-// load/store instruction.  If you want an unaligned operation,
-// the pointer argument needs to have less alignment than element type,
-// so just accept any pointer type.
-if (Name == "vld1_lane" || Name == "vld1_dup" || Name == "vst1_lane") {
+// vst1_lane, vldap1_lane, and vstl1_lane intrinsics.  Using a pointer to
+// the vector element type with one of those operations causes codegen to
+// select an aligned load/store instruction.  If you want an unaligned
+// operation, the pointer argument needs to have less alignment than element
+// type, so just accept any pointer type.
+if (Name == "vld1_lane" || Name == "vld1_dup" || Name == "vst1_lane" ||
+Name == "vldap1_lane" || Name == "vstl1_lane") {
   PtrArgNum = -1;
   HasConstPtr = false;
 }
Index: clang/test/CodeGen/aarch64-neon-ldst-one-rcpc3.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-neon-ldst-one-rcpc3.c
@@ -0,0 +1,201 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple aarch64-arm-none-eabi -target-feature +neon \
+// RUN:  -target-feature +rcpc3 -disable-O0-optnone -emit-llvm -o - %s \
+// RUN: | opt -S -passes=mem2reg | FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+
+// CHECK-LABEL: @test_vldap1q_lane_u64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <2 x i64> [[B:%.*]] to <16 x i8>
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <16 x i8> [[TMP0]] to <2 x i64>
+// CHECK-NEXT:[[TMP2:%.*]] = load atomic i64, ptr [[A:%.*]] acquire, align 8
+// CHECK-NEXT:[[VLDAP1_LANE:%.*]] = insertelement <2 x i64> [[TMP1]], i64 [[TMP2]], i32 1
+// CHECK-NEXT:ret <2 x i64> [[VLDAP1_LANE]]
+//
+uint64x2_t test_vldap1q_lane_u64(uint64_t  *a, uint64x2_t b) {
+  return vldap1q_lane_u64(a, b, 1);
+}
+
+// CHECK-LABEL: @test_vldap1q_lane_s64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <2 x i64> [[B:%.*]] to <16 x i8>
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <16 x i8> [[TMP0]] to <2 x i64>
+// CHECK-NEXT:[[TMP2:%.*]] = load atomic i64, ptr [[A:%.*]] acquire, align 8
+// CHECK-NEXT:[[VLDAP1_LANE:%.*]] = insertelement <2 x i64> [[TMP1]], i64 [[TMP2]], i32 1
+// CHECK-NEXT:ret <2 x i64> [[VLDAP1_LANE]]
+//
+int64x2_t test_vldap1q_lane_s64(int64_t  *a, int64x2_t b) {
+  return vldap1q_lane_s64(a, b, 1);
+}
+
+// CHECK-LABEL: @test_vldap1q_lane_f64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <2 x double> [[B:%.*]] to <16 x i8>
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <16 x i8> [[TMP0]] to <2 x double>
+// CHECK-NEXT:[[TMP2:%.*]] = load atomic double, ptr [[A:%.*]] acquire, align 8
+// CHECK-NEXT:[[VLDAP1_LANE:%.*]] = insertelement <2 x double> [[TMP1]], double [[TMP2]], i32 1
+// CHECK-NEXT:ret <2 x double> [[VLDAP1_LANE]]
+//
+float64x2_t test_vldap1q_lane_f64(float64_t  *a, float64x2_t b) {
+  return vldap1q_lane_f64(a, b, 1);
+}
+
+// CHECK-LABEL: @test_vldap1q_lane_p64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <2 x i64> [[B:%.*]] to <16 x i8>
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <16 x i8> [[TMP0]] to <2 x i64>
+// CHECK-NEXT:[[TMP2:%.*]] = load atomic i64, ptr [[A:%.*]] acquire, align 8
+// CHECK-NEXT:[[VLDAP1_LANE:%.*]] = insertelement <2 x i64> [[TMP1]], i64 [[TMP2]], i32 1
+// CHECK-NEXT:ret <2 x i64> [[VLDAP1_LANE]

[PATCH] D152924: [libLTO][AIX] Respect `-f[no]-integrated-as` on AIX

2023-06-16 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 marked 3 inline comments as done.
qiongsiwu1 added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:700
+CmdArgs.push_back(Args.MakeArgString(
+Twine(PluginOptPrefix) + "-no-integrated-as=" + NoIntegratedAs));
+  else if (!UseIntegratedAs) {

MaskRay wrote:
> shchenz wrote:
> > qiongsiwu1 wrote:
> > > shchenz wrote:
> > > > qiongsiwu1 wrote:
> > > > > shchenz wrote:
> > > > > > Seems other options leverage the default value in the back end, for 
> > > > > > example the default value for `DisableIntegratedAS` in backend is 
> > > > > > false, so when the front end requires integrated-as, maybe we can 
> > > > > > save the option here?
> > > > > Ah thanks for the comment! 
> > > > > 
> > > > > > maybe we can save the option here?
> > > > > 
> > > > > Could you help me understand what we mean by "the option"? Do we mean 
> > > > > saving (or using?) the value of `-f[no]-integrated-as` explicitly 
> > > > > here somehow instead of relying on `ToolChain.useIntegratedAs()`? How 
> > > > > do we intend to use the saved option value? My understanding is that 
> > > > > `DisableIntegratedAS` takes its value from the option 
> > > > > `-no-integrated-as` if `-no-integrated-as` is specified. As pointed 
> > > > > out eariler, `DisableIntegratedAS` is false by default. This code 
> > > > > explicitly sets `-no-integrated-as` to `0` or `1`, so for the LTO use 
> > > > > case, we overwrite the back end default since the option is always 
> > > > > present. 
> > > > For example, if front-end requires to use integrated-assembler which is 
> > > > same with back-end's default value, we don't need to pass 
> > > > `-no-integrated-as=0`? We only pass the option `-no-integrated-as=1` 
> > > > when `if (IsOSAIX && !UseIntegratedAs)`.
> > > Ah I see! Thanks for the clarification! 
> > > 
> > > @w2yehia and I discussed this and we preferred setting the option 
> > > explicitly regardless of the backend's default. The reason was that we 
> > > did not want to leave a hanging case where the option was not passed to 
> > > the backend, a case in which we would rely on a non-local 
> > > option(`DisableIntegratedAS`)'s default value to control the backend. In 
> > > other words, always passing in the option allowed us to reason about this 
> > > code locally within this file. @w2yehia feel free to chime in if I am not 
> > > describing our discussion correctly. 
> > > 
> > > Could you help me understand the benefit of not passing in the option for 
> > > the default case? 
> > > Could you help me understand the benefit of not passing in the option for 
> > > the default case?
> > 
> > Too many options pass from front-end to back-end is a reason. And another 
> > reason is: I met one case that there is a back-end option has no default 
> > value, so each front-end, like clang and FORTRAN will have to explicitly 
> > pass the same option. I was asked to set a default in the back-end, so no 
> > need to explicitly set the options in each front-end.
> > 
> > If what I read is right, some bool type options like `EmulatedTLS`, 
> > `EnableStackSizeSection` are only passed when their values are not the same 
> > with the back-end's default.
> > 
> > I am ok to keep it as now if you guys already have an agreement. This is 
> > just minor I think.
> If you are going to add `-no-integrated-as=0`, I suggest that you rename the 
> option to `-integrated-as` and use `-integrated-as=1` instead.
`-no-integrated-as=0` is no longer added. The backend default will take care of 
the case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152924

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


[PATCH] D153130: [Clang][AArch64] Implement ACLE feature macro for FEAT_LRCPC3

2023-06-16 Thread Lucas Prates via Phabricator via cfe-commits
pratlucas created this revision.
pratlucas added reviewers: tmatheson, vhscampos.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
pratlucas requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This implements the new value for the `__ARM_FEATURE_RCPC` feature
macro, which was introduced to the ACLE to indicate the availability of
FEAT_LRCPC3.

More details can be found on:
https://github.com/ARM-software/acle/blob/main/main/acle.md#rcpc


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153130

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/test/Preprocessor/aarch64-target-features.c


Index: clang/test/Preprocessor/aarch64-target-features.c
===
--- clang/test/Preprocessor/aarch64-target-features.c
+++ clang/test/Preprocessor/aarch64-target-features.c
@@ -27,6 +27,7 @@
 // CHECK: __ARM_FEATURE_LDREX 0xF
 // CHECK: __ARM_FEATURE_NUMERIC_MAXMIN 1
 // CHECK-NOT: __ARM_FEATURE_RCPC 1
+// CHECK-NOT: __ARM_FEATURE_RCPC 3
 // CHECK-NOT: __ARM_FEATURE_SHA2 1
 // CHECK-NOT: __ARM_FEATURE_SHA3 1
 // CHECK-NOT: __ARM_FEATURE_SHA512 1
@@ -612,3 +613,6 @@
 
 // RUN: %clang --target=aarch64 -march=armv8.2-a+rcpc -x c -E -dM %s -o - | 
FileCheck --check-prefix=CHECK-RCPC %s
 // CHECK-RCPC: __ARM_FEATURE_RCPC 1
+
+// RUN: %clang --target=aarch64 -march=armv8.2-a+rcpc3 -x c -E -dM %s -o - | 
FileCheck --check-prefix=CHECK-RCPC3 %s
+// CHECK-RCPC3: __ARM_FEATURE_RCPC 3
Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -82,6 +82,7 @@
   bool HasNoSVE = false;
   bool HasFMV = true;
   bool HasGCS = false;
+  bool HasRCPC3 = false;
 
   const llvm::AArch64::ArchInfo *ArchInfo = &llvm::AArch64::ARMV8A;
 
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -415,7 +415,9 @@
   if (HasCRC)
 Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
 
-  if (HasRCPC)
+  if (HasRCPC3)
+Builder.defineMacro("__ARM_FEATURE_RCPC", "3");
+  else if (HasRCPC)
 Builder.defineMacro("__ARM_FEATURE_RCPC", "1");
 
   if (HasFMV)
@@ -671,6 +673,7 @@
   .Case("bti", HasBTI)
   .Cases("ls64", "ls64_v", "ls64_accdata", HasLS64)
   .Case("wfxt", HasWFxT)
+  .Case("rcpc3", HasRCPC3)
   .Default(false);
 }
 
@@ -928,6 +931,8 @@
   HasD128 = true;
 if (Feature == "+gcs")
   HasGCS = true;
+if (Feature == "+rcpc3")
+  HasRCPC3 = true;
   }
 
   // Check features that are manually disabled by command line options.


Index: clang/test/Preprocessor/aarch64-target-features.c
===
--- clang/test/Preprocessor/aarch64-target-features.c
+++ clang/test/Preprocessor/aarch64-target-features.c
@@ -27,6 +27,7 @@
 // CHECK: __ARM_FEATURE_LDREX 0xF
 // CHECK: __ARM_FEATURE_NUMERIC_MAXMIN 1
 // CHECK-NOT: __ARM_FEATURE_RCPC 1
+// CHECK-NOT: __ARM_FEATURE_RCPC 3
 // CHECK-NOT: __ARM_FEATURE_SHA2 1
 // CHECK-NOT: __ARM_FEATURE_SHA3 1
 // CHECK-NOT: __ARM_FEATURE_SHA512 1
@@ -612,3 +613,6 @@
 
 // RUN: %clang --target=aarch64 -march=armv8.2-a+rcpc -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-RCPC %s
 // CHECK-RCPC: __ARM_FEATURE_RCPC 1
+
+// RUN: %clang --target=aarch64 -march=armv8.2-a+rcpc3 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-RCPC3 %s
+// CHECK-RCPC3: __ARM_FEATURE_RCPC 3
Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -82,6 +82,7 @@
   bool HasNoSVE = false;
   bool HasFMV = true;
   bool HasGCS = false;
+  bool HasRCPC3 = false;
 
   const llvm::AArch64::ArchInfo *ArchInfo = &llvm::AArch64::ARMV8A;
 
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -415,7 +415,9 @@
   if (HasCRC)
 Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
 
-  if (HasRCPC)
+  if (HasRCPC3)
+Builder.defineMacro("__ARM_FEATURE_RCPC", "3");
+  else if (HasRCPC)
 Builder.defineMacro("__ARM_FEATURE_RCPC", "1");
 
   if (HasFMV)
@@ -671,6 +673,7 @@
   .Case("bti", HasBTI)
   .Cases("ls64", "ls64_v", "ls64_accdata", HasLS64)
   .Case("wfxt", HasWFxT)
+  .Case("rcpc3", HasRCPC3)
   .Default(false);
 }
 
@@ -928,6 +931,8 @@
   HasD128 = true;
 if (Feature == "+gcs")
   HasGCS = true;
+if (Feature == "+rcpc3")
+  HasRCPC3 = true;
   }
 
   // Check features that are manually disabled by command line options.
___
cfe-commits mailing

[PATCH] D152924: [libLTO][AIX] Respect `-f[no]-integrated-as` on AIX

2023-06-16 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 marked an inline comment as done.
qiongsiwu1 added a comment.

In D152924#4426895 , @shchenz wrote:

> Seems passing `-Wl,-bplugin_opt:-no-integrated-as=1` from clang driver does 
> not work as expected. Is this expected or by design(We can only use 
> -fno-integrated-as but no -Wl,-bplugin_opt:-no-integrated-as=1)?
>
>   clang -flto -Wl,-bplugin_opt:-no-integrated-as=1 *.c -v
> -bplugin_opt:-no-integrated-as=1 -bplugin:../lib/libLTO.so 
> -bplugin_opt:-mcpu=pwr7 -bplugin_opt:-no-integrated-as=0 ;;; Note the second 
> -no-integrated-as=0 pass from clang front-end.

Thanks for catching this! The latest patch fixed the problem. As you rightly 
pointed out, always passing in ` -no-integrated-as=0` by default interferes 
with uses such as above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152924

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


[PATCH] D146242: [ARM] Fixing ABI mismatch for packed structs passed as function arguments

2023-06-16 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson added a comment.

In D146242#4427707 , @chill wrote:

> I was just thinking to LGTM it :)
>
> IMHO, the alignment adjustment  happens because of C.4 (B.3 indeed leave the 
> HFA/HVA unmodified).
>
>> C.4  If the argument is an HFA, an HVA, a Quad-precision Floating-point or 
>> short vector type then the NSAA is rounded up to the next multiple of 8 if 
>> its natural alignment is ≤ 8 or the next multiple of 16 if its natural 
>> alignment is ≥ 16.

I think that C2 would be hit first, suggesting it should be allocated a SIMD 
register and alignment should be irrelevant, assuming sufficient registers:

> C.2 If the argument is an HFA or an HVA and there are sufficient unallocated 
> SIMD and Floating-point registers (NSRN + number of members ≤ 8), then the 
> argument is allocated to SIMD and Floating-point registers (with one register 
> per member of the HFA or HVA). The NSRN is incremented by the number of 
> registers used. The argument has now been allocated.

If not enough registers, the size also needs rounded up:

> C.3 If the argument is an HFA or an HVA then the NSRN is set to 8 and the 
> size of the argument is rounded up to the nearest multiple of 8 bytes.

After that C4 would indeed be hit. However C4 differs from B6 
, in that C4 rounds up to the nearest multiple of 
8 or 16 (which is not what the patch currently does) whereas B6 
 restricts it to either 6 or 16 (which this what 
this patch does, but shouldn't apply to HVAs).

The final rule that actually does the allocation is C6:

> C.6 If the argument is an HFA, an HVA, a Half-, Single-, Double- or Quad- 
> precision Floating-point or short vector type, then the argument is copied to 
> memory at the adjusted NSAA. The NSAA is incremented by the size of the 
> argument. The argument has now been allocated.

(This is all in reference to HVA types like `struct { uint8x16_t m; };`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146242

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


[PATCH] D153131: [clang analysis][thread-safety] Handle return-by-reference...

2023-06-16 Thread Clement Courbet via Phabricator via cfe-commits
courbet created this revision.
courbet added a reviewer: delesley.
Herald added a reviewer: NoQ.
Herald added a project: All.
courbet requested review of this revision.
Herald added a project: clang.

...of guarded variables, when the function is not marked as requiring locks:

  class Return {
Mutex mu;
Foo foo GUARDED_BY(mu);
  
Foo &returns_ref_locked() {
  MutexLock lock(&mu);
  return foo;  // BAD
}
  
Foo &returns_ref_locks_required() SHARED_LOCKS_REQUIRED(mu) {
  return foo;  // OK
}
  };

This is implemented as `-Wthread-safety-return` and not part of
`-Wthread-safety` for now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153131

Files:
  clang/include/clang/Analysis/Analyses/ThreadSafety.h
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Analysis/ThreadSafety.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/SemaCXX/warn-thread-safety-analysis.cpp

Index: clang/test/SemaCXX/warn-thread-safety-analysis.cpp
===
--- clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=0 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=1 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wthread-safety -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=0 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wthread-safety -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety -Wthread-safety-return -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=0 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety -Wthread-safety-return -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wthread-safety -Wthread-safety-return -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=0 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wthread-safety -Wthread-safety-return -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=1 %s
 
 // FIXME: should also run  %clang_cc1 -fsyntax-only -verify -Wthread-safety -std=c++11 -Wc++98-compat %s
 // FIXME: should also run  %clang_cc1 -fsyntax-only -verify -Wthread-safety %s
@@ -5580,6 +5580,41 @@
   }
 };
 
+class Return {
+  Mutex mu;
+  Foo foo GUARDED_BY(mu);
+
+  Foo returns_value_locked() {
+MutexLock lock(&mu);
+return foo;
+  }
+
+  Foo returns_value_locks_required() EXCLUSIVE_LOCKS_REQUIRED(mu) {
+return foo;
+  }
+
+  Foo returns_value_not_locked() {
+return foo;   // expected-warning {{reading variable 'foo' requires holding mutex 'mu'}}
+  }
+
+  Foo &returns_ref() {
+return foo;   // expected-warning {{returning variable 'foo' by reference requires holding mutex 'mu'}}
+  }
+
+  Foo &returns_ref_locked() {
+MutexLock lock(&mu);
+return foo;   // expected-warning {{returning variable 'foo' by reference requires holding mutex 'mu'}}
+  }
+
+  Foo &returns_ref_locks_required() SHARED_LOCKS_REQUIRED(mu) {
+return foo;
+  }
+
+  Foo *returns_ptr() {
+return &foo;  // FIXME -- Do we want to warn on this ?
+  }
+};
+
 
 }  // end namespace PassByRefTest
 
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -1971,6 +1971,9 @@
 case POK_PtPassByRef:
   DiagID = diag::warn_pt_guarded_pass_by_reference;
   break;
+case POK_ReturnByRef:
+  DiagID = diag::warn_guarded_return_by_reference;
+  break;
   }
   PartialDiagnosticAt Warning(Loc, S.PDiag(DiagID) << Kind
<< D
@@ -2001,6 +2004,9 @@
 case POK_PtPassByRef:
   DiagID = diag::warn_pt_guarded_pass_by_reference;
   break;
+case POK_ReturnByRef:
+  DiagID = diag::warn_guarded_return_by_reference;
+  break;
   }
   PartialDiagnosticAt Warning(Loc, S.PDiag(DiagID) << Kind
<< D
Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -41,6 +41,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Immuta

[PATCH] D149437: [clangd] Emit ChangeAnnotation label and description for include-cleaner diagnostics.

2023-06-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 532117.
hokein marked 2 inline comments as done.
hokein added a comment.

rebase, and address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149437

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/test/include-cleaner-batch-fix.test

Index: clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
===
--- clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
+++ clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
@@ -118,7 +118,7 @@
 # CHECK-NEXT: "version": 0
 # CHECK-NEXT:   }
 ---
-{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///simple.cpp"},"range":{"start":{"line":2,"character":1},"end":{"line":2,"character":4}},"context":{"diagnostics":[{"range":{"start": {"line": 2, "character": 1}, "end": {"line": 2, "character": 4}},"severity":3,"message":"No header providing \"Foo\" is directly included (fixes available)", "code": "missing-includes", "source": "clangd"}]}}}
+{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///simple.cpp"},"range":{"start":{"line":2,"character":1},"end":{"line":2,"character":4}},"context":{"diagnostics":[{"range":{"start": {"line": 2, "character": 1}, "end": {"line": 2, "character": 4}},"severity":2,"message":"No header providing \"Foo\" is directly included (fixes available)", "code": "missing-includes", "source": "clangd"}]}}}
 #  CHECK:  "id": 2,
 # CHECK-NEXT:  "jsonrpc": "2.0",
 # CHECK-NEXT:  "result": [
@@ -158,11 +158,13 @@
 # CHECK-NEXT:{
 # CHECK-NEXT:  "changeAnnotations": {
 # CHECK-NEXT:"AddAllMissingIncludes0": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "description": "Provides Foo",
+# CHECK-NEXT:  "label": "{{.*}}foo.h{{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:},
 # CHECK-NEXT:"AddAllMissingIncludes1": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "description": "Provides Bar",
+# CHECK-NEXT:  "label": "{{.*}}bar.h{{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:}
 # CHECK-NEXT:  },
@@ -171,7 +173,7 @@
 # CHECK-NEXT:  "edits": [
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes0",
-# CHECK-NEXT:  "newText": "#include {{.*}}bar.h{{.*}}",
+# CHECK-NEXT:  "newText": "#include {{.*}}foo.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,
@@ -185,7 +187,7 @@
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes1",
-# CHECK-NEXT:  "newText": "#include {{.*}}foo.h{{.*}}",
+# CHECK-NEXT:  "newText": "#include {{.*}}bar.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,
@@ -214,19 +216,21 @@
 # CHECK-NEXT:{
 # CHECK-NEXT:  "changeAnnotations": {
 # CHECK-NEXT:"AddAllMissingIncludes0": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "description": "Provides Foo",
+# CHECK-NEXT:  "label": "{{.*}}foo.h{{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:},
 # CHECK-NEXT:"AddAllMissingIncludes1": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "description": "Provides Bar",
+# CHECK-NEXT:  "label": "{{.*}}bar.h{{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:},
 # CHECK-NEXT:"RemoveAllUnusedIncludes0": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "label": "Remove {{.*}}all1.h{{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:},
 # CHECK-NEXT:"RemoveAllUnusedIncludes1": {
-# CHECK-NEXT:  "label": "",
+# CHECK-NEXT:  "label": "Remove {{.*}}all2.h{{.*}}",
 # CHECK-NEXT:  "needsConfirmation": true
 # CHECK-NEXT:}
 # CHECK-NEXT:  },
@@ -263,7 +267,7 @@
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes0",
-# CHECK-NEXT:  "newText": "#include {{.*}}bar.h{{.*}}",
+# CHECK-NEXT:  "newText": "#include {{.*}}foo.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "char

[PATCH] D153132: [clang analysis][NFCI] Preparatory work for D153131.

2023-06-16 Thread Clement Courbet via Phabricator via cfe-commits
courbet created this revision.
courbet added a reviewer: delesley.
Herald added a reviewer: NoQ.
Herald added a project: All.
courbet requested review of this revision.
Herald added a project: clang.

Refactoring in preparation for D153131 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153132

Files:
  clang/lib/Analysis/ThreadSafety.cpp

Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -1016,6 +1016,19 @@
 
   BeforeSet *GlobalBeforeSet;
 
+  void warnIfMutexNotHeld(const FactSet &FSet, const NamedDecl *D,
+  const Expr *Exp, AccessKind AK, Expr *MutexExp,
+  ProtectedOperationKind POK, til::LiteralPtr *Self,
+  SourceLocation Loc);
+  void warnIfMutexHeld(const FactSet &FSet, const NamedDecl *D, const Expr *Exp,
+   Expr *MutexExp, til::LiteralPtr *Self,
+   SourceLocation Loc);
+
+  void checkAccess(const FactSet &FSet, const Expr *Exp, AccessKind AK,
+   ProtectedOperationKind POK);
+  void checkPtAccess(const FactSet &FSet, const Expr *Exp, AccessKind AK,
+ ProtectedOperationKind POK);
+
 public:
   ThreadSafetyAnalyzer(ThreadSafetyHandler &H, BeforeSet* Bset)
   : Arena(&Bpa), SxBuilder(Arena), Handler(H), GlobalBeforeSet(Bset) {}
@@ -1525,6 +1538,7 @@
 /// output error messages related to missing locks.
 /// FIXME: In future, we may be able to not inherit from a visitor.
 class BuildLockset : public ConstStmtVisitor {
+  using VisitorBase = ConstStmtVisitor;
   friend class ThreadSafetyAnalyzer;
 
   ThreadSafetyAnalyzer *Analyzer;
@@ -1535,16 +1549,15 @@
   unsigned CtxIndex;
 
   // helper functions
-  void warnIfMutexNotHeld(const NamedDecl *D, const Expr *Exp, AccessKind AK,
-  Expr *MutexExp, ProtectedOperationKind POK,
-  til::LiteralPtr *Self, SourceLocation Loc);
-  void warnIfMutexHeld(const NamedDecl *D, const Expr *Exp, Expr *MutexExp,
-   til::LiteralPtr *Self, SourceLocation Loc);
 
   void checkAccess(const Expr *Exp, AccessKind AK,
-   ProtectedOperationKind POK = POK_VarAccess);
+   ProtectedOperationKind POK = POK_VarAccess) {
+Analyzer->checkAccess(FSet, Exp, AK, POK);
+  }
   void checkPtAccess(const Expr *Exp, AccessKind AK,
- ProtectedOperationKind POK = POK_VarAccess);
+ ProtectedOperationKind POK = POK_VarAccess) {
+Analyzer->checkPtAccess(FSet, Exp, AK, POK);
+  }
 
   void handleCall(const Expr *Exp, const NamedDecl *D,
   til::LiteralPtr *Self = nullptr,
@@ -1556,7 +1569,7 @@
 
 public:
   BuildLockset(ThreadSafetyAnalyzer *Anlzr, CFGBlockInfo &Info)
-  : ConstStmtVisitor(), Analyzer(Anlzr), FSet(Info.EntrySet),
+  : VisitorBase(), Analyzer(Anlzr), FSet(Info.EntrySet),
 LVarCtx(Info.EntryContext), CtxIndex(Info.EntryIndex) {}
 
   void VisitUnaryOperator(const UnaryOperator *UO);
@@ -1572,17 +1585,14 @@
 
 /// Warn if the LSet does not contain a lock sufficient to protect access
 /// of at least the passed in AccessKind.
-void BuildLockset::warnIfMutexNotHeld(const NamedDecl *D, const Expr *Exp,
-  AccessKind AK, Expr *MutexExp,
-  ProtectedOperationKind POK,
-  til::LiteralPtr *Self,
-  SourceLocation Loc) {
+void ThreadSafetyAnalyzer::warnIfMutexNotHeld(
+const FactSet &FSet, const NamedDecl *D, const Expr *Exp, AccessKind AK,
+Expr *MutexExp, ProtectedOperationKind POK, til::LiteralPtr *Self,
+SourceLocation Loc) {
   LockKind LK = getLockKindFromAccessKind(AK);
-
-  CapabilityExpr Cp =
-  Analyzer->SxBuilder.translateAttrExpr(MutexExp, D, Exp, Self);
+  CapabilityExpr Cp = SxBuilder.translateAttrExpr(MutexExp, D, Exp, Self);
   if (Cp.isInvalid()) {
-warnInvalidLock(Analyzer->Handler, MutexExp, D, Exp, Cp.getKind());
+warnInvalidLock(Handler, MutexExp, D, Exp, Cp.getKind());
 return;
   } else if (Cp.shouldIgnore()) {
 return;
@@ -1590,68 +1600,67 @@
 
   if (Cp.negative()) {
 // Negative capabilities act like locks excluded
-const FactEntry *LDat = FSet.findLock(Analyzer->FactMan, !Cp);
+const FactEntry *LDat = FSet.findLock(FactMan, !Cp);
 if (LDat) {
-  Analyzer->Handler.handleFunExcludesLock(
-  Cp.getKind(), D->getNameAsString(), (!Cp).toString(), Loc);
-  return;
+Handler.handleFunExcludesLock(Cp.getKind(), D->getNameAsString(),
+  (!Cp).toString(), Loc);
+return;
 }
 
 // If this does not refer to a negative capability in the same class,
 // then stop here.
-if (!Analyze

[PATCH] D149437: [clangd] Emit ChangeAnnotation label and description for include-cleaner diagnostics.

2023-06-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:169
 
-std::vector generateMissingIncludeDiagnostics(
+using MissingIncludeEdits = llvm::MapVector;
+MissingIncludeEdits generateMissingIncludeEdits(

kadircet wrote:
> what do we gain by preserving the insertion order here exactly?
> 
> in `generateMissingIncludeDiagnostics`, we already traverse using the order 
> of `MissingIncludeDiagInfo`s and inside `addAllMissingIncludes` the order we 
> preserved here (diagnostic order) doesn't really make much sense, we probably 
> should generate fixes in the order of insertion location, or header spelling.
> 
> so what about just using a DenseMap ?
The reason was that we need a deterministic-order for visting 
`MissingIncludeEdits`, otherwise that batch-fix lit test might fail from time 
to time. 

particularly, in `addAllMissingIncludes`, we generate a `Fix` by iterating 
`MissingIncludeEdits`, we construct the `Fix.Edits`, and `Fix.Annotations`.

- For `Fix.Edits`, as you pointed out in another comment, we can sort it by 
(range, newText), to make the case where multiple #includes insertion are at 
the same place better;
- For `Fix.Annotations`, this is a bit hard to do a sort afterward as we 
construct the ID + Annotation, but luckily the final order doesn't matter 
there, we only need a deterministic order to make lit test happy.

The other alternative is to switch `MissingIncludeEdits` to a `vector<{Header, 
TextEdit}>` sorted by the `TextEdit`, but in 
`generateMissingIncludeDiagnostics`, we need to lookup from a `Header`, then 
this means we have to do a linear scan which doesn't feel good.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:330
+  llvm::DenseMap>
+  HeaderToSymbols;

kadircet wrote:
> we might still have symbols with the same name (`ns1::Foo` vs `ns2::Foo`), 
> they'll show up the same in the final annotation.
> 
> since we're already sorting by name, we might as well deduplicate after 
> sorting and store just a SmallVector here
you're right, done.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:353
+ChangeAnnotationIdentifier ID = AddAllMissingID + std::to_string(I++);
+AddAllMissing.Edits.push_back(Edit);
+AddAllMissing.Edits.back().annotationId = ID;

kadircet wrote:
> we might generate multiple insertions to same location here e.g. insert `a.h` 
> and `b.h` at the top of the file. 
> [LSP](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textEditArray)
>  says that order reported by the server will be preserved. hence we should 
> actually make sure our edits are ordered by spelling.
Good catch, this seems like an existing problem today. Sorting these edits by 
spelling header is one solution, 

I'm planning to do it in this patch, added a FIXME.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149437

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


[clang-tools-extra] b472176 - [clangd] Remove unused includes in IncludeCleaner.cpp, NFC

2023-06-16 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-06-16T15:15:07+02:00
New Revision: b472176829d44a68d94f26eaa743947e92fc9d1d

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

LOG: [clangd] Remove unused includes in IncludeCleaner.cpp, NFC

Added: 


Modified: 
clang-tools-extra/clangd/IncludeCleaner.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index dac24bcc7e4d7..e04e28bd30f18 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -13,7 +13,6 @@
 #include "Preamble.h"
 #include "Protocol.h"
 #include "SourceCode.h"
-#include "URI.h"
 #include "clang-include-cleaner/Analysis.h"
 #include "clang-include-cleaner/IncludeSpeller.h"
 #include "clang-include-cleaner/Record.h"
@@ -22,11 +21,6 @@
 #include "support/Path.h"
 #include "support/Trace.h"
 #include "clang/AST/ASTContext.h"
-#include "clang/AST/DeclCXX.h"
-#include "clang/AST/Expr.h"
-#include "clang/AST/ExprCXX.h"
-#include "clang/AST/TemplateName.h"
-#include "clang/AST/Type.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
@@ -47,7 +41,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Casting.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatVariadic.h"



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


[PATCH] D152924: [libLTO][AIX] Respect `-f[no]-integrated-as` on AIX

2023-06-16 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:703
+Arg *A = Args.getLastArgNoClaim(options::OPT_fno_integrated_as);
+D.Diag(diag::warn_drv_unsupported_lto_option_for_target)
+<< A->getSpelling() << ToolChain.getTriple().getTriple();

MaskRay wrote:
> The patch is titled AIX but this would change the Linux behavior. In my 
> experience this diagnostic is not useful.
Yes I agree the title is a bit misleading. The warning is added because the 
behaviour of `-fno-integrated-as` changes with and without `-flto`. Without 
`-flto`, `clang` does create the job to invoke system assembler, and with 
`-flto`, currently `clang` silently ignores the `-fno-integrated-as` option 
(without this patch). I felt that was unexpected, hence I added the warning. I 
am happy to remove the warning if the community thinks that silently ignoring 
the option is acceptable. 

The limitation of this diagnostic is that it goes through `clang` and there is 
nothing in the backend guarding against using `-no-integrated-as` directly 
through `-plugin-opt` on Linux, which will be ignored. @MaskRay is this 
something we should worry about? If not, I will not try looking for a place to 
add the warning in the backend.

Thanks! 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152924

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


[clang] 459f495 - [clang][Interp] Check inc/dec family of ops for initialization

2023-06-16 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-06-16T15:19:23+02:00
New Revision: 459f495f49a197a042890e1daa0a98cbae892d2b

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

LOG: [clang][Interp] Check inc/dec family of ops for initialization

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

Added: 


Modified: 
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 3798146b32d11..8d7f191ebaa09 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -53,17 +53,6 @@ static bool Jf(InterpState &S, CodePtr &PC, int32_t Offset) {
   return true;
 }
 
-static bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
- AccessKinds AK) {
-  if (Ptr.isInitialized())
-return true;
-  if (!S.checkingPotentialConstantExpression()) {
-const SourceInfo &Loc = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_constexpr_access_uninit) << AK << false;
-  }
-  return false;
-}
-
 static bool CheckActive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
 AccessKinds AK) {
   if (Ptr.isActive())
@@ -243,6 +232,18 @@ bool CheckMutable(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr) {
   return false;
 }
 
+bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
+  AccessKinds AK) {
+  if (Ptr.isInitialized())
+return true;
+
+  if (!S.checkingPotentialConstantExpression()) {
+const SourceInfo &Loc = S.Current->getSource(OpPC);
+S.FFDiag(Loc, diag::note_constexpr_access_uninit) << AK << false;
+  }
+  return false;
+}
+
 bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
   if (!CheckLive(S, OpPC, Ptr, AK_Read))
 return false;

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index d2f4af82089bf..dbe8b3889849c 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -76,6 +76,9 @@ bool CheckMutable(InterpState &S, CodePtr OpPC, const Pointer 
&Ptr);
 /// Checks if a value can be loaded from a block.
 bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr);
 
+bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
+  AccessKinds AK);
+
 /// Checks if a value can be stored in a block.
 bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr);
 
@@ -501,9 +504,11 @@ bool IncDecHelper(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr) {
 /// 4) Pushes the original (pre-inc) value on the stack.
 template ::T>
 bool Inc(InterpState &S, CodePtr OpPC) {
-  // FIXME: Check initialization of Ptr
   const Pointer &Ptr = S.Stk.pop();
 
+  if (!CheckInitialized(S, OpPC, Ptr, AK_Increment))
+return false;
+
   return IncDecHelper(S, OpPC, Ptr);
 }
 
@@ -512,9 +517,11 @@ bool Inc(InterpState &S, CodePtr OpPC) {
 /// 3) Writes the value increased by one back to the pointer
 template ::T>
 bool IncPop(InterpState &S, CodePtr OpPC) {
-  // FIXME: Check initialization of Ptr
   const Pointer &Ptr = S.Stk.pop();
 
+  if (!CheckInitialized(S, OpPC, Ptr, AK_Increment))
+return false;
+
   return IncDecHelper(S, OpPC, Ptr);
 }
 
@@ -524,9 +531,11 @@ bool IncPop(InterpState &S, CodePtr OpPC) {
 /// 4) Pushes the original (pre-dec) value on the stack.
 template ::T>
 bool Dec(InterpState &S, CodePtr OpPC) {
-  // FIXME: Check initialization of Ptr
   const Pointer &Ptr = S.Stk.pop();
 
+  if (!CheckInitialized(S, OpPC, Ptr, AK_Decrement))
+return false;
+
   return IncDecHelper(S, OpPC, Ptr);
 }
 
@@ -535,9 +544,11 @@ bool Dec(InterpState &S, CodePtr OpPC) {
 /// 3) Writes the value decreased by one back to the pointer
 template ::T>
 bool DecPop(InterpState &S, CodePtr OpPC) {
-  // FIXME: Check initialization of Ptr
   const Pointer &Ptr = S.Stk.pop();
 
+  if (!CheckInitialized(S, OpPC, Ptr, AK_Decrement))
+return false;
+
   return IncDecHelper(S, OpPC, Ptr);
 }
 
@@ -562,26 +573,38 @@ bool IncDecFloatHelper(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr,
 }
 
 inline bool Incf(InterpState &S, CodePtr OpPC, llvm::RoundingMode RM) {
-  // FIXME: Check initialization of Ptr
   const Pointer &Ptr = S.Stk.pop();
+
+  if (!CheckInitialized(S, OpPC, Ptr, AK_Increment))
+return false;
+
   return IncDecFloatHelper(S, OpPC, Ptr, RM);
 }
 
 inline bool IncfPop(InterpState &S, CodePtr OpPC, llvm::RoundingMode RM) {
-  // FIXME: Check initialization of Ptr
   const Pointer &Ptr = S.Stk.pop();
+
+  if (!CheckInitialized(S, OpPC, Ptr, AK_Increment))
+return false;
+
   return IncDecFloatHelper(S, OpPC, Ptr, RM);
 }
 
 inline bool Decf(InterpState &S, CodePtr OpPC, llvm::RoundingMode 

[PATCH] D149846: [clang][Interp] Check inc/dec family of ops for initialization

2023-06-16 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG459f495f49a1: [clang][Interp] Check inc/dec family of ops 
for initialization (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149846

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

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -462,14 +462,36 @@
   }
   static_assert(incBool(), "");
 
+  template
   constexpr int uninit() {
-int a;
-++a; // ref-note {{increment of uninitialized}} \
- // FIXME: Should also be rejected by new interpreter
+T a;
+if constexpr (Inc)
+  ++a; // ref-note 2{{increment of uninitialized}} \
+   // expected-note 2{{increment of object outside its lifetime}}
+else
+  --a; // ref-note 2{{decrement of uninitialized}} \
+   // expected-note 2{{decrement of object outside its lifetime}}
 return 1;
   }
-  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
-   // ref-note {{in call to 'uninit()'}}
+  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to 'uninit()'}} \
+  // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to 'uninit()'}}
+
+  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
+   // ref-note {{in call to 'uninit()'}} \
+   // expected-error {{not an integral constant expression}} \
+   // expected-note {{in call to 'uninit()'}}
+
+  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'uninit()'}} \
+// expected-error {{not an integral constant expression}} \
+// expected-note {{in call to 'uninit()'}}
+
+  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
+ // ref-note {{in call to 'uninit()'}} \
+ // expected-error {{not an integral constant expression}} \
+ // expected-note {{in call to 'uninit()'}}
 
   constexpr int OverFlow() { // ref-error {{never produces a constant expression}} \
  // expected-error {{never produces a constant expression}}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -76,6 +76,9 @@
 /// Checks if a value can be loaded from a block.
 bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr);
 
+bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
+  AccessKinds AK);
+
 /// Checks if a value can be stored in a block.
 bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr);
 
@@ -501,9 +504,11 @@
 /// 4) Pushes the original (pre-inc) value on the stack.
 template ::T>
 bool Inc(InterpState &S, CodePtr OpPC) {
-  // FIXME: Check initialization of Ptr
   const Pointer &Ptr = S.Stk.pop();
 
+  if (!CheckInitialized(S, OpPC, Ptr, AK_Increment))
+return false;
+
   return IncDecHelper(S, OpPC, Ptr);
 }
 
@@ -512,9 +517,11 @@
 /// 3) Writes the value increased by one back to the pointer
 template ::T>
 bool IncPop(InterpState &S, CodePtr OpPC) {
-  // FIXME: Check initialization of Ptr
   const Pointer &Ptr = S.Stk.pop();
 
+  if (!CheckInitialized(S, OpPC, Ptr, AK_Increment))
+return false;
+
   return IncDecHelper(S, OpPC, Ptr);
 }
 
@@ -524,9 +531,11 @@
 /// 4) Pushes the original (pre-dec) value on the stack.
 template ::T>
 bool Dec(InterpState &S, CodePtr OpPC) {
-  // FIXME: Check initialization of Ptr
   const Pointer &Ptr = S.Stk.pop();
 
+  if (!CheckInitialized(S, OpPC, Ptr, AK_Decrement))
+return false;
+
   return IncDecHelper(S, OpPC, Ptr);
 }
 
@@ -535,9 +544,11 @@
 /// 3) Writes the value decreased by one back to the pointer
 template ::T>
 bool DecPop(InterpState &S, CodePtr OpPC) {
-  // FIXME: Check initialization of Ptr
   const Pointer &Ptr = S.Stk.pop();
 
+  if (!CheckInitialized(S, OpPC, Ptr, AK_Decrement))
+return false;
+
   return IncDecHelper(S, OpPC, Ptr);
 }
 
@@ -562,26 +573,38 @@
 }
 
 inline bool Incf(InterpState &

[PATCH] D146242: [ARM] Fixing ABI mismatch for packed structs passed as function arguments

2023-06-16 Thread Momchil Velikov via Phabricator via cfe-commits
chill added a comment.

In D146242#4427966 , @tmatheson wrote:

> In D146242#4427707 , @chill wrote:
>
>> I was just thinking to LGTM it :)
>>
>> IMHO, the alignment adjustment  happens because of C.4 (B.3 indeed leave the 
>> HFA/HVA unmodified).
>>
>>> C.4 If the argument is an HFA, an HVA, a Quad-precision Floating-point or 
>>> short vector type then the NSAA is rounded up to the next multiple of 8 if 
>>> its natural alignment is ≤ 8 or the next multiple of 16 if its natural 
>>> alignment is ≥ 16.
>
> I think that C2 would be hit first, suggesting it should be allocated a SIMD 
> register and alignment should be irrelevant, assuming sufficient registers:

Sure, but this is not relevant. We should output a correct `alignstack` 
attribute if in the end it turns out the argument needs to be allocated in 
memory. No harm done if we output the attribute, but the
argument ends up in registers.

>> C.2 If the argument is an HFA or an HVA and there are sufficient unallocated 
>> SIMD and Floating-point registers (NSRN + number of members ≤ 8), then the 
>> argument is allocated to SIMD and Floating-point registers (with one 
>> register per member of the HFA or HVA). The NSRN is incremented by the 
>> number of registers used. The argument has now been allocated.
>
> If not enough registers, the size also needs rounded up:
>
>> C.3 If the argument is an HFA or an HVA then the NSRN is set to 8 and the 
>> size of the argument is rounded up to the nearest multiple of 8 bytes.

I believe that is handled in the backend, by allocating arguments to at least 
8-byte aligned stack slots, e.g. here 
https://github.com/llvm/llvm-project/blob/459f495f49a197a042890e1daa0a98cbae892d2b/llvm/lib/Target/AArch64/AArch64CallingConvention.cpp#L200

> After that C4 would indeed be hit. However C4 differs from B6 
> , in that C4 rounds up to the nearest multiple 
> of 8 or 16 (which is not what the patch currently does) whereas B6 
>  restricts it to either 6 or 16 (which this what 
> this patch does, but shouldn't apply to HVAs).

But there isn't any other power of two between 8 and 16.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146242

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


[PATCH] D153123: Fix diag for read-only target features

2023-06-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/test/OpenMP/driver-openmp-amdgpu.c:8
+// RUN:   --offload-device-only -o - 2>&1 | FileCheck --check-prefix=CHECK %s
+// CHECK-NOT: warning: feature flag {{.*}} is ignored since the feature is 
read only

arsenm wrote:
> Can you use -verify and expected-no-diagnostics? CHECK-NOT is really fragile
-verify only works with clang -cc1, whereas we want to make sure there is no 
warning for the whole compilation invoked by clang driver


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

https://reviews.llvm.org/D153123

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


[PATCH] D152914: [Draft] Make __builtin_cpu builtins target-independent

2023-06-16 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added inline comments.



Comment at: llvm/include/llvm/IR/Intrinsics.td:903-907
+// Load of a value provided by the system library at a fixed address. Used for
+// accessing things like HWCAP word provided by GLIBC.
+def int_fixed_addr_ld
+: DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty],
+[IntrInaccessibleMemOnly, ImmArg>]>;

arsenm wrote:
> From this description I don't understand what this is supposed to do. What 
> does the input mean? Why does this use an i32 immarg and not a pointer? Why 
> is the result only i32?
That is fair enough. The description is fairly vague. I can try to improve it 
as per below. The parameter for this is not a pointer (i.e. not an address). It 
is an immediate that represents the index into the enumeration of values that 
are provided at a fixed address. The back end is then free to produce the 
actual fixed address and the load itself.
The choice for the result type was admittedly arbitrary - on PPC, the values 
provided by GLIBC are 32-bit words.

Proposed comment describing this intrinsic:
```
// This intrinsic is provided to allow back ends to emit load
// instructions that load a value from a fixed address. The
// parameter to the intrinsic is not an address, but an
// immediate index into an enumeration that contains the
// union of all such values available on all back ends.
// An example is the HWCAP/HWCAP2/CPUID words
// provided by GLIBC on PowerPC to allow fast access
// to commonly used parts of AUXV. These are provided
// at a fixed offset into the TCB (accessible through the
// thread pointer).
```



Comment at: llvm/include/llvm/IR/Intrinsics.td:905
+// accessing things like HWCAP word provided by GLIBC.
+def int_fixed_addr_ld
+: DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty],

arsenm wrote:
> I think a new intrinsic should be in a separate commit 
Sounds good.



Comment at: llvm/include/llvm/Support/TargetOpcodes.def:148
 
+/// This pseudo-instruction loads a value provided by libc at afixed address.
+/// For example, GLIBC provides HWCAP, HWCAP2 and CPUID at a fixed address

arsenm wrote:
> Typo afixed
ACK


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152914

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


[clang] 1e9ac71 - [clang][Interp] Handle PredefinedExprs

2023-06-16 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-06-16T15:52:12+02:00
New Revision: 1e9ac717877b5a9410db99a8f0d61fa9ca144b44

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

LOG: [clang][Interp] Handle PredefinedExprs

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index b2a27725307f8..8558ba0ba1ee7 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -932,6 +932,14 @@ bool ByteCodeExprGen::VisitLambdaExpr(const 
LambdaExpr *E) {
   return true;
 }
 
+template 
+bool ByteCodeExprGen::VisitPredefinedExpr(const PredefinedExpr *E) {
+  if (DiscardResult)
+return true;
+
+  return this->visit(E->getFunctionName());
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 70961bea98c31..8708bf99d91e7 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -94,6 +94,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
   bool VisitTypeTraitExpr(const TypeTraitExpr *E);
   bool VisitLambdaExpr(const LambdaExpr *E);
+  bool VisitPredefinedExpr(const PredefinedExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 1a93a951ee3f7..3c81c6ff04e6f 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++11 -verify 
%s
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify 
%s
-// RUN: %clang_cc1 -std=c++11 -verify=ref %s
-// RUN: %clang_cc1 -std=c++20 -verify=ref %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fms-extensions 
-std=c++11 -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fms-extensions 
-std=c++20 -verify %s
+// RUN: %clang_cc1 -std=c++11 -fms-extensions -verify=ref %s
+// RUN: %clang_cc1 -std=c++20 -fms-extensions -verify=ref %s
 
 #define INT_MIN (~__INT_MAX__)
 #define INT_MAX __INT_MAX__
@@ -851,3 +851,26 @@ constexpr int ignoredExprs() {
 }
 
 #endif
+
+namespace PredefinedExprs {
+#if __cplusplus >= 201402L
+  template
+  constexpr bool strings_match(const CharT *str1, const CharT *str2) {
+while (*str1 && *str2) {
+  if (*str1++ != *str2++)
+return false;
+};
+
+return *str1 == *str2;
+  }
+
+  void foo() {
+static_assert(strings_match(__FUNCSIG__, "void __cdecl 
PredefinedExprs::foo(void)"), "");
+static_assert(strings_match(L__FUNCSIG__, L"void __cdecl 
PredefinedExprs::foo(void)"), "");
+static_assert(strings_match(L__FUNCTION__, L"foo"), "");
+static_assert(strings_match(__FUNCTION__, "foo"), "");
+static_assert(strings_match(__func__, "foo"), "");
+static_assert(strings_match(__PRETTY_FUNCTION__, "void 
PredefinedExprs::foo()"), "");
+  }
+#endif
+}



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


[PATCH] D148689: [clang][Interp] Handle PredefinedExprs

2023-06-16 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1e9ac717877b: [clang][Interp] Handle PredefinedExprs 
(authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D148689?vs=519835&id=532134#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148689

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


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++11 -verify 
%s
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify 
%s
-// RUN: %clang_cc1 -std=c++11 -verify=ref %s
-// RUN: %clang_cc1 -std=c++20 -verify=ref %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fms-extensions 
-std=c++11 -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fms-extensions 
-std=c++20 -verify %s
+// RUN: %clang_cc1 -std=c++11 -fms-extensions -verify=ref %s
+// RUN: %clang_cc1 -std=c++20 -fms-extensions -verify=ref %s
 
 #define INT_MIN (~__INT_MAX__)
 #define INT_MAX __INT_MAX__
@@ -851,3 +851,26 @@
 }
 
 #endif
+
+namespace PredefinedExprs {
+#if __cplusplus >= 201402L
+  template
+  constexpr bool strings_match(const CharT *str1, const CharT *str2) {
+while (*str1 && *str2) {
+  if (*str1++ != *str2++)
+return false;
+};
+
+return *str1 == *str2;
+  }
+
+  void foo() {
+static_assert(strings_match(__FUNCSIG__, "void __cdecl 
PredefinedExprs::foo(void)"), "");
+static_assert(strings_match(L__FUNCSIG__, L"void __cdecl 
PredefinedExprs::foo(void)"), "");
+static_assert(strings_match(L__FUNCTION__, L"foo"), "");
+static_assert(strings_match(__FUNCTION__, "foo"), "");
+static_assert(strings_match(__func__, "foo"), "");
+static_assert(strings_match(__PRETTY_FUNCTION__, "void 
PredefinedExprs::foo()"), "");
+  }
+#endif
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -94,6 +94,7 @@
   bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
   bool VisitTypeTraitExpr(const TypeTraitExpr *E);
   bool VisitLambdaExpr(const LambdaExpr *E);
+  bool VisitPredefinedExpr(const PredefinedExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -932,6 +932,14 @@
   return true;
 }
 
+template 
+bool ByteCodeExprGen::VisitPredefinedExpr(const PredefinedExpr *E) {
+  if (DiscardResult)
+return true;
+
+  return this->visit(E->getFunctionName());
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++11 -verify %s
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify %s
-// RUN: %clang_cc1 -std=c++11 -verify=ref %s
-// RUN: %clang_cc1 -std=c++20 -verify=ref %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fms-extensions -std=c++11 -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fms-extensions -std=c++20 -verify %s
+// RUN: %clang_cc1 -std=c++11 -fms-extensions -verify=ref %s
+// RUN: %clang_cc1 -std=c++20 -fms-extensions -verify=ref %s
 
 #define INT_MIN (~__INT_MAX__)
 #define INT_MAX __INT_MAX__
@@ -851,3 +851,26 @@
 }
 
 #endif
+
+namespace PredefinedExprs {
+#if __cplusplus >= 201402L
+  template
+  constexpr bool strings_match(const CharT *str1, const CharT *str2) {
+while (*str1 && *str2) {
+  if (*str1++ != *str2++)
+return false;
+};
+
+return *str1 == *str2;
+  }
+
+  void foo() {
+static_assert(strings_match(__FUNCSIG__, "void __cdecl PredefinedExprs::foo(void)"), "");
+static_assert(strings_match(L__FUNCSIG__, L"void __cdecl PredefinedExprs::foo(void)"), "");
+static_assert(strings_match(L__FUNCTION__, L"foo"), "");
+static_assert(strings_match(__FUNCTION__, "foo"), "");
+static_assert(strings_match(__func__, "foo"), "");
+static_assert(strings_match(__PRETTY_FUNCTION__, "void PredefinedExprs::foo()"), "");
+  }
+#endif
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h

[PATCH] D146242: [ARM] Fixing ABI mismatch for packed structs passed as function arguments

2023-06-16 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson accepted this revision.
tmatheson added a comment.
This revision now requires review to proceed.

In D146242#4428051 , @chill wrote:

> But there isn't any other power of two between 8 and 16.

Ok, I see where I was going wrong, misreading C4 (it's the stack address which 
is "next multiple of N", which applies an alignment of N).

In that case I don't have any more objections.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146242

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


[PATCH] D146242: [ARM] Fixing ABI mismatch for packed structs passed as function arguments

2023-06-16 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson added a comment.

The description/commit message should reflect the final reasoning behind the 
change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146242

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


[PATCH] D152720: [clangd][ObjC] Support ObjC class rename from implementation decls

2023-06-16 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:715
+
+void VisitObjCImplementationDecl(const ObjCImplementationDecl *OIMD) {
+  if (const auto *CI = OIMD->getClassInterface())

can you also add tests for these into `FindTargetTests`?



Comment at: clang-tools-extra/clangd/FindTarget.cpp:716
+void VisitObjCImplementationDecl(const ObjCImplementationDecl *OIMD) {
+  if (const auto *CI = OIMD->getClassInterface())
+Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),

we don't have the null check in other places, what's the significance here?



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:131
 return HighlightingKind::Interface;
-  if (isa(D))
+  if (isa(D))
 return HighlightingKind::Namespace;

let's do this in a separate change, with some tests



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:171-177
+if (const auto *C = dyn_cast(D)) {
+  if (C->getLocation() == TokenStartLoc)
+D = C->getClassInterface();
+  else if (const auto *I = C->getImplementation())
+if (I->getLocation() == TokenStartLoc)
+  D = C->getClassInterface();
+}

sorry i don't follow what's the logic doing here and we're likely doing these 
in the wrong layer.

we should either:
- Fix selection tree to pick the correct ASTNode, if it's picking the wrong one 
due to not having special cases for these locations here
- Fix the `targetDecl` logic to make sure it emits all the declarations that 
might be referenced by this ast node, if it's missing ClassInterface.
- Fix the canonicalRenameDecl, if we should always prefer `ClassInterface` in 
these cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152720

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


[PATCH] D153033: [CLANG]Fix potential null pointer dereference bugs

2023-06-16 Thread Soumi Manna via Phabricator via cfe-commits
Manna updated this revision to Diff 532138.
Manna added a comment.

Address review comment.


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

https://reviews.llvm.org/D153033

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/Analysis/ThreadSafety.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -1204,10 +1204,12 @@
 // FIXME: Add a checker option to turn this uniqueing feature off.
 const ExplodedNode *StreamOpenNode = getAcquisitionSite(Err, LeakSym, C);
 assert(StreamOpenNode && "Could not find place of stream opening.");
-PathDiagnosticLocation LocUsedForUniqueing =
-PathDiagnosticLocation::createBegin(
-StreamOpenNode->getStmtForDiagnostics(), C.getSourceManager(),
-StreamOpenNode->getLocationContext());
+
+PathDiagnosticLocation LocUsedForUniqueing;
+if (const Stmt *StreamStmt = StreamOpenNode->getStmtForDiagnostics())
+  LocUsedForUniqueing = PathDiagnosticLocation::createBegin(
+  StreamStmt, C.getSourceManager(),
+  StreamOpenNode->getLocationContext());
 
 std::unique_ptr R =
 std::make_unique(
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -4955,7 +4955,8 @@
   };
   // The matrix subscript operator ([][])is considered a single operator.
   // Separating the index expressions by parenthesis is not allowed.
-  if (base->hasPlaceholderType(BuiltinType::IncompleteMatrixIdx) &&
+  if (base && !base->getType().isNull() &&
+  base->hasPlaceholderType(BuiltinType::IncompleteMatrixIdx) &&
   !isa(base)) {
 Diag(base->getExprLoc(), diag::err_matrix_separate_incomplete_index)
 << SourceRange(base->getBeginLoc(), rbLoc);
Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -502,9 +502,8 @@
 for (Context::iterator I = C.begin(), E = C.end(); I != E; ++I) {
   const NamedDecl *D = I.getKey();
   D->printName(llvm::errs());
-  const unsigned *i = C.lookup(D);
   llvm::errs() << " -> ";
-  dumpVarDefinitionName(*i);
+  dumpVarDefinitionName(I.getData());
   llvm::errs() << "\n";
 }
   }
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -2693,7 +2693,7 @@
 // Copy constructor closure always takes an unqualified reference.
 mangleFunctionArgumentType(getASTContext().getLValueReferenceType(
Proto->getParamType(0)
-   ->getAs()
+   ->castAs()
->getPointeeType(),
/*SpelledAsLValue=*/true),
Range);
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -10030,6 +10030,9 @@
 return false;
 
   ObjCTypeParamList *typeParams = iface->getTypeParamList();
+  if (!typeParams)
+return false;
+
   for (unsigned i = 0, n = lhsArgs.size(); i != n; ++i) {
 if (ctx.hasSameType(lhsArgs[i], rhsArgs[i]))
   continue;


Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -1204,10 +1204,12 @@
 // FIXME: Add a checker option to turn this uniqueing feature off.
 const ExplodedNode *StreamOpenNode = getAcquisitionSite(Err, LeakSym, C);
 assert(StreamOpenNode && "Could not find place of stream opening.");
-PathDiagnosticLocation LocUsedForUniqueing =
-PathDiagnosticLocation::createBegin(
-StreamOpenNode->getStmtForDiagnostics(), C.getSourceManager(),
-StreamOpenNode->getLocationContext());
+
+PathDiagnosticLocation LocUsedForUniqueing;
+if (const Stmt *StreamStmt = StreamOpenNode->getStmtForDiagnostics())
+  LocUsedForUniqueing = PathDiagnosticLocation::createBegin(
+  StreamStmt, C.getSourceManager(),
+  StreamOpenNode->getLocationContext());
 
 std::unique_ptr R =
 std::make_unique(
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.c

[PATCH] D153033: [CLANG]Fix potential null pointer dereference bugs

2023-06-16 Thread Soumi Manna via Phabricator via cfe-commits
Manna marked an inline comment as done.
Manna added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:3368
 
-  VD = VD->getCanonicalDecl();
+  VD = cast(VD->getCanonicalDecl());
   auto I = FunctionGlobalizedDecls.find(CGF.CurFn);

aaron.ballman wrote:
> This is unnecessary, `getCanonicalDecl()` can never return a null pointer (it 
> will return `this`, at the very least)
Thank you @aaron.ballman for reviews! I agree with you. My previous analysis 
was wrong. I have removed this change.


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

https://reviews.llvm.org/D153033

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


[PATCH] D142388: [clang] Add builtin_nondeterministic_value

2023-06-16 Thread Manuel Brito via Phabricator via cfe-commits
ManuelJBrito added a comment.

In D142388#4425246 , @aaron.ballman 
wrote:

> In D142388#4415349 , @rsmith wrote:
>
>> I think `__builtin_any_value` works pretty well, and emphasizes that this 
>> can really return any value. I'd also be OK with 
>> `__builtin_convenient_value`, to emphasize that the compiler will pick 
>> something that's convenient for it, but I prefer `__builtin_any_value`.
>
> I can get behind `__builtin_any_value` as the name.
>
> @ManuelJBrito: would you be willing to make these modifications?

Yes, I can change the name to `__builtin_any_value` . 
Where do we stand in terms of further restricting the types for which we can 
use this? I'm a bit out of my depth in regards to all the subtleties.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142388

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


[PATCH] D152924: [libLTO][AIX] Respect `-f[no]-integrated-as` on AIX

2023-06-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:703
+Arg *A = Args.getLastArgNoClaim(options::OPT_fno_integrated_as);
+D.Diag(diag::warn_drv_unsupported_lto_option_for_target)
+<< A->getSpelling() << ToolChain.getTriple().getTriple();

qiongsiwu1 wrote:
> MaskRay wrote:
> > The patch is titled AIX but this would change the Linux behavior. In my 
> > experience this diagnostic is not useful.
> Yes I agree the title is a bit misleading. The warning is added because the 
> behaviour of `-fno-integrated-as` changes with and without `-flto`. Without 
> `-flto`, `clang` does create the job to invoke system assembler, and with 
> `-flto`, currently `clang` silently ignores the `-fno-integrated-as` option 
> (without this patch). I felt that was unexpected, hence I added the warning. 
> I am happy to remove the warning if the community thinks that silently 
> ignoring the option is acceptable. 
> 
> The limitation of this diagnostic is that it goes through `clang` and there 
> is nothing in the backend guarding against using `-no-integrated-as` directly 
> through `-plugin-opt` on Linux, which will be ignored. @MaskRay is this 
> something we should worry about? If not, I will not try looking for a place 
> to add the warning in the backend.
> 
> Thanks! 
I do not worry about LTO ignoring `-fno-integrated-as` on Linux/*BSD targets. 
The use cases are very limited and the primary user (Linux kernel community) 
knows this.

Actually the link action ignores compilation-affected options anyway (all 
`CompileOnly_option`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152924

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


[PATCH] D152321: [clang] Replace use of Type::getPointerTo() (NFC)

2023-06-16 Thread Youngsuk Kim via Phabricator via cfe-commits
JOE1994 updated this revision to Diff 532164.
JOE1994 added a comment.

- Fix nullptr bug (fixes Clang regression test :` Clang :: 
CodeGen/constructor-attribute.c` )
  - Following feedback from @barannikov88

- Rebase onto latest main : a76376cdb034d817803cbdb2f3f451487807124d 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152321

Files:
  clang/lib/CodeGen/CGAtomic.cpp
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CGCXX.cpp
  clang/lib/CodeGen/CGCXXABI.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp

Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -402,7 +402,7 @@
   llvm::Type *DirectTy = CGF.ConvertTypeForMem(ValueTy), *ElementTy = DirectTy;
   if (IsIndirect) {
 unsigned AllocaAS = CGF.CGM.getDataLayout().getAllocaAddrSpace();
-DirectTy = DirectTy->getPointerTo(AllocaAS);
+DirectTy = llvm::PointerType::get(CGF.getLLVMContext(), AllocaAS);
   }
 
   Address Addr = emitVoidPtrDirectVAArg(CGF, VAListAddr, DirectTy, DirectSize,
@@ -2054,7 +2054,7 @@
   Info = ABIArgInfo::getInAlloca(FrameFields.size(), IsIndirect);
   llvm::Type *LLTy = CGT.ConvertTypeForMem(Type);
   if (IsIndirect)
-LLTy = LLTy->getPointerTo(0);
+LLTy = llvm::PointerType::getUnqual(getVMContext());
   FrameFields.push_back(LLTy);
   StackOffset += IsIndirect ? WordSize : getContext().getTypeSizeInChars(Type);
 
@@ -4863,7 +4863,8 @@
   Builder.CreateCondBr(CC, UsingRegs, UsingOverflow);
 
   llvm::Type *DirectTy = CGF.ConvertType(Ty), *ElementTy = DirectTy;
-  if (isIndirect) DirectTy = DirectTy->getPointerTo(0);
+  if (isIndirect)
+DirectTy = llvm::PointerType::getUnqual(CGF.getLLVMContext());
 
   // Case 1: consume registers.
   Address RegAddr = Address::invalid();
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -584,9 +584,6 @@
   auto *RD =
   cast(MPT->getClass()->castAs()->getDecl());
 
-  llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(
-  CGM.getTypes().arrangeCXXMethodType(RD, FPT, /*FD=*/nullptr));
-
   llvm::Constant *ptrdiff_1 = llvm::ConstantInt::get(CGM.PtrDiffTy, 1);
 
   llvm::BasicBlock *FnVirtual = CGF.createBasicBlock("memptr.virtual");
@@ -687,8 +684,6 @@
   {VFPAddr, llvm::ConstantInt::get(CGM.Int32Ty, 0), TypeId});
   CheckResult = Builder.CreateExtractValue(CheckedLoad, 1);
   VirtualFn = Builder.CreateExtractValue(CheckedLoad, 0);
-  VirtualFn = Builder.CreateBitCast(VirtualFn, FTy->getPointerTo(),
-"memptr.virtualfn");
 } else {
   // When not doing VFE, emit a normal load, as it allows more
   // optimisations than type.checked.load.
@@ -709,15 +704,12 @@
 CGM.getIntrinsic(llvm::Intrinsic::load_relative,
  {VTableOffset->getType()}),
 {VTable, VTableOffset});
-VirtualFn = CGF.Builder.CreateBitCast(VirtualFn, FTy->getPointerTo());
   } else {
 llvm::Value *VFPAddr =
 CGF.Builder.CreateGEP(CGF.Int8Ty, VTable, VTableOffset);
-VFPAddr = CGF.Builder.CreateBitCast(
-VFPAddr, FTy->getPointerTo()->getPointerTo());
 VirtualFn = CGF.Builder.CreateAlignedLoad(
-FTy->getPointerTo(), VFPAddr, CGF.getPointerAlign(),
-"memptr.virtualfn");
+llvm::PointerType::getUnqual(CGF.getLLVMContext()), VFPAddr,
+CGF.getPointerAlign(), "memptr.virtualfn");
   }
 }
 assert(VirtualFn && "Virtual fuction pointer not created!");
@@ -757,8 +749,9 @@
   // In the non-virtual path, the function pointer is actually a
   // function pointer.
   CGF.EmitBlock(FnNonVirtual);
-  llvm::Value *NonVirtualFn =
-Builder.CreateIntToPtr(FnAsInt, FTy->getPointerTo(), "memptr.nonvirtualfn");
+  llvm::Value *NonVirtualFn = Builder.CreateIntToPtr(
+  FnAsInt, llvm::PointerType::getUnqual(CGF.getLLVMContext()),
+  "memptr.nonvirtualfn");
 
   // Check the function pointer if CFI on member function pointers is enabled.
   if (ShouldEmitCFICheck) {
@@ -799,7 +792,8 @@
 
   // We're done.
   CGF.EmitBlock(FnEnd);
-  llvm::PHINode *CalleePtr = Builder.CreatePHI(FTy->getPointerTo(), 2);
+  llvm::PHINode *CalleePtr =
+  Builder.CreatePHI(llvm::PointerType::getUnqual(

[PATCH] D106409: [PowerPC] Truncate exponent parameter for vec_cts,vec_ctf

2023-06-16 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106409

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


[PATCH] D152321: [clang] Replace use of Type::getPointerTo() (NFC)

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



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:2552-2554
   auto AddrAS = addr ? addr->getType()->getPointerAddressSpace() : 0;
-  auto AddrInt8PtrTy =
-  AddrAS ? CGF.Int8Ty->getPointerTo(AddrAS) : CGF.Int8PtrTy;
+  auto AddrPtrTy =
+AddrAS ? llvm::PointerType::get(CGF.getLLVMContext(), AddrAS) : 
CGF.Int8PtrTy;

barannikov88 wrote:
> barannikov88 wrote:
> > I think this can be simplified further to just:
> > `llvm::Type *AddrPtrTy = addr->getType();`
> > 
> I was wrong, `addr` can be null here. Sorry.
> 
Thanks for finding this!

Updating code to handle the nullptr case fixes the Clang regression test `Clang 
:: CodeGen/constructor-attribute.c`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152321

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


[PATCH] D153146: [CLANG] Fix potential integer overflow value in getRVVTypeSize()

2023-06-16 Thread Soumi Manna via Phabricator via cfe-commits
Manna created this revision.
Manna added reviewers: erichkeane, aaron.ballman, tahonermann.
Herald added a project: All.
Manna requested review of this revision.
Herald added a project: clang.

In getRVVTypeSize(clang::​ASTContext &, clang::​BuiltinType const *) potential 
integer overflow occurs on expression VScale->first * MinElts with type 
unsigned int (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then 
used in a context that expects an expression of type uint64_t (64 bits, 
unsigned).

To avoid integer overflow, this patch does cast MinElts to type uint64_t.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153146

Files:
  clang/lib/AST/ASTContext.cpp


Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -9566,7 +9566,7 @@
 
   unsigned EltSize = Context.getTypeSize(Info.ElementType);
   unsigned MinElts = Info.EC.getKnownMinValue();
-  return VScale->first * MinElts * EltSize;
+  return VScale->first * static_cast(MinElts) * EltSize;
 }
 
 bool ASTContext::areCompatibleRVVTypes(QualType FirstType,


Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -9566,7 +9566,7 @@
 
   unsigned EltSize = Context.getTypeSize(Info.ElementType);
   unsigned MinElts = Info.EC.getKnownMinValue();
-  return VScale->first * MinElts * EltSize;
+  return VScale->first * static_cast(MinElts) * EltSize;
 }
 
 bool ASTContext::areCompatibleRVVTypes(QualType FirstType,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152321: [clang] Replace use of Type::getPointerTo() (NFC)

2023-06-16 Thread Youngsuk Kim via Phabricator via cfe-commits
JOE1994 added a comment.

With the updated revision, I don't see new test failures from `ninja 
check-clang` & `ninja check-llvm` & `ninja check-clang-unit` & `ninja 
check-llvm-unit` .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152321

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


[PATCH] D152856: [Driver] Allow warning for unclaimed TargetSpecific options

2023-06-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 532167.
MaskRay added a comment.

avoid `mutable`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152856

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/lib/Driver/ToolChains/MinGW.cpp
  llvm/include/llvm/Option/Arg.h
  llvm/lib/Option/Arg.cpp

Index: llvm/lib/Option/Arg.cpp
===
--- llvm/lib/Option/Arg.cpp
+++ llvm/lib/Option/Arg.cpp
@@ -20,19 +20,19 @@
 
 Arg::Arg(const Option Opt, StringRef S, unsigned Index, const Arg *BaseArg)
 : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
-  OwnsValues(false) {}
+  IgnoredTargetSpecific(false), OwnsValues(false) {}
 
 Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
  const Arg *BaseArg)
 : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
-  OwnsValues(false) {
+  IgnoredTargetSpecific(false), OwnsValues(false) {
   Values.push_back(Value0);
 }
 
 Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
  const char *Value1, const Arg *BaseArg)
 : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
-  OwnsValues(false) {
+  IgnoredTargetSpecific(false), OwnsValues(false) {
   Values.push_back(Value0);
   Values.push_back(Value1);
 }
Index: llvm/include/llvm/Option/Arg.h
===
--- llvm/include/llvm/Option/Arg.h
+++ llvm/include/llvm/Option/Arg.h
@@ -47,11 +47,17 @@
   /// ArgList.
   unsigned Index;
 
-  /// Was this argument used to effect compilation?
+  /// Was this argument used to affect compilation?
   ///
-  /// This is used for generating "argument unused" diagnostics.
+  /// This is used to generate an "argument unused" warning (without
+  /// clang::driver::options::TargetSpecific) or "unsupported option" error
+  /// (with TargetSpecific).
   mutable unsigned Claimed : 1;
 
+  /// Used by an unclaimed option with the TargetSpecific flag. If set, report
+  /// an "argument unused" warning instead of an "unsupported option" error.
+  unsigned IgnoredTargetSpecific : 1;
+
   /// Does this argument own its values?
   mutable unsigned OwnsValues : 1;
 
@@ -93,6 +99,7 @@
   const Arg &getBaseArg() const {
 return BaseArg ? *BaseArg : *this;
   }
+  Arg &getBaseArg() { return BaseArg ? const_cast(*BaseArg) : *this; }
   void setBaseArg(const Arg *BaseArg) { this->BaseArg = BaseArg; }
 
   /// Args are converted to their unaliased form.  For args that originally
@@ -104,10 +111,15 @@
   void setOwnsValues(bool Value) const { OwnsValues = Value; }
 
   bool isClaimed() const { return getBaseArg().Claimed; }
-
-  /// Set the Arg claimed bit.
   void claim() const { getBaseArg().Claimed = true; }
 
+  bool isIgnoredTargetSpecific() const {
+return getBaseArg().IgnoredTargetSpecific;
+  }
+  void ignoreTargetSpecific() {
+getBaseArg().IgnoredTargetSpecific = true;
+  }
+
   unsigned getNumValues() const { return Values.size(); }
 
   const char *getValue(unsigned N = 0) const {
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -701,6 +701,9 @@
   << A->getSpelling() << GuardArgs;
 }
   }
+
+  if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_mthreads))
+A->ignoreTargetSpecific();
 }
 
 void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(
Index: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
===
--- clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -139,4 +139,10 @@
   // or the alias -m[no-]strict-align.
   AddTargetFeature(Args, Features, options::OPT_munaligned_access,
options::OPT_mno_unaligned_access, "ual");
+
+  // Accept but warn about these TargetSpecific options.
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mabi_EQ))
+A->ignoreTargetSpecific();
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mfpu_EQ))
+A->ignoreTargetSpecific();
 }
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4892,7 +4892,8 @@
   // In clang-cl, don't mention unknown arguments here since they have
   // already been warned about.
   if (!IsCLMode() || !A->getOption().matches(options::OPT_UNKNOWN)) {
-if (A->getOption().hasFlag(options::TargetSpecific)) {
+if (A->getOption().hasFlag(options::TargetSpecific) &&
+!A->isIgnoredTargetSpecific()) {
   Diag(diag::err_drv_unsupported_opt_for_target)
   

[clang] a79995c - [Driver] Allow warning for unclaimed TargetSpecific options

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

Author: Fangrui Song
Date: 2023-06-16T08:32:25-07:00
New Revision: a79995ca6004082774a87f7a58ab6be5343364b7

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

LOG: [Driver] Allow warning for unclaimed TargetSpecific options

For unclaimed target-agnostic options, we can apply 
clang_ignored_gcc_optimization_f_Group
to accept but warn about them.
```
% clang -c -fexpensive-optimizations a.c
clang: warning: optimization flag '-fexpensive-optimizations' is not supported 
[-Wignored-optimization-argument]
```

For an unclaimed target-specific option, one target may want to accept but warn
about it. Add `llvm::opt::Arg::IgnoredTargetSpecific` to support this warning
need.

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

Reviewed By: mstorsjo

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
clang/lib/Driver/ToolChains/MinGW.cpp
llvm/include/llvm/Option/Arg.h
llvm/lib/Option/Arg.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 06f02a05b7f13..87df2266bd7e3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3555,7 +3555,6 @@ def mqdsp6_compat : Flag<["-"], "mqdsp6-compat">, 
Group, Flags<[NoXarch
 def m64 : Flag<["-"], "m64">, Group, Flags<[NoXarchOption, 
CoreOption]>;
 def maix64 : Flag<["-"], "maix64">, Group, Flags<[NoXarchOption]>;
 def mx32 : Flag<["-"], "mx32">, Group, Flags<[NoXarchOption, 
CoreOption]>;
-def mabi_EQ : Joined<["-"], "mabi=">, Group;
 def miamcu : Flag<["-"], "miamcu">, Group, Flags<[NoXarchOption, 
CoreOption]>,
   HelpText<"Use Intel MCU ABI">;
 def mno_iamcu : Flag<["-"], "mno-iamcu">, Group, 
Flags<[NoXarchOption, CoreOption]>;
@@ -3564,6 +3563,7 @@ def malign_loops_EQ : Joined<["-"], "malign-loops=">, 
Group;
 def malign_branch_boundary_EQ : Joined<["-"], "malign-branch-boundary=">, 
Group,
@@ -3651,9 +3651,7 @@ def malign_double : Flag<["-"], "malign-double">, 
Group, Flags<[CC1Opti
 let Flags = [TargetSpecific] in {
 def mfloat_abi_EQ : Joined<["-"], "mfloat-abi=">, Group, 
Values<"soft,softfp,hard">;
 def mfpmath_EQ : Joined<["-"], "mfpmath=">, Group;
-} // let Flags = [TargetSpecific]
 def mfpu_EQ : Joined<["-"], "mfpu=">, Group;
-let Flags = [TargetSpecific] in {
 def mhwdiv_EQ : Joined<["-"], "mhwdiv=">, Group;
 def mhwmult_EQ : Joined<["-"], "mhwmult=">, Group;
 } // let Flags = [TargetSpecific]

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9fc62be357a60..4c282241d2b25 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4892,7 +4892,8 @@ void Driver::BuildJobs(Compilation &C) const {
   // In clang-cl, don't mention unknown arguments here since they have
   // already been warned about.
   if (!IsCLMode() || !A->getOption().matches(options::OPT_UNKNOWN)) {
-if (A->getOption().hasFlag(options::TargetSpecific)) {
+if (A->getOption().hasFlag(options::TargetSpecific) &&
+!A->isIgnoredTargetSpecific()) {
   Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getSpelling() << getTargetTriple();
 } else {

diff  --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 44c7472f60a60..fe0d5cf149302 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -139,4 +139,10 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
   // or the alias -m[no-]strict-align.
   AddTargetFeature(Args, Features, options::OPT_munaligned_access,
options::OPT_mno_unaligned_access, "ual");
+
+  // Accept but warn about these TargetSpecific options.
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mabi_EQ))
+A->ignoreTargetSpecific();
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mfpu_EQ))
+A->ignoreTargetSpecific();
 }

diff  --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index 947abb9b02b51..6ce36f84a6d0c 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -701,6 +701,9 @@ void toolchains::MinGW::addClangTargetOptions(
   << A->getSpelling() << GuardArgs;
 }
   }
+
+  if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_mthreads))
+A->ignoreTargetSpecific();
 }
 
 void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(

diff  --git a/llvm/include/llvm/Option/Arg.h b/llvm/include/llvm/Option/Arg.h
index 4be254ccdab44..5a718438bf4a3 100644
--- a/llvm/include/llvm/Option/Arg.h
+++ b/llvm/include/llvm/Option/Arg.h

[PATCH] D152856: [Driver] Allow warning for unclaimed TargetSpecific options

2023-06-16 Thread Fangrui Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa79995ca6004: [Driver] Allow warning for unclaimed 
TargetSpecific options (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152856

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/lib/Driver/ToolChains/MinGW.cpp
  llvm/include/llvm/Option/Arg.h
  llvm/lib/Option/Arg.cpp

Index: llvm/lib/Option/Arg.cpp
===
--- llvm/lib/Option/Arg.cpp
+++ llvm/lib/Option/Arg.cpp
@@ -20,19 +20,19 @@
 
 Arg::Arg(const Option Opt, StringRef S, unsigned Index, const Arg *BaseArg)
 : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
-  OwnsValues(false) {}
+  IgnoredTargetSpecific(false), OwnsValues(false) {}
 
 Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
  const Arg *BaseArg)
 : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
-  OwnsValues(false) {
+  IgnoredTargetSpecific(false), OwnsValues(false) {
   Values.push_back(Value0);
 }
 
 Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
  const char *Value1, const Arg *BaseArg)
 : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
-  OwnsValues(false) {
+  IgnoredTargetSpecific(false), OwnsValues(false) {
   Values.push_back(Value0);
   Values.push_back(Value1);
 }
Index: llvm/include/llvm/Option/Arg.h
===
--- llvm/include/llvm/Option/Arg.h
+++ llvm/include/llvm/Option/Arg.h
@@ -47,11 +47,17 @@
   /// ArgList.
   unsigned Index;
 
-  /// Was this argument used to effect compilation?
+  /// Was this argument used to affect compilation?
   ///
-  /// This is used for generating "argument unused" diagnostics.
+  /// This is used to generate an "argument unused" warning (without
+  /// clang::driver::options::TargetSpecific) or "unsupported option" error
+  /// (with TargetSpecific).
   mutable unsigned Claimed : 1;
 
+  /// Used by an unclaimed option with the TargetSpecific flag. If set, report
+  /// an "argument unused" warning instead of an "unsupported option" error.
+  unsigned IgnoredTargetSpecific : 1;
+
   /// Does this argument own its values?
   mutable unsigned OwnsValues : 1;
 
@@ -93,6 +99,7 @@
   const Arg &getBaseArg() const {
 return BaseArg ? *BaseArg : *this;
   }
+  Arg &getBaseArg() { return BaseArg ? const_cast(*BaseArg) : *this; }
   void setBaseArg(const Arg *BaseArg) { this->BaseArg = BaseArg; }
 
   /// Args are converted to their unaliased form.  For args that originally
@@ -104,10 +111,15 @@
   void setOwnsValues(bool Value) const { OwnsValues = Value; }
 
   bool isClaimed() const { return getBaseArg().Claimed; }
-
-  /// Set the Arg claimed bit.
   void claim() const { getBaseArg().Claimed = true; }
 
+  bool isIgnoredTargetSpecific() const {
+return getBaseArg().IgnoredTargetSpecific;
+  }
+  void ignoreTargetSpecific() {
+getBaseArg().IgnoredTargetSpecific = true;
+  }
+
   unsigned getNumValues() const { return Values.size(); }
 
   const char *getValue(unsigned N = 0) const {
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -701,6 +701,9 @@
   << A->getSpelling() << GuardArgs;
 }
   }
+
+  if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_mthreads))
+A->ignoreTargetSpecific();
 }
 
 void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(
Index: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
===
--- clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -139,4 +139,10 @@
   // or the alias -m[no-]strict-align.
   AddTargetFeature(Args, Features, options::OPT_munaligned_access,
options::OPT_mno_unaligned_access, "ual");
+
+  // Accept but warn about these TargetSpecific options.
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mabi_EQ))
+A->ignoreTargetSpecific();
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mfpu_EQ))
+A->ignoreTargetSpecific();
 }
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4892,7 +4892,8 @@
   // In clang-cl, don't mention unknown arguments here since they have
   // already been warned about.
   if (!IsCLMode() || !A->getOption().matches(options::OPT_UNKNOWN)) {
-if (A->getOption().hasFlag(options::TargetSpecific)) {
+if (A->g

[PATCH] D153017: [analyzer] Fix false negative when using a nullable parameter directly without binding to a variable

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

LGTM; I'll commit this on Monday.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153017

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


[PATCH] D153038: [Clang] Fixes a diagnostic typo.

2023-06-16 Thread Mark de Wever via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG501405f1d5f0: [Clang] Fixes a diagnostic typo. (authored by 
Mordante).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153038

Files:
  clang/include/clang/Basic/DiagnosticSerializationKinds.td
  clang/test/Modules/no-implicit-std-cxx-module.cppm


Index: clang/test/Modules/no-implicit-std-cxx-module.cppm
===
--- clang/test/Modules/no-implicit-std-cxx-module.cppm
+++ clang/test/Modules/no-implicit-std-cxx-module.cppm
@@ -7,7 +7,7 @@
 // RUN: -o %t/a.pcm
 // RUN: %clang_cc1 -std=c++20 %t/user.cpp -fmodule-file=a=%t/a.pcm -verify 
-fsyntax-only
 // RUN: %clang_cc1 -std=c++20 %t/user.cpp -fmodule-file=a=%t/a.pcm -verify 
-fsyntax-only \
-// RUN: -Wno-read-modules-implicitly -DNO_DIAG 
+// RUN: -Wno-read-modules-implicitly -DNO_DIAG
 // RUN: %clang_cc1 -std=c++20 %t/user.cpp -fmodule-file=a=%t/a.pcm 
-fmodule-file=b=%t/b.pcm \
 // RUN: -DNO_DIAG -verify -fsyntax-only
 //
@@ -35,7 +35,7 @@
 return b() + 43;
 }
 
-// CHECK: it is deprecated to read module 'b' implcitly;
+// CHECK: it is deprecated to read module 'b' implicitly;
 
 // CHECK-CORRECT-NOT: warning
 // CHECK-CORRECT-NOT: error
@@ -47,9 +47,9 @@
 #ifdef NO_DIAG
 // expected-no-diagnostics
 #else
- // expected-warning@+2 {{it is deprecated to read module 'b' implcitly;}}
+ // expected-warning@+2 {{it is deprecated to read module 'b' implicitly;}}
 #endif
 import a;
 int use() {
 return a();
-}
\ No newline at end of file
+}
Index: clang/include/clang/Basic/DiagnosticSerializationKinds.td
===
--- clang/include/clang/Basic/DiagnosticSerializationKinds.td
+++ clang/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -135,7 +135,7 @@
   InGroup>;
 
 def warn_reading_std_cxx_module_by_implicit_paths : Warning<
-  "it is deprecated to read module '%0' implcitly; it is going to be removed 
in clang18; "
+  "it is deprecated to read module '%0' implicitly; it is going to be removed 
in clang 18; "
   "consider to specify the dependencies explicitly">,
   InGroup>;
 } // let CategoryName


Index: clang/test/Modules/no-implicit-std-cxx-module.cppm
===
--- clang/test/Modules/no-implicit-std-cxx-module.cppm
+++ clang/test/Modules/no-implicit-std-cxx-module.cppm
@@ -7,7 +7,7 @@
 // RUN: -o %t/a.pcm
 // RUN: %clang_cc1 -std=c++20 %t/user.cpp -fmodule-file=a=%t/a.pcm -verify -fsyntax-only
 // RUN: %clang_cc1 -std=c++20 %t/user.cpp -fmodule-file=a=%t/a.pcm -verify -fsyntax-only \
-// RUN: -Wno-read-modules-implicitly -DNO_DIAG 
+// RUN: -Wno-read-modules-implicitly -DNO_DIAG
 // RUN: %clang_cc1 -std=c++20 %t/user.cpp -fmodule-file=a=%t/a.pcm -fmodule-file=b=%t/b.pcm \
 // RUN: -DNO_DIAG -verify -fsyntax-only
 //
@@ -35,7 +35,7 @@
 return b() + 43;
 }
 
-// CHECK: it is deprecated to read module 'b' implcitly;
+// CHECK: it is deprecated to read module 'b' implicitly;
 
 // CHECK-CORRECT-NOT: warning
 // CHECK-CORRECT-NOT: error
@@ -47,9 +47,9 @@
 #ifdef NO_DIAG
 // expected-no-diagnostics
 #else
- // expected-warning@+2 {{it is deprecated to read module 'b' implcitly;}}
+ // expected-warning@+2 {{it is deprecated to read module 'b' implicitly;}}
 #endif
 import a;
 int use() {
 return a();
-}
\ No newline at end of file
+}
Index: clang/include/clang/Basic/DiagnosticSerializationKinds.td
===
--- clang/include/clang/Basic/DiagnosticSerializationKinds.td
+++ clang/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -135,7 +135,7 @@
   InGroup>;
 
 def warn_reading_std_cxx_module_by_implicit_paths : Warning<
-  "it is deprecated to read module '%0' implcitly; it is going to be removed in clang18; "
+  "it is deprecated to read module '%0' implicitly; it is going to be removed in clang 18; "
   "consider to specify the dependencies explicitly">,
   InGroup>;
 } // let CategoryName
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 501405f - [Clang] Fixes a diagnostic typo.

2023-06-16 Thread Mark de Wever via cfe-commits

Author: Mark de Wever
Date: 2023-06-16T17:40:53+02:00
New Revision: 501405f1d5f027717ab6866aa1dece2d384791cc

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

LOG: [Clang] Fixes a diagnostic typo.

Some small style updates as drive-by.

Reviewed By: ChuanqiXu

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSerializationKinds.td
clang/test/Modules/no-implicit-std-cxx-module.cppm

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSerializationKinds.td 
b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
index bab7f76b11121..5197aa16c4ae2 100644
--- a/clang/include/clang/Basic/DiagnosticSerializationKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -135,7 +135,7 @@ def warn_eagerly_load_for_standard_cplusplus_modules : 
Warning<
   InGroup>;
 
 def warn_reading_std_cxx_module_by_implicit_paths : Warning<
-  "it is deprecated to read module '%0' implcitly; it is going to be removed 
in clang18; "
+  "it is deprecated to read module '%0' implicitly; it is going to be removed 
in clang 18; "
   "consider to specify the dependencies explicitly">,
   InGroup>;
 } // let CategoryName

diff  --git a/clang/test/Modules/no-implicit-std-cxx-module.cppm 
b/clang/test/Modules/no-implicit-std-cxx-module.cppm
index d7a9e3ce67c08..0432159fed180 100644
--- a/clang/test/Modules/no-implicit-std-cxx-module.cppm
+++ b/clang/test/Modules/no-implicit-std-cxx-module.cppm
@@ -7,7 +7,7 @@
 // RUN: -o %t/a.pcm
 // RUN: %clang_cc1 -std=c++20 %t/user.cpp -fmodule-file=a=%t/a.pcm -verify 
-fsyntax-only
 // RUN: %clang_cc1 -std=c++20 %t/user.cpp -fmodule-file=a=%t/a.pcm -verify 
-fsyntax-only \
-// RUN: -Wno-read-modules-implicitly -DNO_DIAG 
+// RUN: -Wno-read-modules-implicitly -DNO_DIAG
 // RUN: %clang_cc1 -std=c++20 %t/user.cpp -fmodule-file=a=%t/a.pcm 
-fmodule-file=b=%t/b.pcm \
 // RUN: -DNO_DIAG -verify -fsyntax-only
 //
@@ -35,7 +35,7 @@ export int a() {
 return b() + 43;
 }
 
-// CHECK: it is deprecated to read module 'b' implcitly;
+// CHECK: it is deprecated to read module 'b' implicitly;
 
 // CHECK-CORRECT-NOT: warning
 // CHECK-CORRECT-NOT: error
@@ -47,9 +47,9 @@ export int a() {
 #ifdef NO_DIAG
 // expected-no-diagnostics
 #else
- // expected-warning@+2 {{it is deprecated to read module 'b' implcitly;}}
+ // expected-warning@+2 {{it is deprecated to read module 'b' implicitly;}}
 #endif
 import a;
 int use() {
 return a();
-}
\ No newline at end of file
+}



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


[PATCH] D152570: [clang] Apply -fmacro-prefix-map to anonymous tags in template arguments

2023-06-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:515
+- Apply ``-fmacro-prefix-map`` to anonymous tags in template arguments
+  (`#63219 `_)
 

I'll add a period to be consistent with other entries. Thanks!



Comment at: clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp:1
+// RUN: %clang_cc1 -triple %itanium_abi_triple 
-fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+

I'll remove `-S` since `-emit-llvm` wins for CC1 options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152570

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


[PATCH] D152658: [InstCombine] Change SimplifyDemandedVectorElts to use PoisonElts instead of UndefElts

2023-06-16 Thread Manuel Brito via Phabricator via cfe-commits
ManuelJBrito added inline comments.



Comment at: llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp:3102-3105
   case Intrinsic::x86_sse4a_extrqi:
   case Intrinsic::x86_sse4a_insertq:
   case Intrinsic::x86_sse4a_insertqi:
+PoisonElts.setHighBits(VWidth / 2);

nlopes wrote:
> this change doesn't look correct. The bits are undefined, doesn't seem like 
> you can use poison here.
Thanks, I'll fix it. This will cause some regressions in the cases where only 
the upper half is demanded.
Eventually we could fold those cases to freeze(poison).



Comment at: llvm/test/Transforms/InstCombine/vec_shuffle.ll:1301
 ; CHECK-LABEL: @fmul_splat_constant(
-; CHECK-NEXT:[[TMP1:%.*]] = fmul <2 x float> [[X:%.*]], 
-; CHECK-NEXT:[[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> 
poison, <2 x i32> zeroinitializer
+  ; CHECK-NEXT:[[TMP1:%.*]] = shufflevector <2 x float> [[X:%.*]], <2 x 
float> undef, <2 x i32> zeroinitializer
+; CHECK-NEXT:[[R:%.*]] = fmul <2 x float> [[TMP1]], 

nlopes wrote:
> Why does it regress here (goes from poison to undef)?
This regression is due to the change in foldVectorBinop in 
InstructionCombining.cpp
It seems that without this canonicalization, demanded elements doesn't trigger 
causing the regression.

I changed it to match poison instead of undef, because of the following:

shufflevector < 4 x i32 > %1, < 4 x i32 > undef , <1, 2, 6, 7>  --> 
shufflevector < 4 x i32 > %1, < 4 x i32 > undef , <1, 2, undef, undef>

Now we don't do this because it would insert poison.

Not simplifying the mask causes the following assert to fail:

```
assert(ShMask[I] < (int)NumElts && "Not expecting narrowing shuffle") 
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152658

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


[PATCH] D146242: [ARM] Fixing ABI mismatch for packed structs passed as function arguments

2023-06-16 Thread Momchil Velikov via Phabricator via cfe-commits
chill added a comment.

> Previously when a packed struct, containing vector data types such as
> uint16x8_t, is passed as a function argument, the alignment of the
> struct used by the function caller and the alignment used by the callee
> to load the argument from stack does not match.

I would suggest adding tests with assembler output that show what is fixed 
(perhaps pre-committed).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146242

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


[clang] 30ffb3e - [clang] Apply -fmacro-prefix-map to anonymous tags in template arguments

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

Author: Dan McGregor
Date: 2023-06-16T08:47:00-07:00
New Revision: 30ffb3e4fbce3132fbf63c62a8ecbb1edbec4fc9

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

LOG: [clang] Apply -fmacro-prefix-map to anonymous tags in template arguments

When expanding template arguments for pretty function printing,
such as for __PRETTY_FUNCTION__, make TypePrinter apply
macro-prefix-map remapping to anonymous tags such as lambdas.

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

Reviewed By: MaskRay, aaron.ballman

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

Added: 
clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/Expr.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 336bd5b6aa2e1..82e3b9d5de38b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -511,6 +511,8 @@ Bug Fixes in This Version
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
   (`#50244 _`).
+- Apply ``-fmacro-prefix-map`` to anonymous tags in template arguments
+  (`#63219 `_).
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 1fbb76a19acb2..0d927d083ed20 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@ std::string PredefinedExpr::ComputeName(IdentKind IK, 
const Decl *CurrentDecl) {
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions &LO) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions &LO;
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = &PrettyCB;
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 

diff  --git a/clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp 
b/clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp
new file mode 100644
index 0..e87f0ab484dc4
--- /dev/null
+++ b/clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple 
-fmacro-prefix-map=%p=./UNLIKELY_PATH/empty %s -emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private 
unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:[[#@LINE-1]]:24)]\00", align 1
+
+  return 0;
+}



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


  1   2   >