[PATCH] D144961: [NVPTX] Add f16 and v2f16 ldg builtins

2023-03-01 Thread Jakub Chlanda via Phabricator via cfe-commits
jchlanda updated this revision to Diff 501392.
jchlanda added a comment.

Add more verbose test names.


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

https://reviews.llvm.org/D144961

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-nvptx-native-half-type.c
  llvm/test/CodeGen/NVPTX/ldu-ldg.ll

Index: llvm/test/CodeGen/NVPTX/ldu-ldg.ll
===
--- llvm/test/CodeGen/NVPTX/ldu-ldg.ll
+++ llvm/test/CodeGen/NVPTX/ldu-ldg.ll
@@ -4,34 +4,82 @@
 
 declare i8 @llvm.nvvm.ldu.global.i.i8.p1(ptr addrspace(1) %ptr, i32 %align)
 declare i32 @llvm.nvvm.ldu.global.i.i32.p1(ptr addrspace(1) %ptr, i32 %align)
+
 declare i8 @llvm.nvvm.ldg.global.i.i8.p1(ptr addrspace(1) %ptr, i32 %align)
+declare i16 @llvm.nvvm.ldg.global.i.i16.p1(ptr addrspace(1) %ptr, i32 %align)
 declare i32 @llvm.nvvm.ldg.global.i.i32.p1(ptr addrspace(1) %ptr, i32 %align)
+declare i64 @llvm.nvvm.ldg.global.i.i64.p1(ptr addrspace(1) %ptr, i32 %align)
+declare float @llvm.nvvm.ldg.global.f.f32.p1(ptr addrspace(1) %ptr, i32 %align)
+declare double @llvm.nvvm.ldg.global.f.f64.p1(ptr addrspace(1) %ptr, i32 %align)
+declare half @llvm.nvvm.ldg.global.f.f16.p1(ptr addrspace(1) %ptr, i32 %align)
+declare <2 x half> @llvm.nvvm.ldg.global.f.v2f16.p1(ptr addrspace(1) %ptr, i32 %align)
 
-
-; CHECK: func0
-define i8 @func0(ptr addrspace(1) %ptr) {
+; CHECK: test_ldu_i8
+define i8 @test_ldu_i8(ptr addrspace(1) %ptr) {
 ; ldu.global.u8
   %val = tail call i8 @llvm.nvvm.ldu.global.i.i8.p1(ptr addrspace(1) %ptr, i32 4)
   ret i8 %val
 }
 
-; CHECK: func1
-define i32 @func1(ptr addrspace(1) %ptr) {
+; CHECK: test_ldu_i32
+define i32 @test_ldu_i32(ptr addrspace(1) %ptr) {
 ; ldu.global.u32
   %val = tail call i32 @llvm.nvvm.ldu.global.i.i32.p1(ptr addrspace(1) %ptr, i32 4)
   ret i32 %val
 }
 
-; CHECK: func2
-define i8 @func2(ptr addrspace(1) %ptr) {
+; CHECK: test_ldg_i8
+define i8 @test_ldg_i8(ptr addrspace(1) %ptr) {
 ; ld.global.nc.u8
   %val = tail call i8 @llvm.nvvm.ldg.global.i.i8.p1(ptr addrspace(1) %ptr, i32 4)
   ret i8 %val
 }
 
-; CHECK: func3
-define i32 @func3(ptr addrspace(1) %ptr) {
+; CHECK: test_ldg_i16
+define i16 @test_ldg_i16(ptr addrspace(1) %ptr) {
+; ld.global.nc.u16
+  %val = tail call i16 @llvm.nvvm.ldg.global.i.i16.p1(ptr addrspace(1) %ptr, i32 4)
+  ret i16 %val
+}
+
+; CHECK: test_ldg_i32
+define i32 @test_ldg_i32(ptr addrspace(1) %ptr) {
 ; ld.global.nc.u32
   %val = tail call i32 @llvm.nvvm.ldg.global.i.i32.p1(ptr addrspace(1) %ptr, i32 4)
   ret i32 %val
 }
+
+; CHECK: test_ldg_i64
+define i64 @test_ldg_i64(ptr addrspace(1) %ptr) {
+; ld.global.nc.u64
+  %val = tail call i64 @llvm.nvvm.ldg.global.i.i64.p1(ptr addrspace(1) %ptr, i32 8)
+  ret i64 %val
+}
+
+; CHECK: test_ldg_f32
+define float @test_ldg_f32(ptr addrspace(1) %ptr) {
+; ld.global.nc.u64
+  %val = tail call float @llvm.nvvm.ldg.global.f.f32.p1(ptr addrspace(1) %ptr, i32 4)
+  ret float %val
+}
+
+; CHECK: test_ldg_f64
+define double @test_ldg_f64(ptr addrspace(1) %ptr) {
+; ld.global.nc.u64
+  %val = tail call double @llvm.nvvm.ldg.global.f.f64.p1(ptr addrspace(1) %ptr, i32 8)
+  ret double %val
+}
+
+; CHECK: test_ldg_f16
+define half @test_ldg_f16(ptr addrspace(1) %ptr) {
+; ld.global.nc.b16
+  %val = tail call half @llvm.nvvm.ldg.global.f.f16.p1(ptr addrspace(1) %ptr, i32 4)
+  ret half %val
+}
+
+; CHECK: test_ldg_v2f16
+define <2 x half> @test_ldg_v2f16(ptr addrspace(1) %ptr) {
+; ld.global.nc.b32
+  %val = tail call <2 x half> @llvm.nvvm.ldg.global.f.v2f16.p1(ptr addrspace(1) %ptr, i32 4)
+  ret <2 x half> %val
+}
Index: clang/test/CodeGen/builtins-nvptx-native-half-type.c
===
--- clang/test/CodeGen/builtins-nvptx-native-half-type.c
+++ clang/test/CodeGen/builtins-nvptx-native-half-type.c
@@ -172,3 +172,12 @@
 #endif
   // CHECK: ret void
 }
+
+// CHECK-LABEL: nvvm_ldg_native_half_types
+__device__ void nvvm_ldg_native_half_types(const void *p) {
+  // CHECK: call half @llvm.nvvm.ldg.global.f.f16.p0
+  __nvvm_ldg_h((const __fp16 *)p);
+  typedef __fp16 __fp16v2 __attribute__((ext_vector_type(2)));
+  // CHECK: call <2 x half> @llvm.nvvm.ldg.global.f.v2f16.p0
+  __nvvm_ldg_h2((const __fp16v2 *)p);
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -18228,7 +18228,9 @@
 // elements, its alignment is set to number of elements times the alignment
 // of its member: n*alignof(t)."
 return MakeLdg(Intrinsic::nvvm_ldg_global_i);
+  case NVPTX::BI__nvvm_ldg_h:
   case NVPTX::BI__nvvm_ldg_f:
+  case NVPTX::BI__nvvm_ldg_h2:
   case NVPTX::BI__nvvm_ldg_f2:
   case NVPTX::BI__nvvm_ldg_f4:
   case NVPTX::BI__nvvm_ldg_d:
Index: clang/include/clang/Basic/BuiltinsNVPTX.def
=

[PATCH] D144961: [NVPTX] Add f16 and v2f16 ldg builtins

2023-03-01 Thread Jakub Chlanda via Phabricator via cfe-commits
jchlanda added inline comments.



Comment at: llvm/test/CodeGen/NVPTX/ldu-ldg.ll:5-6
 
 declare i8 @llvm.nvvm.ldu.global.i.i8.p1(ptr addrspace(1) %ptr, i32 %align)
 declare i32 @llvm.nvvm.ldu.global.i.i32.p1(ptr addrspace(1) %ptr, i32 %align)
+

tra wrote:
> Do we want to add missing `ldu` variants, too?
Looks like none of the `ldu` builtins have been exposed yet. I'll do it in a 
follow up patch.



Comment at: llvm/test/CodeGen/NVPTX/ldu-ldg.ll:39
 ; CHECK: func3
-define i32 @func3(ptr addrspace(1) %ptr) {
+define i16 @func3(ptr addrspace(1) %ptr) {
+; ld.global.nc.u16

tra wrote:
> Nit: I'd give test functions more descriptive names. E.g. `test_ldg_u16`.
Sure, done now.


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

https://reviews.llvm.org/D144961

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


[PATCH] D145007: Driver: introduce GNU spellings to control MSVC paths

2023-03-01 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added reviewers: akhuang, hans, thakis, zahen, pkasting.
mstorsjo added a comment.

Looks reasonable to me, adding a few others for opinions. Should we have some 
tests for this? I guess testing these is somewhat environment reliant though, 
so it's probably not so easy...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145007

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


[PATCH] D144454: Add builtin for llvm set rounding

2023-03-01 Thread xiongji90 via Phabricator via cfe-commits
xiongji90 added a comment.

In D144454#4142253 , @rjmccall wrote:

> New builtins should be documented in the user manual.
>
> There are standard pragmas for changing the rounding mode, right?  What's the 
> interaction between the ability to set this dynamically with a builtin call 
> and those pragmas?

Hi, @rjmccall 
I didn't find appropriate place to document this new added builtin in 
https://github.com/llvm/llvm-project/blob/main/clang/docs/UsersManual.rst and 
didn't find a specific doc for builtins, so could you provide advice on where 
should document builtins newly added?
Thanks very much.




Comment at: clang/test/CodeGen/builtins.c:283
+  res = __builtin_flt_rounds_set(1);
+  // CHECK: call void @llvm.set.rounding(
 }

rjmccall wrote:
> Just for completeness, please test that this gets the result of the 
> expression.
Hi, @rjmccall 
I updated the test to check "llvm.set.rounding" string with input, does it meet 
your requirement?
Thanks very much.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144454

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


[PATCH] D144603: Add option to disable compiler launcher on external projects

2023-03-01 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

A more generic version might be to have a list of variables to (not) 
passthrough.

First option is to remove `{C,CXX}_COMPILER_LAUNCHER` from 
`_BOOTSTRAP_DEFAULT_PASSTHROUGH` and then include it as needed by setting 
something like 
`CLANG_BOOTSTRAP_EXTRA_PASSTHROUGH=C_COMPILER_LAUNCHER;CXX_COMPILER_LAUNCHER`.
Second option is to provide a way to filter out variable from passthrough, for 
example 
`CLANG_BOOTSTRAP_NO_PASSTHROUGH=C_COMPILER_LAUNCHER;CXX_COMPILER_LAUNCHER`.

I slightly prefer the first option, but it'd be a breaking change, so the 
second option might be the only feasible one.




Comment at: llvm/cmake/modules/LLVMExternalProjectUtils.cmake:305-310
+  set(C_COMPILER_LAUNCHER ${CMAKE_C_COMPILER_LAUNCHER})
+  set(CXX_COMPILER_LAUNCHER ${CMAKE_CXX_COMPILER_LAUNCHER})
+  if (LLVM_DISABLE_COMPILER_LAUNCHER_FOR_EXT_PROJECT)
+set(C_COMPILER_LAUNCHER "")
+set(CXX_COMPILER_LAUNCHER "")
+  endif()

I think it's better to avoid setting these at all if disabled rather than 
setting them to an empty string. You can just append these to `cmake_args`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144603

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


[PATCH] D144603: Add option to disable compiler launcher on external projects

2023-03-01 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

@beanz @smeenai do you have any preferences/other ideas?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144603

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


[PATCH] D143480: [clang][Interp] Fix derived-to-base casts for >1 levels

2023-03-01 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/D143480/new/

https://reviews.llvm.org/D143480

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


[PATCH] D143466: [clang][Interp] Fix initializing base class members

2023-03-01 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/D143466/new/

https://reviews.llvm.org/D143466

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


[PATCH] D144622: [clang[[ASTImporter] Import TemplateName correctly

2023-03-01 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added a comment.

Basically LGTM (assuming that the TC passes), I added two minor suggestions, 
but I'm not opposed to merging this in its current state.




Comment at: clang/unittests/AST/ASTImporterTest.cpp:8142-8150
+  R"(
+  template 
+  struct A;
+  template 
+  struct A {};
+  template  class T = A>
+  struct B {};

Nitpick: consider saving this string in a constant instead of repeating it 
twice.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:8201-8202
+  ->getAsRecordDecl());
+  EXPECT_TRUE(Spec1->getPreviousDecl() == Spec2 ||
+  Spec2->getPreviousDecl() == Spec1);
+  TemplateDecl *Templ1 =

For clarity, perhaps also assert that Spec1 != Spec2.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144622

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


[PATCH] D143334: [clang][Interp] Fix diagnosing uninitialized ctor record arrays

2023-03-01 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/D143334/new/

https://reviews.llvm.org/D143334

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


[PATCH] D142630: [clang][Interp] Implement virtual function calls

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

Ping


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

https://reviews.llvm.org/D142630

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


[PATCH] D142617: [clang][Interp] Check This pointer without creating InterpFrame

2023-03-01 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/D142617/new/

https://reviews.llvm.org/D142617

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


[PATCH] D141591: [clang][Interp] Properly identify not-yet-defined functions

2023-03-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1486
   bool IsBeingCompiled = Func && !Func->isFullyCompiled();
-  bool WasNotDefined = Func && !Func->hasBody();
+  bool WasNotDefined = Func && !Func->isConstexpr() && !Func->hasBody();
 

shafik wrote:
> Why the check for `isContexpr()`?
`isConstexpr()` just returns whether the function is valid (i.e. was compiled 
successfully). `hasBody()` can still return `false` for a valid function, if 
the funcdecl had no body.


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

https://reviews.llvm.org/D141591

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


[PATCH] D141472: [clang][Interp] Add function pointers

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

Ping


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

https://reviews.llvm.org/D141472

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


[clang] feba033 - [clang][ASTImporter] Improve import of InjectedClassNameType.

2023-03-01 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2023-03-01T09:26:10+01:00
New Revision: feba03340cf3a1690e75ede75ca4603acb9dc2a6

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

LOG: [clang][ASTImporter] Improve import of InjectedClassNameType.

During AST import multiple different InjectedClassNameType objects
could be created for a single class template. This can cause problems
and failed assertions when these types are compared and found to be
not the same (because the instance is different and there is no
canonical type).
The import of this type does not use the factory method in ASTContext,
probably because the preconditions are not fulfilled at that state.
The fix tries to make the code in ASTImporter work more like the code
in ASTContext::getInjectedClassNameType. If a type is stored at the
Decl or previous Decl object, it is reused instead of creating a new
one. This avoids crash at least a part of the cases.

Reviewed By: gamesh411, donat.nagy, vabridgers

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

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 3ca2b67bcb777..99f72d0a2fe64 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -1464,20 +1464,11 @@ ExpectedType 
ASTNodeImporter::VisitInjectedClassNameType(
   if (!ToDeclOrErr)
 return ToDeclOrErr.takeError();
 
-  ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType());
-  if (!ToInjTypeOrErr)
-return ToInjTypeOrErr.takeError();
-
-  // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST 
reading
-  // See comments in InjectedClassNameType definition for details
-  // return Importer.getToContext().getInjectedClassNameType(D, InjType);
-  enum {
-TypeAlignmentInBits = 4,
-TypeAlignment = 1 << TypeAlignmentInBits
-  };
-
-  return QualType(new (Importer.getToContext(), TypeAlignment)
-  InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0);
+  // The InjectedClassNameType is created in VisitRecordDecl when the
+  // T->getDecl() is imported. Here we can return the existing type.
+  const Type *Ty = (*ToDeclOrErr)->getTypeForDecl();
+  assert(Ty && isa(Ty));
+  return QualType(Ty, 0);
 }
 
 ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
@@ -2952,8 +2943,6 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl 
*D) {
 // InjectedClassNameType (see Sema::CheckClassTemplate). Update the
 // previously set type to the correct value here (ToDescribed is not
 // available at record create).
-// FIXME: The previous type is cleared but not removed from
-// ASTContext's internal storage.
 CXXRecordDecl *Injected = nullptr;
 for (NamedDecl *Found : D2CXX->noload_lookup(Name)) {
   auto *Record = dyn_cast(Found);
@@ -2963,20 +2952,34 @@ ExpectedDecl 
ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
   }
 }
 // Create an injected type for the whole redecl chain.
+// The chain may contain an already existing injected type at the 
start,
+// if yes this should be reused. We must ensure that only one type
+// object exists for the injected type (including the injected record
+// declaration), ASTContext does not check it.
 SmallVector Redecls =
 getCanonicalForwardRedeclChain(D2CXX);
+const Type *FrontTy =
+cast(Redecls.front())->getTypeForDecl();
+QualType InjSpec;
+if (auto *InjTy = FrontTy->getAs())
+  InjSpec = InjTy->getInjectedSpecializationType();
+else
+  InjSpec = ToDescribed->getInjectedClassNameSpecialization();
 for (auto *R : Redecls) {
   auto *RI = cast(R);
-  RI->setTypeForDecl(nullptr);
-  // Below we create a new injected type and assign that to the
-  // canonical decl, subsequent declarations in the chain will reuse
-  // that type.
-  Importer.getToContext().getInjectedClassNameType(
-  RI, ToDescribed->getInjectedClassNameSpecialization());
+  if (R != Redecls.front() ||
+  !isa(RI->getTypeForDecl()))
+RI->setTypeForDecl(nullptr);
+  // This function tries to get the injected type from getTypeForDecl,
+  // then from the previous declaration if possible. If not, it creates
+  // a new type.
+  Importer.getToContext().getInjectedClassNameType(RI, InjSpec);
 }
-// Set the new type for the previous injected decl too.
+// Set the new type for the injected decl too.
 if (Injected) {
   Injected->set

[PATCH] D140562: [clang][ASTImporter] Improve import of InjectedClassNameType.

2023-03-01 Thread Balázs Kéri 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 rGfeba03340cf3: [clang][ASTImporter] Improve import of 
InjectedClassNameType. (authored by balazske).

Changed prior to commit:
  https://reviews.llvm.org/D140562?vs=492106&id=501401#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140562

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8137,6 +8137,247 @@
   EXPECT_FALSE(SharedStatePtr->isNewDecl(ToBar));
 }
 
+struct ImportInjectedClassNameType : public ASTImporterOptionSpecificTestBase {
+protected:
+  const CXXRecordDecl *findInjected(const CXXRecordDecl *Parent) {
+for (Decl *Found : Parent->decls()) {
+  const auto *Record = dyn_cast(Found);
+  if (Record && Record->isInjectedClassName())
+return Record;
+}
+return nullptr;
+  }
+
+  void checkInjType(const CXXRecordDecl *D) {
+// The whole redecl chain should have the same InjectedClassNameType
+// instance. The injected record declaration is a separate chain, this
+// should contain the same type too.
+const Type *Ty = nullptr;
+for (const Decl *ReD : D->redecls()) {
+  const auto *ReRD = cast(ReD);
+  EXPECT_TRUE(ReRD->getTypeForDecl());
+  EXPECT_TRUE(!Ty || Ty == ReRD->getTypeForDecl());
+  Ty = ReRD->getTypeForDecl();
+}
+ASSERT_TRUE(Ty);
+const auto *InjTy = Ty->castAs();
+EXPECT_TRUE(InjTy);
+if (CXXRecordDecl *Def = D->getDefinition()) {
+  const CXXRecordDecl *InjRD = findInjected(Def);
+  EXPECT_TRUE(InjRD);
+  EXPECT_EQ(InjRD->getTypeForDecl(), InjTy);
+}
+  }
+
+  void testImport(Decl *ToTU, Decl *FromTU, Decl *FromD) {
+checkInjType(cast(FromD));
+Decl *ToD = Import(FromD, Lang_CXX11);
+if (auto *ToRD = dyn_cast(ToD))
+  checkInjType(ToRD);
+  }
+
+  const char *ToCodeA =
+  R"(
+  template 
+  struct A;
+  )";
+  const char *ToCodeADef =
+  R"(
+  template 
+  struct A {
+typedef A T1;
+  };
+  )";
+  const char *ToCodeC =
+  R"(
+  template 
+  struct C;
+  )";
+  const char *ToCodeCDef =
+  R"(
+  template 
+  struct A {
+typedef A T1;
+  };
+
+  template 
+  struct B {};
+
+  template
+  struct C {
+typedef typename A::T1 T1;
+typedef B T2;
+typedef B T3;
+  };
+  )";
+  const char *FromCode =
+  R"(
+  template 
+  struct A;
+  template 
+  struct A {
+typedef A T1;
+  };
+  template 
+  struct A;
+
+  template 
+  struct B {};
+
+  template 
+  struct C;
+  template 
+  struct C {
+typedef typename A::T1 T1;
+typedef B T2;
+typedef B T3;
+  };
+  template 
+  struct C;
+
+  template 
+  struct D {
+void f(typename C::T3 *);
+  };
+  )";
+};
+
+TEST_P(ImportInjectedClassNameType, ImportADef) {
+  Decl *ToTU = getToTuDecl(ToCodeA, Lang_CXX11);
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX11);
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A"), isDefinition()));
+  testImport(ToTU, FromTU, FromA);
+}
+
+TEST_P(ImportInjectedClassNameType, ImportAFirst) {
+  Decl *ToTU = getToTuDecl(ToCodeA, Lang_CXX11);
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX11);
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+  testImport(ToTU, FromTU, FromA);
+}
+
+TEST_P(ImportInjectedClassNameType, ImportALast) {
+  Decl *ToTU = getToTuDecl(ToCodeA, Lang_CXX11);
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX11);
+  auto *FromA = LastDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+  testImport(ToTU, FromTU, FromA);
+}
+
+TEST_P(ImportInjectedClassNameType, ImportADefToDef) {
+  Decl *ToTU = getToTuDecl(ToCodeADef, Lang_CXX11);
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX11);
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A"), isDefinition()));
+  testImport(ToTU, FromTU, FromA);
+}
+
+TEST_P(ImportInjectedClassNameType, ImportAFirstToDef) {
+  Decl *ToTU = getToTuDecl(ToCodeADef, Lang_CXX11);
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX11);
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+  testImport(ToTU, FromTU, FromA);
+}
+
+TEST_P(ImportInjectedClassNameType, ImportALastToDef) {
+  Decl *ToTU = getToTuDecl(ToCodeADef, Lang_CXX11);
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX11);
+  auto *FromA = LastDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+  testImport(ToTU, FromTU, FromA)

[PATCH] D144709: [clang-format] Improve QualifierAlignment

2023-03-01 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

As tests currently fail can you set it to "planned changes" until they pass

  [  FAILED  ] 5 tests, listed below:
  [  FAILED  ] QualifierFixerTest.RightQualifier
  [  FAILED  ] QualifierFixerTest.LeftQualifier
  [  FAILED  ] QualifierFixerTest.ConstVolatileQualifiersOrder
  [  FAILED  ] QualifierFixerTest.MoveConstBeyondType
  [  FAILED  ] QualifierFixerTest.TemplatesRight


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[PATCH] D145031: [clang-tidy] use isConvertingConstructor to simplify code

2023-03-01 Thread thyecust via Phabricator via cfe-commits
thyecust updated this revision to Diff 501407.

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

https://reviews.llvm.org/D145031

Files:
  clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp


Index: clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
+++ clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
@@ -98,7 +98,7 @@
 
   const auto *Ctor = Result.Nodes.getNodeAs("ctor");
   if (Ctor->isOutOfLine() || Ctor->getNumParams() == 0 ||
-  Ctor->getMinRequiredArguments() > 1)
+  Ctor->isConvertingConstructor(true))
 return;
 
   bool TakesInitializerList = isStdInitializerList(


Index: clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
+++ clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
@@ -98,7 +98,7 @@
 
   const auto *Ctor = Result.Nodes.getNodeAs("ctor");
   if (Ctor->isOutOfLine() || Ctor->getNumParams() == 0 ||
-  Ctor->getMinRequiredArguments() > 1)
+  Ctor->isConvertingConstructor(true))
 return;
 
   bool TakesInitializerList = isStdInitializerList(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144709: [clang-format] Improve QualifierAlignment

2023-03-01 Thread Alexander Hederstaf via Phabricator via cfe-commits
AlexanderHederstaf updated this revision to Diff 501420.
AlexanderHederstaf added a comment.

Distinguish configured qualifiers from other qualifiers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

Files:
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/QualifierAlignmentFixer.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/QualifierFixerTest.cpp

Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -241,7 +241,7 @@
   verifyFormat("int const *b;", Style);
   verifyFormat("int const &b;", Style);
   verifyFormat("int const &&b;", Style);
-  verifyFormat("int const *b const;", Style);
+  verifyFormat("int const *const b;", Style);
   verifyFormat("int *const c;", Style);
 
   verifyFormat("const Foo a;", Style);
@@ -252,7 +252,7 @@
   verifyFormat("Foo const *b;", Style);
   verifyFormat("Foo const &b;", Style);
   verifyFormat("Foo const &&b;", Style);
-  verifyFormat("Foo const *b const;", Style);
+  verifyFormat("Foo const *const b;", Style);
 
   verifyFormat("LLVM_NODISCARD const int &Foo();", Style);
   verifyFormat("LLVM_NODISCARD int const &Foo();", Style);
@@ -275,7 +275,7 @@
   verifyFormat("int const *b;", Style);
   verifyFormat("int const &b;", Style);
   verifyFormat("int const &&b;", Style);
-  verifyFormat("int const *b const;", Style);
+  verifyFormat("int const *const b;", Style);
   verifyFormat("int *const c;", Style);
 
   verifyFormat("Foo const a;", Style);
@@ -286,7 +286,7 @@
   verifyFormat("Foo const *b;", Style);
   verifyFormat("Foo const &b;", Style);
   verifyFormat("Foo const &&b;", Style);
-  verifyFormat("Foo const *b const;", Style);
+  verifyFormat("Foo const *const b;", Style);
   verifyFormat("Foo *const b;", Style);
   verifyFormat("Foo const *const b;", Style);
   verifyFormat("auto const v = get_value();", Style);
@@ -303,6 +303,11 @@
   verifyFormat("void foo() const final;", Style);
   verifyFormat("void foo() const final LLVM_READONLY;", Style);
   verifyFormat("void foo() const LLVM_READONLY;", Style);
+  verifyFormat("void foo() const volatile override;", Style);
+  verifyFormat("void foo() const volatile override LLVM_READONLY;", Style);
+  verifyFormat("void foo() const volatile final;", Style);
+  verifyFormat("void foo() const volatile final LLVM_READONLY;", Style);
+  verifyFormat("void foo() const volatile LLVM_READONLY;", Style);
 
   verifyFormat(
   "template  explicit Action(Action const &action);",
@@ -343,6 +348,7 @@
   verifyFormat("int const volatile;", "volatile const int;", Style);
   verifyFormat("int const volatile;", "const volatile int;", Style);
   verifyFormat("int const volatile;", "const int volatile;", Style);
+
   verifyFormat("int const volatile *restrict;", "volatile const int *restrict;",
Style);
   verifyFormat("int const volatile *restrict;", "const volatile int *restrict;",
@@ -350,9 +356,44 @@
   verifyFormat("int const volatile *restrict;", "const int volatile *restrict;",
Style);
 
+  verifyFormat("long long int const volatile;", "const long long int volatile;",
+   Style);
+  verifyFormat("long long int const volatile;", "long const long int volatile;",
+   Style);
+  verifyFormat("long long int const volatile;", "long long volatile int const;",
+   Style);
+  verifyFormat("long long int const volatile;", "long volatile long const int;",
+   Style);
+  verifyFormat("long long int const volatile;", "const long long volatile int;",
+   Style);
+
   verifyFormat("static int const bat;", "static const int bat;", Style);
   verifyFormat("static int const bat;", "static int const bat;", Style);
 
+  // static is not configured, unchanged on the left of the right hand
+  // qualifiers.
+  verifyFormat("int static const volatile;", "volatile const int static;",
+   Style);
+  verifyFormat("int static const volatile;", "const volatile int static;",
+   Style);
+  verifyFormat("int static const volatile;", "const int volatile static;",
+   Style);
+  verifyFormat("Foo static const volatile;", "volatile const Foo static;",
+   Style);
+  verifyFormat("Foo static const volatile;", "const volatile Foo static;",
+   Style);
+  verifyFormat("Foo static const volatile;", "const Foo volatile static;",
+   Style);
+
+  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::Bar const volatile A::*;",
+ 

[PATCH] D144709: [clang-format] Improve QualifierAlignment

2023-03-01 Thread Alexander Hederstaf via Phabricator via cfe-commits
AlexanderHederstaf added a comment.

This code from llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp failed 
with **Right** but without a full list of specifiers. As **static** was not 
configured, the } was not discovered by **IsRightQualifier**. Changed some of 
the qualifier tests to check against the full list instead.

  struct ExecutionClass {
ExecutionMode Mask;
const char *Description;
  } static const kExecutionClasses[] = {
  {ExecutionMode::ALWAYS_SERIAL_IMPLICIT_REGS_ALIAS |
   ExecutionMode::ALWAYS_SERIAL_TIED_REGS_ALIAS,
   "Repeating a single implicitly serial instruction"},
  {ExecutionMode::SERIAL_VIA_EXPLICIT_REGS,
   "Repeating a single explicitly serial instruction"},
  {ExecutionMode::SERIAL_VIA_MEMORY_INSTR |
   ExecutionMode::SERIAL_VIA_NON_MEMORY_INSTR,
   "Repeating two instructions"},
  };

Resulted in

  } static kExecutionClasses const[] = {

Which is now fixed. This struct will be left unchanged as with other structs.

I ran clang format on all files in clang/ and llvm/, where I had added 
QualifierAlignment: Right to any .clang-format. I built with

  cmake -S llvm -B build -G Ninja -DCMAKE_BUILD_TYPE=Release 
-DLLVM_ENABLE_PROJECTS="clang"
  cmake --build build

Is that sufficient or did you imagine some other build?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[PATCH] D144709: [clang-format] Improve QualifierAlignment

2023-03-01 Thread Alexander Hederstaf via Phabricator via cfe-commits
AlexanderHederstaf added a comment.

In D144709#4160820 , @MyDeveloperDay 
wrote:

> As tests currently fail can you set it to "planned changes" until they pass
>
>   [  FAILED  ] 5 tests, listed below:
>   [  FAILED  ] QualifierFixerTest.RightQualifier
>   [  FAILED  ] QualifierFixerTest.LeftQualifier
>   [  FAILED  ] QualifierFixerTest.ConstVolatileQualifiersOrder
>   [  FAILED  ] QualifierFixerTest.MoveConstBeyondType
>   [  FAILED  ] QualifierFixerTest.TemplatesRight

Tests should pass now, but how/where do I set that setting?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[PATCH] D145047: Fix broken link on Clang documentation page

2023-03-01 Thread Tulio Leao via Phabricator via cfe-commits
tupaschoal created this revision.
tupaschoal added reviewers: vhscampos, brenoguim.
Herald added a project: All.
tupaschoal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

While browsing the latest clang manual 
, I came across this warning and 
clicked, but it leads to a broken page, apparently because it's missing the 
trailing `/`. Seems to be the only place where it's missing in the whole of 
LLVM monorepo.

F26690053: image.png 
F26690057: image.png 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145047

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -13,7 +13,7 @@
   .. warning::
  These are in-progress notes for the upcoming Clang |version| release.
  Release notes for previous releases can be found on
- `the Releases Page `_.
+ `the Releases Page `_.
 
 Introduction
 


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -13,7 +13,7 @@
   .. warning::
  These are in-progress notes for the upcoming Clang |version| release.
  Release notes for previous releases can be found on
- `the Releases Page `_.
+ `the Releases Page `_.
 
 Introduction
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144179: [Clang] Added functionality to provide config file name via env variable

2023-03-01 Thread Jolanta Jensen via Phabricator via cfe-commits
jolanta.jensen updated this revision to Diff 501428.
jolanta.jensen added a comment.

Test adjustment for Windows. Disabling read permissions using chmod does not 
seem to work on Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144179

Files:
  clang/include/clang/Config/config.h.cmake
  clang/include/clang/Driver/Driver.h
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/config-file-from-env.c

Index: clang/test/Driver/config-file-from-env.c
===
--- /dev/null
+++ clang/test/Driver/config-file-from-env.c
@@ -0,0 +1,51 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: mkdir %t/empty_dir
+// RUN: echo "-Wall" > %t/c.cfg
+// RUN: echo "-ffast-math" > %t/cxx.cfg
+// RUN: touch %t/unreadable.cfg
+// RUN: chmod a-r %t/unreadable.cfg
+// RUN: touch %t/test.c
+// RUN: touch %t/test.cpp
+
+// RUN: env CONFIG_FILE=%t/c.cfg %clang -S %t/test.c -o /dev/null -### 2>&1 | FileCheck %s -check-prefix CHECK-C1
+// CHECK-C1: Configuration file: {{.*[\/\\]}}c.cfg
+// CHECK-C1: -Wall
+
+// RUN: %if !system-windows %{env CONFIG_FILE=%t/unreadable.cfg not %clang -S %t/test.c -o /dev/null -### 2>&1 | FileCheck %s -check-prefix CHECK-C2 %}
+// CHECK-C2: error: cannot read configuration file '{{.*[\/\\]}}unreadable.cfg'
+
+// RUN: env CONFIG_FILE=%t/c.cfg %clang -S %t/test.c --config %S/Inputs/config-1.cfg -o /dev/null -### 2>&1 | FileCheck %s -check-prefix CHECK-C3
+// CHECK-C3: Configuration file: {{.*[\/\\]}}config-1.cfg
+// CHECK-C3: -Werror
+// CHECK-C3-NOT: -Wall
+
+// RUN: env CONFIG_FILE= not %clang -S %t/test.c -o /dev/null -### 2>&1 | FileCheck %s -check-prefix CHECK-C4
+// CHECK-C4: error: cannot read configuration file ''
+
+// RUN: env CONFIG_FILE=%t/empty_dir not %clang -S %t/test.c -o /dev/null -### 2>&1 | FileCheck %s -check-prefix CHECK-C5
+// CHECK-C5: error: configuration file '{{.*[\/\\]}}empty_dir' cannot be opened: not a regular file
+
+// RUN: env CONFIG_FILE=%t/cxx.cfg %clang++ -S %t/test.cpp -o /dev/null -### 2>&1 | FileCheck %s -check-prefix CHECK-CXX1
+// CHECK-CXX1: Configuration file: {{.*[\/\\]}}cxx.cfg
+// CHECK-CXX1: -ffast-math
+
+// RUN: %if !system-windows %{env CONFIG_FILE=%t/unreadable.cfg not %clang++ -S %t/test.cpp -o /dev/null -### 2>&1 | FileCheck %s -check-prefix CHECK-CXX2 %}
+// CHECK-CXX2: error: cannot read configuration file '{{.*[\/\\]}}unreadable.cfg'
+
+// RUN: env CONFIG_FILE=%t/cxx.cfg %clang++ -S %t/test.cpp --config %S/Inputs/config-1.cfg -o /dev/null -### 2>&1 | FileCheck %s -check-prefix CHECK-CXX3
+// CHECK-CXX3: Configuration file: {{.*[\/\\]}}config-1.cfg
+// CHECK-CXX3: -Werror
+// CHECK-CXX3-NOT: -ffast-math
+
+// RUN: env CONFIG_FILE= not %clang++ -S %t/test.cpp -o /dev/null -### 2>&1 | FileCheck %s -check-prefix CHECK-CXX4
+// CHECK-CXX4: error: cannot read configuration file ''
+
+// RUN: env CONFIG_FILE=%t/empty_dir not %clang++ -S %t/test.cpp -o /dev/null -### 2>&1 | FileCheck %s -check-prefix CHECK-CXX5
+// CHECK-CXX5: error: configuration file '{{.*[\/\\]}}empty_dir' cannot be opened: not a regular file
+
+// RUN: env CONFIG_FILE=%t/c.cfg %clang++ --config=%t/cxx.cfg -S %t/test.cpp -o /dev/null -### 2>&1 | FileCheck %s -check-prefix CHECK-CXX6
+// CHECK-CXX6-NOT: Configuration file: {{.*[\/\\]}}c.cfg
+// CHECK-CXX6-NOT: -Wall
+
+// RUN: rm -rf %t
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1034,6 +1034,35 @@
   return false;
 }
 
+bool Driver::readConfigFileFromEnv() {
+  llvm::cl::ExpansionContext ExpCtx(Saver.getAllocator(),
+llvm::cl::tokenizeConfigFile);
+  ExpCtx.setVFS(&getVFS());
+  std::string EnvCfgName = "CONFIG_FILE";
+
+#if defined(ENV_CONFIG_FILE_NAME)
+  EnvCfgName = ENV_CONFIG_FILE_NAME;
+#endif
+  const char *EnvCfgFileName = getenv(EnvCfgName.c_str());
+
+  if (!EnvCfgFileName)
+return false;
+
+  std::string CfgFileName = EnvCfgFileName;
+  if (CfgFileName.empty()) {
+Diag(diag::err_drv_cannot_read_config_file) << CfgFileName << "";
+return true;
+  }
+
+  // If argument contains directory separator, treat it as a path to
+  // configuration file.
+  SmallString<128> CfgFilePath;
+  if (llvm::sys::path::is_relative(CfgFileName))
+llvm::sys::fs::current_path(CfgFilePath);
+  llvm::sys::path::append(CfgFilePath, CfgFileName);
+  return readConfigFile(CfgFilePath, ExpCtx);
+}
+
 bool Driver::loadConfigFiles() {
   llvm::cl::ExpansionContext ExpCtx(Saver.getAllocator(),
 llvm::cl::tokenizeConfigFile);
@@ -1099,6 +1128,9 @@
 }
   }
 
+  if (ConfigFiles.empty())
+return readConfigFileFromEnv();
+
   // No error occurred.
   return false;
 }
Index: clang/include/clang/Driver/Driver.h
===
--- clang/include/clang/Driver

[PATCH] D145047: Fix broken link on Clang documentation page

2023-03-01 Thread Tulio Leao via Phabricator via cfe-commits
tupaschoal added a subscriber: royjacobson.
tupaschoal added a comment.

Btw seems to have been broken recently by 
https://github.com/llvm/llvm-project/commit/f5aa8d191a5b5ea118281bfa410bdb2ee961c704,
 so tagging @royjacobson too


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145047

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


[PATCH] D145040: Add test for Flags.data_flow_trace

2023-03-01 Thread Ilya Karapsin via Phabricator via cfe-commits
karapsinie updated this revision to Diff 501432.
karapsinie added a comment.
Herald added a reviewer: shafik.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

arc diff git merge-base HEAD origin --update D145040 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145040

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/Expr.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Preprocessor/feature_tests.c
  clang/test/Preprocessor/feature_tests.cpp
  clang/test/Sema/source_location.c
  clang/test/SemaCXX/Inputs/source-location-file.h
  clang/test/SemaCXX/source_location.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -259,6 +259,10 @@
  Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
  sourceLocExpr(hasBuiltinStr("__builtin_FILE");
+  testImport("void declToImport() { (void)__builtin_FILE_NAME(); }", Lang_CXX03,
+ "", Lang_CXX03, Verifier,
+ functionDecl(hasDescendant(
+ sourceLocExpr(hasBuiltinStr("__builtin_FILE_NAME");
   testImport("void declToImport() { (void)__builtin_COLUMN(); }", Lang_CXX03,
  "", Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
@@ -1546,7 +1550,7 @@
   R"s(
   struct declToImport {
 int a = d;
-union { 
+union {
   int b;
   int c;
 };
@@ -3804,7 +3808,7 @@
 int a[2] = {1,2};
 auto [x1,y1] = a;
 auto& [x2,y2] = a;
-
+
 struct S {
   mutable int x1 : 2;
   volatile double y1;
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -84,6 +84,7 @@
 static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
+static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
 
@@ -91,6 +92,7 @@
 static_assert(noexcept(__builtin_LINE()));
 static_assert(noexcept(__builtin_COLUMN()));
 static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FILE_NAME()));
 static_assert(noexcept(__builtin_FUNCTION()));
 static_assert(noexcept(__builtin_source_location()));
 
@@ -346,6 +348,54 @@
 
 } // namespace test_file
 
+//===--===//
+//__builtin_FILE_NAME()
+//===--===//
+
+namespace test_file_name {
+constexpr const char *test_file_name_simple(
+  const char *__f = __builtin_FILE_NAME()) {
+  return __f;
+}
+void test_function() {
+#line 900
+  static_assert(is_equal(test_file_name_simple(), __FILE_NAME__));
+  static_assert(is_equal(SLF::test_function_filename(), __FILE_NAME__), "");
+  static_assert(is_equal(SLF::test_function_filename_template(42),
+ __FILE_NAME__), "");
+
+  static_assert(is_equal(SLF::test_function_filename_indirect(),
+ SLF::global_info_filename), "");
+  static_assert(is_equal(SLF::test_function_filename_template_indirect(42),
+ SLF::global_info_filename), "");
+
+  static_assert(test_file_name_simple() != nullptr);
+  static_assert(is_equal(test_file_name_simple(), "source_location.cpp"));
+}
+
+void test_class() {
+#line 315
+  using SLF::TestClass;
+  constexpr TestClass Default;
+  constexpr TestClass InParam{42};
+  constexpr TestClass Template{42, 42};
+  constexpr auto *F = Default.info_file_name;
+  constexpr auto Char = F[0];
+  static_assert(is_equal(Default.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.ctor_info_file_name, __FILE_NAME__), "");
+}
+
+void test_aggr_class() {
+  using Agg = SLF::AggrClass<>;
+  constexpr Agg Default{};
+  constexpr Agg InitOne{42};
+  static_assert(is_equal(Default.init_info_file_name, __FILE_NAME__), "");
+  static_assert(is_equal(InitOne.init_info_file_name, __FILE_NAME__), "");
+}
+
+} // namespace test_file_name
+
 //===--===//
 //__builtin_FUNCTION()
 //===--===//
@@ -487,6 +537,7 @@
 #line 44 "test_file.c"
 static_assert(is_equal("test_file.c", __FILE__));
 static_assert(is_equal("test_file.c", __builtin_FILE()));
+static_assert(is_equal("test_file.c", __builtin_FILE_NAME()));
 static_assert(is_equal("test_file.

[PATCH] D145031: [clang-tidy] use isConvertingConstructor to simplify code

2023-03-01 Thread thyecust via Phabricator via cfe-commits
thyecust abandoned this revision.
thyecust added a comment.

this change looks meaningless now


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

https://reviews.llvm.org/D145031

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


[PATCH] D144866: [clang] Fix aggregate initialization inside lambda constexpr

2023-03-01 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Thanks for the review @shafik .




Comment at: clang/lib/AST/ExprConstant.cpp:8763
 if (isLambdaCallOperator(Info.CurrentCall->Callee)) {
-  // Ensure we actually have captured 'this'. (an error will have
-  // been previously reported if not).
+  // Ensure we actually have captured 'this'. If something was wrong with
+  // 'this' capture, the error would have been previously reported.

shafik wrote:
> shafik wrote:
> > Fznamznon wrote:
> > > shafik wrote:
> > > > It might be worth it to review all the examples here: 
> > > > https://eel.is/c++draft/expr.prim.lambda
> > > > 
> > > > and make sure the test we have actually covers all the scenarios. It 
> > > > looks like we capture most of them but I have not gone over them fully.
> > > At least the ones about `this` capture seem to be working and covered. 
> > > Not all of them have the same behavior as described though, for example 
> > > on https://eel.is/c++draft/expr.prim.lambda#closure-6 clang complains 
> > > about missing capture, though gcc agrees https://godbolt.org/z/hfxbEP5fW 
> > > , so this is probably a bug in the example. Anyway I think this is a bit 
> > > out of the scope of the patch.
> > I will dig into that discrepancy. 
> If you move the lambda to be a global, it works: 
> https://godbolt.org/z/84ax7518o which is what the original example has.
Yes, this is understandable. But in the example there is also an `assert` which 
doesn't do well in global scope.

BTW, in case this is interesting, another one that doesn't seem to be working 
with clang is https://eel.is/c++draft/expr.prim.lambda#capture-example-2 
https://godbolt.org/z/dP71j3MxK.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144866

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


[clang] 831591b - [NFC][clang] Refine tests by adding `:` to checks

2023-03-01 Thread Mariya Podchishchaeva via cfe-commits

Author: Mariya Podchishchaeva
Date: 2023-03-01T05:58:34-05:00
New Revision: 831591b2a075d86f7ae51d0f688af1ddcf360707

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

LOG: [NFC][clang] Refine tests by adding `:` to checks

The tests can fail if wokring directory where the tests were launched
has a `error` substring in its path.

Reviewed By: benlangmuir

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

Added: 


Modified: 
clang/test/Driver/unknown-std.S
clang/test/Index/allow-editor-placeholders.cpp
clang/test/VFS/real-path-found-first.m
clang/test/VFS/vfsroot-include.c

Removed: 




diff  --git a/clang/test/Driver/unknown-std.S b/clang/test/Driver/unknown-std.S
index ecb6a9e92fafd..eac102d9352d7 100644
--- a/clang/test/Driver/unknown-std.S
+++ b/clang/test/Driver/unknown-std.S
@@ -1,2 +1,2 @@
 // RUN: %clang -std=c++11 %s -E -o /dev/null 2>&1 | FileCheck %s --allow-empty
-// CHECK-NOT: error
+// CHECK-NOT: error:

diff  --git a/clang/test/Index/allow-editor-placeholders.cpp 
b/clang/test/Index/allow-editor-placeholders.cpp
index 5a7207d3f07a6..2870777d935c7 100644
--- a/clang/test/Index/allow-editor-placeholders.cpp
+++ b/clang/test/Index/allow-editor-placeholders.cpp
@@ -2,4 +2,4 @@
 
 <#placeholder#>;
 
-// CHECK-NOT: error
+// CHECK-NOT: error:

diff  --git a/clang/test/VFS/real-path-found-first.m 
b/clang/test/VFS/real-path-found-first.m
index 34a34098f4a20..60a7b10199f12 100644
--- a/clang/test/VFS/real-path-found-first.m
+++ b/clang/test/VFS/real-path-found-first.m
@@ -39,7 +39,7 @@
 // RUN: -ivfsoverlay %t.yaml -fsyntax-only -Rmodule-include-translation \
 // RUN: -Werror=non-modular-include-in-framework-module | FileCheck %s
 // CHECK: warning: treating
-// CHECK-NOT: error
+// CHECK-NOT: error:
 
 // With a VFS-mapped module map file
 // RUN: mv %t/SomeFramework.framework/Modules/module.modulemap 
%t/hide_module.map

diff  --git a/clang/test/VFS/vfsroot-include.c 
b/clang/test/VFS/vfsroot-include.c
index eb641c58a650d..99c9b4cca0c12 100644
--- a/clang/test/VFS/vfsroot-include.c
+++ b/clang/test/VFS/vfsroot-include.c
@@ -13,4 +13,4 @@
 #include "actual_header.h"
 // CHECK: fatal error: 'actual_header.h' file not found
 // CHECK: 1 error generated.
-// CHECK-NOT: error
+// CHECK-NOT: error:



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


[PATCH] D144495: [NFC][clang] Refine tests by adding `:` to checks

2023-03-01 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG831591b2a075: [NFC][clang] Refine tests by adding `:` to 
checks (authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144495

Files:
  clang/test/Driver/unknown-std.S
  clang/test/Index/allow-editor-placeholders.cpp
  clang/test/VFS/real-path-found-first.m
  clang/test/VFS/vfsroot-include.c


Index: clang/test/VFS/vfsroot-include.c
===
--- clang/test/VFS/vfsroot-include.c
+++ clang/test/VFS/vfsroot-include.c
@@ -13,4 +13,4 @@
 #include "actual_header.h"
 // CHECK: fatal error: 'actual_header.h' file not found
 // CHECK: 1 error generated.
-// CHECK-NOT: error
+// CHECK-NOT: error:
Index: clang/test/VFS/real-path-found-first.m
===
--- clang/test/VFS/real-path-found-first.m
+++ clang/test/VFS/real-path-found-first.m
@@ -39,7 +39,7 @@
 // RUN: -ivfsoverlay %t.yaml -fsyntax-only -Rmodule-include-translation \
 // RUN: -Werror=non-modular-include-in-framework-module | FileCheck %s
 // CHECK: warning: treating
-// CHECK-NOT: error
+// CHECK-NOT: error:
 
 // With a VFS-mapped module map file
 // RUN: mv %t/SomeFramework.framework/Modules/module.modulemap 
%t/hide_module.map
Index: clang/test/Index/allow-editor-placeholders.cpp
===
--- clang/test/Index/allow-editor-placeholders.cpp
+++ clang/test/Index/allow-editor-placeholders.cpp
@@ -2,4 +2,4 @@
 
 <#placeholder#>;
 
-// CHECK-NOT: error
+// CHECK-NOT: error:
Index: clang/test/Driver/unknown-std.S
===
--- clang/test/Driver/unknown-std.S
+++ clang/test/Driver/unknown-std.S
@@ -1,2 +1,2 @@
 // RUN: %clang -std=c++11 %s -E -o /dev/null 2>&1 | FileCheck %s --allow-empty
-// CHECK-NOT: error
+// CHECK-NOT: error:


Index: clang/test/VFS/vfsroot-include.c
===
--- clang/test/VFS/vfsroot-include.c
+++ clang/test/VFS/vfsroot-include.c
@@ -13,4 +13,4 @@
 #include "actual_header.h"
 // CHECK: fatal error: 'actual_header.h' file not found
 // CHECK: 1 error generated.
-// CHECK-NOT: error
+// CHECK-NOT: error:
Index: clang/test/VFS/real-path-found-first.m
===
--- clang/test/VFS/real-path-found-first.m
+++ clang/test/VFS/real-path-found-first.m
@@ -39,7 +39,7 @@
 // RUN: -ivfsoverlay %t.yaml -fsyntax-only -Rmodule-include-translation \
 // RUN: -Werror=non-modular-include-in-framework-module | FileCheck %s
 // CHECK: warning: treating
-// CHECK-NOT: error
+// CHECK-NOT: error:
 
 // With a VFS-mapped module map file
 // RUN: mv %t/SomeFramework.framework/Modules/module.modulemap %t/hide_module.map
Index: clang/test/Index/allow-editor-placeholders.cpp
===
--- clang/test/Index/allow-editor-placeholders.cpp
+++ clang/test/Index/allow-editor-placeholders.cpp
@@ -2,4 +2,4 @@
 
 <#placeholder#>;
 
-// CHECK-NOT: error
+// CHECK-NOT: error:
Index: clang/test/Driver/unknown-std.S
===
--- clang/test/Driver/unknown-std.S
+++ clang/test/Driver/unknown-std.S
@@ -1,2 +1,2 @@
 // RUN: %clang -std=c++11 %s -E -o /dev/null 2>&1 | FileCheck %s --allow-empty
-// CHECK-NOT: error
+// CHECK-NOT: error:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145040: Add test for Flags.data_flow_trace

2023-03-01 Thread Ilya Karapsin via Phabricator via cfe-commits
karapsinie updated this revision to Diff 501449.
karapsinie added a comment.

Attempt to restore


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145040

Files:
  compiler-rt/lib/fuzzer/FuzzerDriver.cpp


Index: compiler-rt/lib/fuzzer/FuzzerDriver.cpp
===
--- compiler-rt/lib/fuzzer/FuzzerDriver.cpp
+++ compiler-rt/lib/fuzzer/FuzzerDriver.cpp
@@ -797,7 +797,7 @@
   if (Flags.verbosity)
 Printf("INFO: Seed: %u\n", Seed);
 
-  if (Flags.collect_data_flow && !Flags.fork &&
+  if (Flags.collect_data_flow && Flags.data_flow_trace && !Flags.fork &&
   !(Flags.merge || Flags.set_cover_merge)) {
 if (RunIndividualFiles)
   return CollectDataFlow(Flags.collect_data_flow, Flags.data_flow_trace,


Index: compiler-rt/lib/fuzzer/FuzzerDriver.cpp
===
--- compiler-rt/lib/fuzzer/FuzzerDriver.cpp
+++ compiler-rt/lib/fuzzer/FuzzerDriver.cpp
@@ -797,7 +797,7 @@
   if (Flags.verbosity)
 Printf("INFO: Seed: %u\n", Seed);
 
-  if (Flags.collect_data_flow && !Flags.fork &&
+  if (Flags.collect_data_flow && Flags.data_flow_trace && !Flags.fork &&
   !(Flags.merge || Flags.set_cover_merge)) {
 if (RunIndividualFiles)
   return CollectDataFlow(Flags.collect_data_flow, Flags.data_flow_trace,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144878: __builtin_FILE_NAME()

2023-03-01 Thread Ilya Karapsin via Phabricator via cfe-commits
karapsinie added a comment.

I tried rebase revision, but edit other revision 
(https://reviews.llvm.org/D145040).
We need to rebase the revision, because the tests are falling, because there is 
no this commit: 
https://reviews.llvm.org/rG24d144571dbffc6993d13fb7ca781248eed024de
How do it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144878

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


[PATCH] D144405: [clang][pp] Handle attributes defined by plugin in __has_attribute

2023-03-01 Thread Anders Waldenborg via Phabricator via cfe-commits
wanders added inline comments.



Comment at: clang/lib/Basic/Attributes.cpp:46
+  for (auto &AttrPlugin : getAttributePluginInstances()) {
+for (auto &S : AttrPlugin->Spellings)
+  if (S.Syntax == Syntax && S.NormalizedFullName == Name)

erichkeane wrote:
> I think this should be a property of the AttributePlugin type, where you send 
> it the Syntax/Name and it checks to see if it is provided. 
Do you think I should do something like this? 

(refactor based on mainline)

```
diff --git a/clang/include/clang/Sema/ParsedAttr.h 
b/clang/include/clang/Sema/ParsedAttr.h
index f060564e6719..635580ac599b 100644
--- a/clang/include/clang/Sema/ParsedAttr.h
+++ b/clang/include/clang/Sema/ParsedAttr.h
@@ -98,6 +98,13 @@ protected:
 public:
   virtual ~ParsedAttrInfo() = default;
 
+  /// Check if this attribute can be spelled like this. Only used for plugin 
attributes
+  virtual bool hasSpelling(AttributeCommonInfo::Syntax Syntax, StringRef Name) 
{
+return llvm::any_of(Spellings, [&] (const Spelling &S) {
+  return (S.Syntax == Syntax && S.NormalizedFullName == Name);
+});
+  }
+
   /// Check if this attribute appertains to D, and issue a diagnostic if not.
   virtual bool diagAppertainsToDecl(Sema &S, const ParsedAttr &Attr,
 const Decl *D) const {
diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index c1e39acb14ec..b53132d73d79 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -135,8 +135,7 @@ const ParsedAttrInfo &ParsedAttrInfo::get(const 
AttributeCommonInfo &A) {
 SyntaxUsed = AttributeCommonInfo::AS_Keyword;
 
   for (auto &Ptr : *PluginAttrInstances)
-for (auto &S : Ptr->Spellings)
-  if (S.Syntax == SyntaxUsed && S.NormalizedFullName == FullName)
+if (Ptr->handlesSpelling(SyntaxUsed, FullName))
 return *Ptr;
 
   // If we failed to find a match then return a default ParsedAttrInfo.
```

Maybe not `virtual` as allowing plugins to handle attributes not in their 
Spellings array maybe is too flexible?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144405

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


[clang] 570995e - [clang][test][RISCV] Add RISC-V to clang/test/Sema/Float16.c

2023-03-01 Thread Alex Bradbury via cfe-commits

Author: Alex Bradbury
Date: 2023-03-01T11:33:30Z
New Revision: 570995eba2f93d639e69b6b12817d44a3b26cc72

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

LOG: [clang][test][RISCV] Add RISC-V to clang/test/Sema/Float16.c

Since D105001, HasFloat16 was unconditionally set to true for RISC-V.
This patch adds test coverage for this.

Added: 


Modified: 
clang/test/Sema/Float16.c

Removed: 




diff  --git a/clang/test/Sema/Float16.c b/clang/test/Sema/Float16.c
index 26c604fed27aa..9269a0ded4eb9 100644
--- a/clang/test/Sema/Float16.c
+++ b/clang/test/Sema/Float16.c
@@ -4,6 +4,8 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s -DHAVE
+// RUN: %clang_cc1 -fsyntax-only -verify -triple riscv32 %s -DHAVE
+// RUN: %clang_cc1 -fsyntax-only -verify -triple riscv64 %s -DHAVE
 
 #ifndef HAVE
 // expected-error@+2{{_Float16 is not supported on this target}}



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


[PATCH] D144878: __builtin_FILE_NAME()

2023-03-01 Thread Ilya Karapsin via Phabricator via cfe-commits
karapsinie updated this revision to Diff 501451.
karapsinie added a comment.

Execute "git-clang-format HEAD~1"


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

https://reviews.llvm.org/D144878

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/Expr.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Preprocessor/feature_tests.c
  clang/test/Preprocessor/feature_tests.cpp
  clang/test/Sema/source_location.c
  clang/test/SemaCXX/Inputs/source-location-file.h
  clang/test/SemaCXX/source_location.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -259,6 +259,10 @@
  Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
  sourceLocExpr(hasBuiltinStr("__builtin_FILE");
+  testImport("void declToImport() { (void)__builtin_FILE_NAME(); }", Lang_CXX03,
+ "", Lang_CXX03, Verifier,
+ functionDecl(hasDescendant(
+ sourceLocExpr(hasBuiltinStr("__builtin_FILE_NAME");
   testImport("void declToImport() { (void)__builtin_COLUMN(); }", Lang_CXX03,
  "", Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
@@ -1546,7 +1550,7 @@
   R"s(
   struct declToImport {
 int a = d;
-union { 
+union {
   int b;
   int c;
 };
@@ -3804,7 +3808,7 @@
 int a[2] = {1,2};
 auto [x1,y1] = a;
 auto& [x2,y2] = a;
-
+
 struct S {
   mutable int x1 : 2;
   volatile double y1;
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -84,6 +84,7 @@
 static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
+static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
 
@@ -91,6 +92,7 @@
 static_assert(noexcept(__builtin_LINE()));
 static_assert(noexcept(__builtin_COLUMN()));
 static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FILE_NAME()));
 static_assert(noexcept(__builtin_FUNCTION()));
 static_assert(noexcept(__builtin_source_location()));
 
@@ -346,6 +348,54 @@
 
 } // namespace test_file
 
+//===--===//
+//__builtin_FILE_NAME()
+//===--===//
+
+namespace test_file_name {
+constexpr const char *test_file_name_simple(
+  const char *__f = __builtin_FILE_NAME()) {
+  return __f;
+}
+void test_function() {
+#line 900
+  static_assert(is_equal(test_file_name_simple(), __FILE_NAME__));
+  static_assert(is_equal(SLF::test_function_filename(), __FILE_NAME__), "");
+  static_assert(is_equal(SLF::test_function_filename_template(42),
+ __FILE_NAME__), "");
+
+  static_assert(is_equal(SLF::test_function_filename_indirect(),
+ SLF::global_info_filename), "");
+  static_assert(is_equal(SLF::test_function_filename_template_indirect(42),
+ SLF::global_info_filename), "");
+
+  static_assert(test_file_name_simple() != nullptr);
+  static_assert(is_equal(test_file_name_simple(), "source_location.cpp"));
+}
+
+void test_class() {
+#line 315
+  using SLF::TestClass;
+  constexpr TestClass Default;
+  constexpr TestClass InParam{42};
+  constexpr TestClass Template{42, 42};
+  constexpr auto *F = Default.info_file_name;
+  constexpr auto Char = F[0];
+  static_assert(is_equal(Default.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.ctor_info_file_name, __FILE_NAME__), "");
+}
+
+void test_aggr_class() {
+  using Agg = SLF::AggrClass<>;
+  constexpr Agg Default{};
+  constexpr Agg InitOne{42};
+  static_assert(is_equal(Default.init_info_file_name, __FILE_NAME__), "");
+  static_assert(is_equal(InitOne.init_info_file_name, __FILE_NAME__), "");
+}
+
+} // namespace test_file_name
+
 //===--===//
 //__builtin_FUNCTION()
 //===--===//
@@ -487,6 +537,7 @@
 #line 44 "test_file.c"
 static_assert(is_equal("test_file.c", __FILE__));
 static_assert(is_equal("test_file.c", __builtin_FILE()));
+static_assert(is_equal("test_file.c", __builtin_FILE_NAME()));
 static_assert(is_equal("test_file.c", SL::current().file()));
 static_assert(is_equal("test_file.c", SLF::test_function().file()));
 static_assert(is_equal(SLF::FILE, SLF::test_function_indirect().file()));
Index: clang/test/SemaCXX

[PATCH] D142373: [Utils] Add --full-function-signature to update_cc_test_checks.py to match return type as well as args

2023-03-01 Thread Alex Bradbury via Phabricator via cfe-commits
asb abandoned this revision.
asb added a comment.

Abandoned in favour of https://reviews.llvm.org/D144963 which rebases this 
logic on top of the new `--version` support.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142373

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


[clang] f8d10d5 - [clang-format][NFC] Refactor formatting unit tests.

2023-03-01 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2023-03-01T12:36:07Z
New Revision: f8d10d5ac9ab4b45b388c74357fc82fb96562e66

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

LOG: [clang-format][NFC] Refactor formatting unit tests.

Pull out common base class for formatting unit tests, removing duplicate
code that accumulated over the years.

Pull out macro expansion test into its own test file.

Added: 
clang/unittests/Format/FormatReplacementTest.cpp
clang/unittests/Format/FormatTestBase.h
clang/unittests/Format/FormatTestMacroExpansion.cpp

Modified: 
clang/unittests/Format/BracesInserterTest.cpp
clang/unittests/Format/BracesRemoverTest.cpp
clang/unittests/Format/CMakeLists.txt
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/FormatTestComments.cpp
clang/unittests/Format/FormatTestObjC.cpp
clang/unittests/Format/FormatTestTextProto.cpp
clang/unittests/Format/FormatTestUtils.h
clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
clang/unittests/Format/QualifierFixerTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/BracesInserterTest.cpp 
b/clang/unittests/Format/BracesInserterTest.cpp
index c685907451835..e0c447d671f45 100644
--- a/clang/unittests/Format/BracesInserterTest.cpp
+++ b/clang/unittests/Format/BracesInserterTest.cpp
@@ -6,64 +6,16 @@
 //
 
//===--===//
 
-#include "clang/Format/Format.h"
-
-#include "../Tooling/ReplacementTest.h"
-#include "FormatTestUtils.h"
+#include "FormatTestBase.h"
 
 #define DEBUG_TYPE "braces-inserter-test"
 
 namespace clang {
 namespace format {
+namespace test {
 namespace {
 
-class BracesInserterTest : public ::testing::Test {
-protected:
-  std::string format(llvm::StringRef Code, const FormatStyle &Style,
- const std::vector &Ranges) {
-LLVM_DEBUG(llvm::errs() << "---\n");
-LLVM_DEBUG(llvm::errs() << Code << "\n\n");
-auto NonEmptyRanges = Ranges;
-if (Ranges.empty())
-  NonEmptyRanges = {1, tooling::Range(0, Code.size())};
-FormattingAttemptStatus Status;
-tooling::Replacements Replaces =
-reformat(Style, Code, NonEmptyRanges, "", &Status);
-EXPECT_EQ(true, Status.FormatComplete) << Code << "\n\n";
-ReplacementCount = Replaces.size();
-auto Result = applyAllReplacements(Code, Replaces);
-EXPECT_TRUE(static_cast(Result));
-LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
-return *Result;
-  }
-
-  void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
- llvm::StringRef Code,
- const FormatStyle &Style = getLLVMStyle(),
- const std::vector &Ranges = {}) {
-testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
-EXPECT_EQ(Expected.str(), format(Expected, Style, Ranges))
-<< "Expected code is not stable";
-EXPECT_EQ(Expected.str(), format(Code, Style, Ranges));
-if (Style.Language == FormatStyle::LK_Cpp && Ranges.empty()) {
-  // Objective-C++ is a superset of C++, so everything checked for C++
-  // needs to be checked for Objective-C++ as well.
-  FormatStyle ObjCStyle = Style;
-  ObjCStyle.Language = FormatStyle::LK_ObjC;
-  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle, Ranges));
-}
-  }
-
-  void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
- const FormatStyle &Style = getLLVMStyle(),
- const std::vector &Ranges = {}) {
-_verifyFormat(File, Line, Code, Code, Style, Ranges);
-  }
-
-  int ReplacementCount;
-};
-
-#define verifyFormat(...) _verifyFormat(__FILE__, __LINE__, __VA_ARGS__)
+class BracesInserterTest : public FormatTestBase {};
 
 TEST_F(BracesInserterTest, InsertBraces) {
   FormatStyle Style = getLLVMStyle();
@@ -328,9 +280,10 @@ TEST_F(BracesInserterTest, InsertBracesRange) {
"  }",
Code, Style, {tooling::Range(10, 8)}); // line 2
 
-  verifyFormat(Code, Style, {tooling::Range(19, 11)}); // line 3
+  verifyFormat(Code, Code, Style, {tooling::Range(19, 11)}); // line 3
 }
 
 } // namespace
+} // namespace test
 } // namespace format
 } // namespace clang

diff  --git a/clang/unittests/Format/BracesRemoverTest.cpp 
b/clang/unittests/Format/BracesRemoverTest.cpp
index ba0b3eb53d155..5155eefb9e08c 100644
--- a/clang/unittests/Format/BracesRemoverTest.cpp
+++ b/clang/unittests/Format/BracesRemoverTest.cpp
@@ -6,66 +6,16 @@
 //
 
//===--===//
 
-#include "clang/Format/Format.h"
-
-#include "../Tooling/ReplacementTest.h"
-#include "FormatTestUtils.h"
+#include "FormatTestBase.h"
 
 #define DEBUG_TYPE "braces-re

[PATCH] D145057: [clang][ASTImport] Add support for import of empty records

2023-03-01 Thread Pavel Kosov via Phabricator via cfe-commits
kpdev42 created this revision.
kpdev42 added reviewers: clayborg, balazske.
kpdev42 added a project: LLVM.
Herald added a subscriber: martong.
Herald added a reviewer: shafik.
Herald added a project: All.
kpdev42 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Patch represents the clang part of changes in D143347 



Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145057

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/include/clang/AST/DeclCXX.h
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8137,6 +8137,29 @@
   EXPECT_FALSE(SharedStatePtr->isNewDecl(ToBar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportDefinitionOfEmptyClassWithNoUniqueAddressField) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  struct B {};
+  struct A { B b; };
+  )",
+  Lang_CXX20);
+
+  CXXRecordDecl *FromD = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+
+  for (auto *FD : FromD->fields())
+FD->addAttr(clang::NoUniqueAddressAttr::Create(FromD->getASTContext(),
+   clang::SourceRange()));
+  FromD->markEmpty();
+
+  CXXRecordDecl *ToD = cast(Import(FromD, Lang_CXX20));
+  EXPECT_EQ(true, ToD->isEmpty());
+  for (auto *FD : ToD->fields())
+EXPECT_EQ(true, FD->hasAttr());
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3892,6 +3892,9 @@
   D->getInClassInitStyle()))
 return ToField;
 
+  Err = Importer.ImportAttrs(ToField, D);
+  if (Err)
+return std::move(Err);
   ToField->setAccess(D->getAccess());
   ToField->setLexicalDeclContext(LexicalDC);
   if (ToInitializer)
@@ -8978,6 +8981,18 @@
   return FromDPos->second->getTranslationUnitDecl();
 }
 
+Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) {
+  if (FromD->hasAttrs())
+for (const Attr *FromAttr : FromD->getAttrs()) {
+  auto ToAttrOrErr = Import(FromAttr);
+  if (ToAttrOrErr)
+ToD->addAttr(*ToAttrOrErr);
+  else
+return ToAttrOrErr.takeError();
+}
+  return Error::success();
+}
+
 Expected ASTImporter::Import(Decl *FromD) {
   if (!FromD)
 return nullptr;
@@ -9112,15 +9127,8 @@
 
   // Make sure that ImportImpl registered the imported decl.
   assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
-
-  if (FromD->hasAttrs())
-for (const Attr *FromAttr : FromD->getAttrs()) {
-  auto ToAttrOrErr = Import(FromAttr);
-  if (ToAttrOrErr)
-ToD->addAttr(*ToAttrOrErr);
-  else
-return ToAttrOrErr.takeError();
-}
+  if (auto Error = ImportAttrs(ToD, FromD))
+return std::move(Error);
 
   // Notify subclasses.
   Imported(FromD, ToD);
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -1165,6 +1165,10 @@
   ///
   /// \note This does NOT include a check for union-ness.
   bool isEmpty() const { return data().Empty; }
+  /// Marks this record as empty. This is used by DWARFASTParserClang
+  /// when parsing records with empty fields having [[no_unique_address]]
+  /// attribute
+  void markEmpty() { data().Empty = true; }
 
   void setInitMethod(bool Val) { data().HasInitMethod = Val; }
   bool hasInitMethod() const { return data().HasInitMethod; }
Index: clang/include/clang/AST/ASTImporter.h
===
--- clang/include/clang/AST/ASTImporter.h
+++ clang/include/clang/AST/ASTImporter.h
@@ -258,6 +258,7 @@
 FoundDeclsTy findDeclsInToCtx(DeclContext *DC, DeclarationName Name);
 
 void AddToLookupTable(Decl *ToD);
+llvm::Error ImportAttrs(Decl *ToD, Decl *FromD);
 
   protected:
 /// Can be overwritten by subclasses to implement their own import logic.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145059: [clangd] Add support from showing used symbols on cross ref request

2023-03-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145059

Files:
  clang-tools-extra/clangd/XRefs.cpp

Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -16,6 +16,8 @@
 #include "Selection.h"
 #include "SourceCode.h"
 #include "URI.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "index/Index.h"
 #include "index/Merge.h"
 #include "index/Relation.h"
@@ -1310,6 +1312,28 @@
 return printQualifiedName(*ND);
   return {};
 }
+
+// FIXME(bakalova): Remove after merging https://reviews.llvm.org/D143496
+std::vector
+collectMacroReferences(ParsedAST &AST) {
+  const auto &SM = AST.getSourceManager();
+  //  FIXME: !!this is a hacky way to collect macro references.
+  std::vector Macros;
+  auto &PP = AST.getPreprocessor();
+  for (const syntax::Token &Tok :
+   AST.getTokens().spelledTokens(SM.getMainFileID())) {
+auto Macro = locateMacroAt(Tok, PP);
+if (!Macro)
+  continue;
+if (auto DefLoc = Macro->Info->getDefinitionLoc(); DefLoc.isValid())
+  Macros.push_back(
+  {Tok.location(),
+   include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok.text(SM)),
+  DefLoc},
+   include_cleaner::RefType::Explicit});
+  }
+  return Macros;
+}
 } // namespace
 
 ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
@@ -1324,6 +1348,74 @@
 return {};
   }
 
+  // TODO(bakalova) Look closer at the proper directive kind handling.
+  std::vector Includes = AST.getIncludeStructure().MainFileIncludes;
+  for (auto &Inc : Includes) {
+if (Inc.Directive != tok::PPKeywordKind::pp_include) {
+  // Ignore non-C++ include directives.
+  continue;
+}
+// It is enough to compare line numbers, since one include per line is a
+// standard.
+if (Pos.line != Inc.HashLine) {
+  continue;
+}
+
+const auto Macros = collectMacroReferences(AST);
+include_cleaner::walkUsed(
+AST.getLocalTopLevelDecls(), Macros,
+AST.getPragmaIncludes(), SM,
+[&](const include_cleaner::SymbolReference &Ref,
+llvm::ArrayRef Providers) {
+  if (!Ref.RefLocation.isFileID() ||
+  Ref.RT != include_cleaner::RefType::Explicit ||
+  !SM.isWrittenInMainFile(SM.getSpellingLoc(Ref.RefLocation))) {
+return;
+  }
+  const syntax::Token *Tok =
+  AST.getTokens().spelledTokenAt(Ref.RefLocation);
+  if (Tok == nullptr) {
+elog("Can't find spelled token at the symbol reference location.");
+return;
+  }
+  const SourceLocation &RefEndLocation = Tok->endLocation();
+  clangd::Range Range =
+  clangd::Range{sourceLocToPosition(SM, Ref.RefLocation),
+sourceLocToPosition(SM, RefEndLocation)};
+  ReferencesResult::Reference Result;
+  Result.Loc.range = Range;
+  Result.Loc.uri = URIMainFile;
+
+  // TODO(bakalova) does this differentiation make any sense in this
+  // context? Possibly not if (Ref.IsDefinition) {
+  //   Result.Attributes |= ReferencesResult::Declaration;
+  //   Result.Attributes |= ReferencesResult::Definition;
+  // }
+  for (const include_cleaner::Header &H : Providers) {
+switch (H.kind()) {
+case include_cleaner::Header::Physical:
+  if (H.physical()->tryGetRealPathName() == Inc.Resolved) {
+Results.References.push_back(std::move(Result));
+  }
+  break;
+case include_cleaner::Header::Standard:
+  if (Inc.Written == H.standard().name()) {
+Results.References.push_back(std::move(Result));
+  }
+  break;
+case include_cleaner::Header::Verbatim:
+  if (Inc.Written == H.verbatim()) {
+Results.References.push_back(std::move(Result));
+  }
+  break;
+}
+  }
+});
+if (!Results.References.empty()) {
+  return Results;
+}
+  }
+
   llvm::DenseSet IDsToQuery, OverriddenMethods;
 
   const auto *IdentifierAtCursor =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144709: [clang-format] Improve QualifierAlignment

2023-03-01 Thread Alexander Hederstaf via Phabricator via cfe-commits
AlexanderHederstaf updated this revision to Diff 501476.
AlexanderHederstaf added a comment.

Change order for typename and :: as
const typename ::Bar b; is valid code.

Add code for handling ::template.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

Files:
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/QualifierAlignmentFixer.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/QualifierFixerTest.cpp

Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -241,7 +241,7 @@
   verifyFormat("int const *b;", Style);
   verifyFormat("int const &b;", Style);
   verifyFormat("int const &&b;", Style);
-  verifyFormat("int const *b const;", Style);
+  verifyFormat("int const *const b;", Style);
   verifyFormat("int *const c;", Style);
 
   verifyFormat("const Foo a;", Style);
@@ -252,7 +252,7 @@
   verifyFormat("Foo const *b;", Style);
   verifyFormat("Foo const &b;", Style);
   verifyFormat("Foo const &&b;", Style);
-  verifyFormat("Foo const *b const;", Style);
+  verifyFormat("Foo const *const b;", Style);
 
   verifyFormat("LLVM_NODISCARD const int &Foo();", Style);
   verifyFormat("LLVM_NODISCARD int const &Foo();", Style);
@@ -275,7 +275,7 @@
   verifyFormat("int const *b;", Style);
   verifyFormat("int const &b;", Style);
   verifyFormat("int const &&b;", Style);
-  verifyFormat("int const *b const;", Style);
+  verifyFormat("int const *const b;", Style);
   verifyFormat("int *const c;", Style);
 
   verifyFormat("Foo const a;", Style);
@@ -286,7 +286,7 @@
   verifyFormat("Foo const *b;", Style);
   verifyFormat("Foo const &b;", Style);
   verifyFormat("Foo const &&b;", Style);
-  verifyFormat("Foo const *b const;", Style);
+  verifyFormat("Foo const *const b;", Style);
   verifyFormat("Foo *const b;", Style);
   verifyFormat("Foo const *const b;", Style);
   verifyFormat("auto const v = get_value();", Style);
@@ -303,6 +303,11 @@
   verifyFormat("void foo() const final;", Style);
   verifyFormat("void foo() const final LLVM_READONLY;", Style);
   verifyFormat("void foo() const LLVM_READONLY;", Style);
+  verifyFormat("void foo() const volatile override;", Style);
+  verifyFormat("void foo() const volatile override LLVM_READONLY;", Style);
+  verifyFormat("void foo() const volatile final;", Style);
+  verifyFormat("void foo() const volatile final LLVM_READONLY;", Style);
+  verifyFormat("void foo() const volatile LLVM_READONLY;", Style);
 
   verifyFormat(
   "template  explicit Action(Action const &action);",
@@ -343,6 +348,7 @@
   verifyFormat("int const volatile;", "volatile const int;", Style);
   verifyFormat("int const volatile;", "const volatile int;", Style);
   verifyFormat("int const volatile;", "const int volatile;", Style);
+
   verifyFormat("int const volatile *restrict;", "volatile const int *restrict;",
Style);
   verifyFormat("int const volatile *restrict;", "const volatile int *restrict;",
@@ -350,9 +356,44 @@
   verifyFormat("int const volatile *restrict;", "const int volatile *restrict;",
Style);
 
+  verifyFormat("long long int const volatile;", "const long long int volatile;",
+   Style);
+  verifyFormat("long long int const volatile;", "long const long int volatile;",
+   Style);
+  verifyFormat("long long int const volatile;", "long long volatile int const;",
+   Style);
+  verifyFormat("long long int const volatile;", "long volatile long const int;",
+   Style);
+  verifyFormat("long long int const volatile;", "const long long volatile int;",
+   Style);
+
   verifyFormat("static int const bat;", "static const int bat;", Style);
   verifyFormat("static int const bat;", "static int const bat;", Style);
 
+  // static is not configured, unchanged on the left of the right hand
+  // qualifiers.
+  verifyFormat("int static const volatile;", "volatile const int static;",
+   Style);
+  verifyFormat("int static const volatile;", "const volatile int static;",
+   Style);
+  verifyFormat("int static const volatile;", "const int volatile static;",
+   Style);
+  verifyFormat("Foo static const volatile;", "volatile const Foo static;",
+   Style);
+  verifyFormat("Foo static const volatile;", "const volatile Foo static;",
+   Style);
+  verifyFormat("Foo static const volatile;", "const Foo volatile static;",
+   Style);
+
+  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);
+
+ 

[clang] 81979c3 - [clang][RISCV][test] Add further test coverage for _Float16 on RISC-V

2023-03-01 Thread Alex Bradbury via cfe-commits

Author: Alex Bradbury
Date: 2023-03-01T13:32:49Z
New Revision: 81979c3038defe8653b62ba05517ee6d6b3eb976

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

LOG: [clang][RISCV][test] Add further test coverage for _Float16 on RISC-V

Check for size and alignment as we do for other types.

Added: 


Modified: 
clang/test/Driver/riscv32-toolchain.c
clang/test/Driver/riscv64-toolchain.c

Removed: 




diff  --git a/clang/test/Driver/riscv32-toolchain.c 
b/clang/test/Driver/riscv32-toolchain.c
index 15f6d232d613..bc46e5ffde5d 100644
--- a/clang/test/Driver/riscv32-toolchain.c
+++ b/clang/test/Driver/riscv32-toolchain.c
@@ -248,6 +248,9 @@ int align_ll = __alignof(long long);
 // CHECK: @align_p = dso_local global i32 4
 int align_p = __alignof(void*);
 
+// CHECK: @align_f16 = dso_local global i32 2
+int align_f16 = __alignof(_Float16);
+
 // CHECK: @align_f = dso_local global i32 4
 int align_f = __alignof(float);
 
@@ -284,6 +287,9 @@ int align_a_ll = __alignof(_Atomic(long long));
 // CHECK: @align_a_p = dso_local global i32 4
 int align_a_p = __alignof(_Atomic(void*));
 
+// CHECK: @align_a_f16 = dso_local global i32 2
+int align_a_f16 = __alignof(_Atomic(_Float16));
+
 // CHECK: @align_a_f = dso_local global i32 4
 int align_a_f = __alignof(_Atomic(float));
 
@@ -332,6 +338,9 @@ int size_a_ll = sizeof(_Atomic(long long));
 // CHECK: @size_a_p = dso_local global i32 4
 int size_a_p = sizeof(_Atomic(void*));
 
+// CHECK: @size_a_f16 = dso_local global i32 2
+int size_a_f16 = sizeof(_Atomic(_Float16));
+
 // CHECK: @size_a_f = dso_local global i32 4
 int size_a_f = sizeof(_Atomic(float));
 
@@ -380,6 +389,9 @@ unsigned long long check_ulonglong(void) { return 0; }
 // CHECK: define dso_local i32 @check_size_t()
 size_t check_size_t(void) { return 0; }
 
+// CHECK: define dso_local half @check_float16()
+_Float16 check_float16(void) { return 0; }
+
 // CHECK: define dso_local float @check_float()
 float check_float(void) { return 0; }
 

diff  --git a/clang/test/Driver/riscv64-toolchain.c 
b/clang/test/Driver/riscv64-toolchain.c
index 28e8142bb76f..613d3343b12d 100644
--- a/clang/test/Driver/riscv64-toolchain.c
+++ b/clang/test/Driver/riscv64-toolchain.c
@@ -204,6 +204,9 @@ int align_ll = __alignof(long long);
 // CHECK: @align_p = dso_local global i32 8
 int align_p = __alignof(void*);
 
+// CHECK: @align_f16 = dso_local global i32 2
+int align_f16 = __alignof(_Float16);
+
 // CHECK: @align_f = dso_local global i32 4
 int align_f = __alignof(float);
 
@@ -240,6 +243,9 @@ int align_a_ll = __alignof(_Atomic(long long));
 // CHECK: @align_a_p = dso_local global i32 8
 int align_a_p = __alignof(_Atomic(void*));
 
+// CHECK: @align_a_f16 = dso_local global i32 2
+int align_a_f16 = __alignof(_Atomic(_Float16));
+
 // CHECK: @align_a_f = dso_local global i32 4
 int align_a_f = __alignof(_Atomic(float));
 
@@ -288,6 +294,9 @@ int size_a_ll = sizeof(_Atomic(long long));
 // CHECK: @size_a_p = dso_local global i32 8
 int size_a_p = sizeof(_Atomic(void*));
 
+// CHECK: @size_a_f16 = dso_local global i32 2
+int size_a_f16 = sizeof(_Atomic(_Float16));
+
 // CHECK: @size_a_f = dso_local global i32 4
 int size_a_f = sizeof(_Atomic(float));
 
@@ -336,6 +345,9 @@ unsigned long long check_ulonglong(void) { return 0; }
 // CHECK: define dso_local i64 @check_size_t()
 size_t check_size_t(void) { return 0; }
 
+// CHECK: define dso_local half @check_float16()
+_Float16 check_float16(void) { return 0; }
+
 // CHECK: define dso_local float @check_float()
 float check_float(void) { return 0; }
 



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


[PATCH] D144878: __builtin_FILE_NAME()

2023-03-01 Thread Ilya Karapsin via Phabricator via cfe-commits
karapsinie updated this revision to Diff 501484.
karapsinie added a comment.

Duplicate code moved to "Preprocessor::processPathToFilename"


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

https://reviews.llvm.org/D144878

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/AST/Expr.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Preprocessor/feature_tests.c
  clang/test/Preprocessor/feature_tests.cpp
  clang/test/Sema/source_location.c
  clang/test/SemaCXX/Inputs/source-location-file.h
  clang/test/SemaCXX/source_location.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -259,6 +259,10 @@
  Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
  sourceLocExpr(hasBuiltinStr("__builtin_FILE");
+  testImport("void declToImport() { (void)__builtin_FILE_NAME(); }", Lang_CXX03,
+ "", Lang_CXX03, Verifier,
+ functionDecl(hasDescendant(
+ sourceLocExpr(hasBuiltinStr("__builtin_FILE_NAME");
   testImport("void declToImport() { (void)__builtin_COLUMN(); }", Lang_CXX03,
  "", Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
@@ -1546,7 +1550,7 @@
   R"s(
   struct declToImport {
 int a = d;
-union { 
+union {
   int b;
   int c;
 };
@@ -3804,7 +3808,7 @@
 int a[2] = {1,2};
 auto [x1,y1] = a;
 auto& [x2,y2] = a;
-
+
 struct S {
   mutable int x1 : 2;
   volatile double y1;
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -84,6 +84,7 @@
 static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
+static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
 
@@ -91,6 +92,7 @@
 static_assert(noexcept(__builtin_LINE()));
 static_assert(noexcept(__builtin_COLUMN()));
 static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FILE_NAME()));
 static_assert(noexcept(__builtin_FUNCTION()));
 static_assert(noexcept(__builtin_source_location()));
 
@@ -346,6 +348,54 @@
 
 } // namespace test_file
 
+//===--===//
+//__builtin_FILE_NAME()
+//===--===//
+
+namespace test_file_name {
+constexpr const char *test_file_name_simple(
+  const char *__f = __builtin_FILE_NAME()) {
+  return __f;
+}
+void test_function() {
+#line 900
+  static_assert(is_equal(test_file_name_simple(), __FILE_NAME__));
+  static_assert(is_equal(SLF::test_function_filename(), __FILE_NAME__), "");
+  static_assert(is_equal(SLF::test_function_filename_template(42),
+ __FILE_NAME__), "");
+
+  static_assert(is_equal(SLF::test_function_filename_indirect(),
+ SLF::global_info_filename), "");
+  static_assert(is_equal(SLF::test_function_filename_template_indirect(42),
+ SLF::global_info_filename), "");
+
+  static_assert(test_file_name_simple() != nullptr);
+  static_assert(is_equal(test_file_name_simple(), "source_location.cpp"));
+}
+
+void test_class() {
+#line 315
+  using SLF::TestClass;
+  constexpr TestClass Default;
+  constexpr TestClass InParam{42};
+  constexpr TestClass Template{42, 42};
+  constexpr auto *F = Default.info_file_name;
+  constexpr auto Char = F[0];
+  static_assert(is_equal(Default.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.ctor_info_file_name, __FILE_NAME__), "");
+}
+
+void test_aggr_class() {
+  using Agg = SLF::AggrClass<>;
+  constexpr Agg Default{};
+  constexpr Agg InitOne{42};
+  static_assert(is_equal(Default.init_info_file_name, __FILE_NAME__), "");
+  static_assert(is_equal(InitOne.init_info_file_name, __FILE_NAME__), "");
+}
+
+} // namespace test_file_name
+
 //===--===//
 //__builtin_FUNCTION()
 //===--===//
@@ -487,6 +537,7 @@
 #line 44 "test_file.c"
 static_assert(is_equal("test_file.c", __FILE__));
 static_assert(is_equal("test_file.c", __builtin_FILE()));
+static_assert(is_equal("test_file.c", __builtin_FILE_NAME()));
 static_assert(is_equal("test_file.c", SL::current().file()));
 static_assert(is_equal("test_file.c", SLF::test_function().file

[PATCH] D144878: __builtin_FILE_NAME()

2023-03-01 Thread Ilya Karapsin via Phabricator via cfe-commits
karapsinie updated this revision to Diff 501486.
karapsinie added a comment.

Execute "git-clang-format HEAD~1"


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

https://reviews.llvm.org/D144878

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/AST/Expr.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Preprocessor/feature_tests.c
  clang/test/Preprocessor/feature_tests.cpp
  clang/test/Sema/source_location.c
  clang/test/SemaCXX/Inputs/source-location-file.h
  clang/test/SemaCXX/source_location.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -259,6 +259,10 @@
  Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
  sourceLocExpr(hasBuiltinStr("__builtin_FILE");
+  testImport("void declToImport() { (void)__builtin_FILE_NAME(); }", Lang_CXX03,
+ "", Lang_CXX03, Verifier,
+ functionDecl(hasDescendant(
+ sourceLocExpr(hasBuiltinStr("__builtin_FILE_NAME");
   testImport("void declToImport() { (void)__builtin_COLUMN(); }", Lang_CXX03,
  "", Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
@@ -1546,7 +1550,7 @@
   R"s(
   struct declToImport {
 int a = d;
-union { 
+union {
   int b;
   int c;
 };
@@ -3804,7 +3808,7 @@
 int a[2] = {1,2};
 auto [x1,y1] = a;
 auto& [x2,y2] = a;
-
+
 struct S {
   mutable int x1 : 2;
   volatile double y1;
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -84,6 +84,7 @@
 static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
+static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
 
@@ -91,6 +92,7 @@
 static_assert(noexcept(__builtin_LINE()));
 static_assert(noexcept(__builtin_COLUMN()));
 static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FILE_NAME()));
 static_assert(noexcept(__builtin_FUNCTION()));
 static_assert(noexcept(__builtin_source_location()));
 
@@ -346,6 +348,54 @@
 
 } // namespace test_file
 
+//===--===//
+//__builtin_FILE_NAME()
+//===--===//
+
+namespace test_file_name {
+constexpr const char *test_file_name_simple(
+  const char *__f = __builtin_FILE_NAME()) {
+  return __f;
+}
+void test_function() {
+#line 900
+  static_assert(is_equal(test_file_name_simple(), __FILE_NAME__));
+  static_assert(is_equal(SLF::test_function_filename(), __FILE_NAME__), "");
+  static_assert(is_equal(SLF::test_function_filename_template(42),
+ __FILE_NAME__), "");
+
+  static_assert(is_equal(SLF::test_function_filename_indirect(),
+ SLF::global_info_filename), "");
+  static_assert(is_equal(SLF::test_function_filename_template_indirect(42),
+ SLF::global_info_filename), "");
+
+  static_assert(test_file_name_simple() != nullptr);
+  static_assert(is_equal(test_file_name_simple(), "source_location.cpp"));
+}
+
+void test_class() {
+#line 315
+  using SLF::TestClass;
+  constexpr TestClass Default;
+  constexpr TestClass InParam{42};
+  constexpr TestClass Template{42, 42};
+  constexpr auto *F = Default.info_file_name;
+  constexpr auto Char = F[0];
+  static_assert(is_equal(Default.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.ctor_info_file_name, __FILE_NAME__), "");
+}
+
+void test_aggr_class() {
+  using Agg = SLF::AggrClass<>;
+  constexpr Agg Default{};
+  constexpr Agg InitOne{42};
+  static_assert(is_equal(Default.init_info_file_name, __FILE_NAME__), "");
+  static_assert(is_equal(InitOne.init_info_file_name, __FILE_NAME__), "");
+}
+
+} // namespace test_file_name
+
 //===--===//
 //__builtin_FUNCTION()
 //===--===//
@@ -487,6 +537,7 @@
 #line 44 "test_file.c"
 static_assert(is_equal("test_file.c", __FILE__));
 static_assert(is_equal("test_file.c", __builtin_FILE()));
+static_assert(is_equal("test_file.c", __builtin_FILE_NAME()));
 static_assert(is_equal("test_file.c", SL::current().file()));
 static_assert(is_equal("test_file.c", SLF::test_function().file()));
 static_assert(is_equa

[PATCH] D143415: LibclangTest: remove libclang-test-* tmp dir reliably

2023-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D143415#4160550 , @vedgy wrote:

> Can someone merge/land this review? I don't have commit access.

I'm happy to do that for you -- what name and email address would you like me 
to use for patch attribution?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143415

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


[PATCH] D136751: [clang][Interp] This pointers are writable in constructors

2023-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


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

https://reviews.llvm.org/D136751

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


[PATCH] D142617: [clang][Interp] Check This pointer without creating InterpFrame

2023-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/InterpStack.h:70-72
+  template  T &peek(size_t Offset) const {
+return *reinterpret_cast(peek(Offset));
+  }

Ooofda, this only differs from `peek()` on line 97 because this function has a 
templated return type, but otherwise the signatures only differ based on return 
type. This doesn't feel like the most clean overload set...

Also, should this be worrying about alignment of `T` compared to the offset we 
find it at? (Should there be an assert that the offset is sensible for a `T`?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142617

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


[PATCH] D143415: LibclangTest: remove libclang-test-* tmp dir reliably

2023-03-01 Thread Igor Kushnir via Phabricator via cfe-commits
vedgy added a comment.

In D143415#4161460 , @aaron.ballman 
wrote:

> In D143415#4160550 , @vedgy wrote:
>
>> Can someone merge/land this review? I don't have commit access.
>
> I'm happy to do that for you -- what name and email address would you like me 
> to use for patch attribution?

user.email=igor...@gmail.com
user.name=Igor Kushnir

A pity that Phabricator doesn't pick up git user name and email.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143415

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


[clang] 8d09bd6 - [clang][Interp] This pointers are writable in de-/constructors

2023-03-01 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-03-01T15:41:10+01:00
New Revision: 8d09bd616be8e347d2769d7b17cd8e717c855c45

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

LOG: [clang][Interp] This pointers are writable in de-/constructors

This is possible in C++20, so we need to check this when doing stores.

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

Added: 


Modified: 
clang/lib/AST/Interp/Function.h
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Pointer.h
clang/test/AST/Interp/cxx20.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Function.h b/clang/lib/AST/Interp/Function.h
index 1eb4fa90d794..422211708a77 100644
--- a/clang/lib/AST/Interp/Function.h
+++ b/clang/lib/AST/Interp/Function.h
@@ -134,6 +134,8 @@ class Function final {
 
   /// Checks if the function is a constructor.
   bool isConstructor() const { return isa(F); }
+  /// Checks if the function is a destructor.
+  bool isDestructor() const { return isa(F); }
 
   /// Checks if the function is fully done compiling.
   bool isFullyCompiled() const { return IsFullyCompiled; }

diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 319aba0ffa94..329cc0ff949d 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -213,7 +213,14 @@ bool CheckRange(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr,
 
 bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
   assert(Ptr.isLive() && "Pointer is not live");
-  if (!Ptr.isConst()) {
+  if (!Ptr.isConst())
+return true;
+
+  // The This pointer is writable in constructors and destructors,
+  // even if isConst() returns true.
+  if (const Function *Func = S.Current->getFunction();
+  Func && (Func->isConstructor() || Func->isDestructor()) &&
+  Ptr.block() == S.Current->getThis().block()) {
 return true;
   }
 

diff  --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index 489884a25659..5895c61295e0 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -290,6 +290,8 @@ class Pointer {
   /// Returns the number of elements.
   unsigned getNumElems() const { return getSize() / elemSize(); }
 
+  Block *block() const { return Pointee; }
+
   /// Returns the index into an array.
   int64_t getIndex() const {
 if (isElementPastEnd())

diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index e9505b3cf718..44c97dd1afcd 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -201,3 +201,74 @@ constexpr Derived D; // expected-error {{must be 
initialized by a constant expre
// ref-note {{subobject of type 'bool' is not initialized}}
 #endif
 };
+
+namespace ConstThis {
+  class Foo {
+const int T = 12; // expected-note {{declared const here}} \
+  // ref-note {{declared const here}}
+int a;
+  public:
+constexpr Foo() {
+  this->a = 10;
+  T = 13; // expected-error {{cannot assign to non-static data member 'T' 
with const-qualified type}} \
+  // ref-error {{cannot assign to non-static data member 'T' with 
const-qualified type}}
+}
+  };
+  constexpr Foo F; // expected-error {{must be initialized by a constant 
expression}} \
+   // ref-error {{must be initialized by a constant 
expression}}
+
+
+  class FooDtor {
+int a;
+  public:
+constexpr FooDtor() {
+  this->a = 10;
+}
+constexpr ~FooDtor() {
+  this->a = 12;
+}
+  };
+
+  constexpr int foo() {
+const FooDtor f;
+return 0;
+  }
+  static_assert(foo() == 0);
+
+  template 
+  struct ctor_test {
+int a = 0;
+
+constexpr ctor_test() {
+  if (Good)
+a = 10;
+  int local = 100 / a; // expected-note {{division by zero}} \
+   // ref-note {{division by zero}}
+}
+  };
+
+  template 
+  struct dtor_test {
+int a = 0;
+
+constexpr dtor_test() = default;
+constexpr ~dtor_test() {
+  if (Good)
+a = 10;
+  int local = 100 / a; // expected-note {{division by zero}} \
+   // ref-note {{division by zero}}
+}
+  };
+
+  constexpr ctor_test good_ctor;
+  constexpr dtor_test good_dtor;
+
+  constexpr ctor_test bad_ctor; // expected-error {{must be initialized 
by a constant expression}} \
+   // expected-note {{in call to}} \
+   // ref-error {{must be initialized by a 
constant expression}} \
+   // ref-note {{in call to}}
+  constexpr dtor_test bad_dtor; // expected-error {{must have constant 
destruction}} \
+   // expected-note {{in call to}

[PATCH] D136751: [clang][Interp] This pointers are writable in constructors

2023-03-01 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8d09bd616be8: [clang][Interp] This pointers are writable in 
de-/constructors (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136751

Files:
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Pointer.h
  clang/test/AST/Interp/cxx20.cpp

Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -201,3 +201,74 @@
// ref-note {{subobject of type 'bool' is not initialized}}
 #endif
 };
+
+namespace ConstThis {
+  class Foo {
+const int T = 12; // expected-note {{declared const here}} \
+  // ref-note {{declared const here}}
+int a;
+  public:
+constexpr Foo() {
+  this->a = 10;
+  T = 13; // expected-error {{cannot assign to non-static data member 'T' with const-qualified type}} \
+  // ref-error {{cannot assign to non-static data member 'T' with const-qualified type}}
+}
+  };
+  constexpr Foo F; // expected-error {{must be initialized by a constant expression}} \
+   // ref-error {{must be initialized by a constant expression}}
+
+
+  class FooDtor {
+int a;
+  public:
+constexpr FooDtor() {
+  this->a = 10;
+}
+constexpr ~FooDtor() {
+  this->a = 12;
+}
+  };
+
+  constexpr int foo() {
+const FooDtor f;
+return 0;
+  }
+  static_assert(foo() == 0);
+
+  template 
+  struct ctor_test {
+int a = 0;
+
+constexpr ctor_test() {
+  if (Good)
+a = 10;
+  int local = 100 / a; // expected-note {{division by zero}} \
+   // ref-note {{division by zero}}
+}
+  };
+
+  template 
+  struct dtor_test {
+int a = 0;
+
+constexpr dtor_test() = default;
+constexpr ~dtor_test() {
+  if (Good)
+a = 10;
+  int local = 100 / a; // expected-note {{division by zero}} \
+   // ref-note {{division by zero}}
+}
+  };
+
+  constexpr ctor_test good_ctor;
+  constexpr dtor_test good_dtor;
+
+  constexpr ctor_test bad_ctor; // expected-error {{must be initialized by a constant expression}} \
+   // expected-note {{in call to}} \
+   // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{in call to}}
+  constexpr dtor_test bad_dtor; // expected-error {{must have constant destruction}} \
+   // expected-note {{in call to}} \
+   // ref-error {{must have constant destruction}} \
+   // ref-note {{in call to}}
+};
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -290,6 +290,8 @@
   /// Returns the number of elements.
   unsigned getNumElems() const { return getSize() / elemSize(); }
 
+  Block *block() const { return Pointee; }
+
   /// Returns the index into an array.
   int64_t getIndex() const {
 if (isElementPastEnd())
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -213,7 +213,14 @@
 
 bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
   assert(Ptr.isLive() && "Pointer is not live");
-  if (!Ptr.isConst()) {
+  if (!Ptr.isConst())
+return true;
+
+  // The This pointer is writable in constructors and destructors,
+  // even if isConst() returns true.
+  if (const Function *Func = S.Current->getFunction();
+  Func && (Func->isConstructor() || Func->isDestructor()) &&
+  Ptr.block() == S.Current->getThis().block()) {
 return true;
   }
 
Index: clang/lib/AST/Interp/Function.h
===
--- clang/lib/AST/Interp/Function.h
+++ clang/lib/AST/Interp/Function.h
@@ -134,6 +134,8 @@
 
   /// Checks if the function is a constructor.
   bool isConstructor() const { return isa(F); }
+  /// Checks if the function is a destructor.
+  bool isDestructor() const { return isa(F); }
 
   /// Checks if the function is fully done compiling.
   bool isFullyCompiled() const { return IsFullyCompiled; }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3eceab9 - LibclangTest: remove libclang-test-* tmp dir reliably

2023-03-01 Thread Aaron Ballman via cfe-commits

Author: Igor Kushnir
Date: 2023-03-01T09:45:24-05:00
New Revision: 3eceab95f314edb85ee72c047a4acd35e757d037

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

LOG: LibclangTest: remove libclang-test-* tmp dir reliably

Temporary directories created by two LibclangReparseTest tests -
ReparseWithModule and clang_parseTranslationUnit2FullArgv - remained in
the system temporary directory after running libclangTests, because not
all files and subdirectories created in TestDir were added to set
LibclangParseTest::Files.

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

Added: 


Modified: 
clang/unittests/libclang/LibclangTest.cpp
clang/unittests/libclang/TestUtils.h

Removed: 




diff  --git a/clang/unittests/libclang/LibclangTest.cpp 
b/clang/unittests/libclang/LibclangTest.cpp
index 809426a01ca7..11a729fc040d 100644
--- a/clang/unittests/libclang/LibclangTest.cpp
+++ b/clang/unittests/libclang/LibclangTest.cpp
@@ -515,6 +515,8 @@ TEST_F(LibclangReparseTest, ReparseWithModule) {
   WriteFile(HeaderName, std::string(HeaderTop) + HeaderBottom);
   WriteFile(ModName, ModFile);
 
+  // Removing recursively is necessary to delete the module cache.
+  RemoveTestDirRecursivelyDuringTeardown = true;
   std::string ModulesCache = std::string("-fmodules-cache-path=") + TestDir;
   const char *Args[] = { "-fmodules", ModulesCache.c_str(),
  "-I", TestDir.c_str() };

diff  --git a/clang/unittests/libclang/TestUtils.h 
b/clang/unittests/libclang/TestUtils.h
index 8900d79ea5ee..c69746c4408a 100644
--- a/clang/unittests/libclang/TestUtils.h
+++ b/clang/unittests/libclang/TestUtils.h
@@ -14,18 +14,21 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 
+#include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 #include 
-#include "gtest/gtest.h"
 
 class LibclangParseTest : public ::testing::Test {
-  std::set Files;
+  // std::greater<> to remove files before their parent dirs in TearDown().
+  std::set> Files;
   typedef std::unique_ptr fixed_addr_string;
   std::map UnsavedFileContents;
 public:
   std::string TestDir;
+  bool RemoveTestDirRecursivelyDuringTeardown = false;
   CXIndex Index;
   CXTranslationUnit ClangTU;
   unsigned TUFlags;
@@ -43,16 +46,26 @@ class LibclangParseTest : public ::testing::Test {
   void TearDown() override {
 clang_disposeTranslationUnit(ClangTU);
 clang_disposeIndex(Index);
+
+namespace fs = llvm::sys::fs;
 for (const std::string &Path : Files)
-  llvm::sys::fs::remove(Path);
-llvm::sys::fs::remove(TestDir);
+  EXPECT_FALSE(fs::remove(Path, /*IgnoreNonExisting=*/false));
+if (RemoveTestDirRecursivelyDuringTeardown)
+  EXPECT_FALSE(fs::remove_directories(TestDir, /*IgnoreErrors=*/false));
+else
+  EXPECT_FALSE(fs::remove(TestDir, /*IgnoreNonExisting=*/false));
   }
   void WriteFile(std::string &Filename, const std::string &Contents) {
 if (!llvm::sys::path::is_absolute(Filename)) {
   llvm::SmallString<256> Path(TestDir);
-  llvm::sys::path::append(Path, Filename);
+  namespace path = llvm::sys::path;
+  for (auto FileI = path::begin(Filename), FileEnd = path::end(Filename);
+   FileI != FileEnd; ++FileI) {
+ASSERT_NE(*FileI, ".");
+path::append(Path, *FileI);
+Files.emplace(Path.str());
+  }
   Filename = std::string(Path.str());
-  Files.insert(Filename);
 }
 llvm::sys::fs::create_directories(llvm::sys::path::parent_path(Filename));
 std::ofstream OS(Filename);



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


[PATCH] D143415: LibclangTest: remove libclang-test-* tmp dir reliably

2023-03-01 Thread Aaron Ballman 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 rG3eceab95f314: LibclangTest: remove libclang-test-* tmp dir 
reliably (authored by vedgy, committed by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143415

Files:
  clang/unittests/libclang/LibclangTest.cpp
  clang/unittests/libclang/TestUtils.h


Index: clang/unittests/libclang/TestUtils.h
===
--- clang/unittests/libclang/TestUtils.h
+++ clang/unittests/libclang/TestUtils.h
@@ -14,18 +14,21 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 
+#include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 #include 
-#include "gtest/gtest.h"
 
 class LibclangParseTest : public ::testing::Test {
-  std::set Files;
+  // std::greater<> to remove files before their parent dirs in TearDown().
+  std::set> Files;
   typedef std::unique_ptr fixed_addr_string;
   std::map UnsavedFileContents;
 public:
   std::string TestDir;
+  bool RemoveTestDirRecursivelyDuringTeardown = false;
   CXIndex Index;
   CXTranslationUnit ClangTU;
   unsigned TUFlags;
@@ -43,16 +46,26 @@
   void TearDown() override {
 clang_disposeTranslationUnit(ClangTU);
 clang_disposeIndex(Index);
+
+namespace fs = llvm::sys::fs;
 for (const std::string &Path : Files)
-  llvm::sys::fs::remove(Path);
-llvm::sys::fs::remove(TestDir);
+  EXPECT_FALSE(fs::remove(Path, /*IgnoreNonExisting=*/false));
+if (RemoveTestDirRecursivelyDuringTeardown)
+  EXPECT_FALSE(fs::remove_directories(TestDir, /*IgnoreErrors=*/false));
+else
+  EXPECT_FALSE(fs::remove(TestDir, /*IgnoreNonExisting=*/false));
   }
   void WriteFile(std::string &Filename, const std::string &Contents) {
 if (!llvm::sys::path::is_absolute(Filename)) {
   llvm::SmallString<256> Path(TestDir);
-  llvm::sys::path::append(Path, Filename);
+  namespace path = llvm::sys::path;
+  for (auto FileI = path::begin(Filename), FileEnd = path::end(Filename);
+   FileI != FileEnd; ++FileI) {
+ASSERT_NE(*FileI, ".");
+path::append(Path, *FileI);
+Files.emplace(Path.str());
+  }
   Filename = std::string(Path.str());
-  Files.insert(Filename);
 }
 llvm::sys::fs::create_directories(llvm::sys::path::parent_path(Filename));
 std::ofstream OS(Filename);
Index: clang/unittests/libclang/LibclangTest.cpp
===
--- clang/unittests/libclang/LibclangTest.cpp
+++ clang/unittests/libclang/LibclangTest.cpp
@@ -515,6 +515,8 @@
   WriteFile(HeaderName, std::string(HeaderTop) + HeaderBottom);
   WriteFile(ModName, ModFile);
 
+  // Removing recursively is necessary to delete the module cache.
+  RemoveTestDirRecursivelyDuringTeardown = true;
   std::string ModulesCache = std::string("-fmodules-cache-path=") + TestDir;
   const char *Args[] = { "-fmodules", ModulesCache.c_str(),
  "-I", TestDir.c_str() };


Index: clang/unittests/libclang/TestUtils.h
===
--- clang/unittests/libclang/TestUtils.h
+++ clang/unittests/libclang/TestUtils.h
@@ -14,18 +14,21 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 
+#include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 #include 
-#include "gtest/gtest.h"
 
 class LibclangParseTest : public ::testing::Test {
-  std::set Files;
+  // std::greater<> to remove files before their parent dirs in TearDown().
+  std::set> Files;
   typedef std::unique_ptr fixed_addr_string;
   std::map UnsavedFileContents;
 public:
   std::string TestDir;
+  bool RemoveTestDirRecursivelyDuringTeardown = false;
   CXIndex Index;
   CXTranslationUnit ClangTU;
   unsigned TUFlags;
@@ -43,16 +46,26 @@
   void TearDown() override {
 clang_disposeTranslationUnit(ClangTU);
 clang_disposeIndex(Index);
+
+namespace fs = llvm::sys::fs;
 for (const std::string &Path : Files)
-  llvm::sys::fs::remove(Path);
-llvm::sys::fs::remove(TestDir);
+  EXPECT_FALSE(fs::remove(Path, /*IgnoreNonExisting=*/false));
+if (RemoveTestDirRecursivelyDuringTeardown)
+  EXPECT_FALSE(fs::remove_directories(TestDir, /*IgnoreErrors=*/false));
+else
+  EXPECT_FALSE(fs::remove(TestDir, /*IgnoreNonExisting=*/false));
   }
   void WriteFile(std::string &Filename, const std::string &Contents) {
 if (!llvm::sys::path::is_absolute(Filename)) {
   llvm::SmallString<256> Path(TestDir);
-  llvm::sys::path::append(Path, Filename);
+  namespace path = llvm::sys::path;
+  for (auto FileI = path::begin(Filename), FileEnd = path::end(Filename);
+   FileI != FileEnd; ++FileI) {
+ASSERT_NE(*FileI, ".");
+path::append(Path, *FileI);
+ 

[PATCH] D143415: LibclangTest: remove libclang-test-* tmp dir reliably

2023-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D143415#4161495 , @vedgy wrote:

> In D143415#4161460 , @aaron.ballman 
> wrote:
>
>> In D143415#4160550 , @vedgy wrote:
>>
>>> Can someone merge/land this review? I don't have commit access.
>>
>> I'm happy to do that for you -- what name and email address would you like 
>> me to use for patch attribution?
>
> user.email=igor...@gmail.com
> user.name=Igor Kushnir

Thanks!

> A pity that Phabricator doesn't pick up git user name and email.

Yeah, Phab works well for a lot of things but still has some rough edges 
unfortunately. I've landed this on your behalf in 
3eceab95f314edb85ee72c047a4acd35e757d037 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143415

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


[PATCH] D144190: [AIX][clang] Storage Locations for Constant Pointers

2023-03-01 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added a comment.

Gentle ping for review. @hubert.reinterpretcast Thanks so much!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144190

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


[PATCH] D142617: [clang][Interp] Check This pointer without creating InterpFrame

2023-03-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 501502.
tbaeder added a comment.

Added an `aligned()` assertion and renamed the old `peek(unsigned Offset)` 
returning a `void*` to `peekData()`, so both `peek` overloads are now public 
member functions.


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

https://reviews.llvm.org/D142617

Files:
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpStack.cpp
  clang/lib/AST/Interp/InterpStack.h


Index: clang/lib/AST/Interp/InterpStack.h
===
--- clang/lib/AST/Interp/InterpStack.h
+++ clang/lib/AST/Interp/InterpStack.h
@@ -64,11 +64,16 @@
 
   /// Returns a reference to the value on the top of the stack.
   template  T &peek() const {
-return *reinterpret_cast(peek(aligned_size()));
+return *reinterpret_cast(peekData(aligned_size()));
+  }
+
+  template  T &peek(size_t Offset) const {
+assert(aligned(Offset));
+return *reinterpret_cast(peekData(Offset));
   }
 
   /// Returns a pointer to the top object.
-  void *top() const { return Chunk ? peek(0) : nullptr; }
+  void *top() const { return Chunk ? peekData(0) : nullptr; }
 
   /// Returns the size of the stack in bytes.
   size_t size() const { return StackSize; }
@@ -90,7 +95,7 @@
   /// Grows the stack to accommodate a value and returns a pointer to it.
   void *grow(size_t Size);
   /// Returns a pointer from the top of the stack.
-  void *peek(size_t Size) const;
+  void *peekData(size_t Size) const;
   /// Shrinks the stack.
   void shrink(size_t Size);
 
Index: clang/lib/AST/Interp/InterpStack.cpp
===
--- clang/lib/AST/Interp/InterpStack.cpp
+++ clang/lib/AST/Interp/InterpStack.cpp
@@ -46,7 +46,7 @@
   return Object;
 }
 
-void *InterpStack::peek(size_t Size) const {
+void *InterpStack::peekData(size_t Size) const {
   assert(Chunk && "Stack is empty!");
 
   StackChunk *Ptr = Chunk;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1499,10 +1499,11 @@
 }
 
 inline bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
-  auto NewFrame = std::make_unique(S, Func, PC);
-  Pointer ThisPtr;
   if (Func->hasThisPointer()) {
-ThisPtr = NewFrame->getThis();
+size_t ThisOffset =
+Func->getArgSize() + (Func->hasRVO() ? primSize(PT_Ptr) : 0);
+const Pointer &ThisPtr = S.Stk.peek(ThisOffset);
+
 if (!CheckInvoke(S, PC, ThisPtr))
   return false;
 
@@ -1513,6 +1514,7 @@
   if (!CheckCallable(S, PC, Func))
 return false;
 
+  auto NewFrame = std::make_unique(S, Func, PC);
   InterpFrame *FrameBefore = S.Current;
   S.Current = NewFrame.get();
 


Index: clang/lib/AST/Interp/InterpStack.h
===
--- clang/lib/AST/Interp/InterpStack.h
+++ clang/lib/AST/Interp/InterpStack.h
@@ -64,11 +64,16 @@
 
   /// Returns a reference to the value on the top of the stack.
   template  T &peek() const {
-return *reinterpret_cast(peek(aligned_size()));
+return *reinterpret_cast(peekData(aligned_size()));
+  }
+
+  template  T &peek(size_t Offset) const {
+assert(aligned(Offset));
+return *reinterpret_cast(peekData(Offset));
   }
 
   /// Returns a pointer to the top object.
-  void *top() const { return Chunk ? peek(0) : nullptr; }
+  void *top() const { return Chunk ? peekData(0) : nullptr; }
 
   /// Returns the size of the stack in bytes.
   size_t size() const { return StackSize; }
@@ -90,7 +95,7 @@
   /// Grows the stack to accommodate a value and returns a pointer to it.
   void *grow(size_t Size);
   /// Returns a pointer from the top of the stack.
-  void *peek(size_t Size) const;
+  void *peekData(size_t Size) const;
   /// Shrinks the stack.
   void shrink(size_t Size);
 
Index: clang/lib/AST/Interp/InterpStack.cpp
===
--- clang/lib/AST/Interp/InterpStack.cpp
+++ clang/lib/AST/Interp/InterpStack.cpp
@@ -46,7 +46,7 @@
   return Object;
 }
 
-void *InterpStack::peek(size_t Size) const {
+void *InterpStack::peekData(size_t Size) const {
   assert(Chunk && "Stack is empty!");
 
   StackChunk *Ptr = Chunk;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1499,10 +1499,11 @@
 }
 
 inline bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
-  auto NewFrame = std::make_unique(S, Func, PC);
-  Pointer ThisPtr;
   if (Func->hasThisPointer()) {
-ThisPtr = NewFrame->getThis();
+size_t ThisOffset =
+Func->getArgSize() + (Func->hasRVO() ? primSize(PT_Ptr) : 0);
+const Pointer &ThisPtr = S.Stk.peek(ThisOffset);
+
 if (!CheckInvoke(S, PC, ThisPtr))
   return false;
 
@@ -1513,6 +1514,7 @@
   if (!CheckCallable(S, P

[PATCH] D142630: [clang][Interp] Implement virtual function calls

2023-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

(Still thinking about the implementation work here, mostly just drive-by 
comments at the moment. My gut instinct is that we've not got sufficient test 
coverage here, but that might be partially because of other parts of the 
interpreter not being ready yet.)




Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1692-1699
+if (const auto *ME = dyn_cast(E->getCallee());
+ME && ME->hasQualifier())
+  HasQualifier = true;
+
+bool IsVirtual = false;
+if (const auto *MD = dyn_cast(FuncDecl);
+MD && MD->isVirtual())

Might as well simplify these a little bit.



Comment at: clang/lib/AST/Interp/Interp.h:1546-1547
+  ThisPtr.getDeclDesc()->getType()->getAsCXXRecordDecl();
+  const CXXRecordDecl *StaticDecl = cast(Func->getParentDecl());
+  const CXXMethodDecl *InitialFunction = cast(Func->getDecl());
+  const CXXMethodDecl *Overrider = S.getContext().getOverridingFunction(




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

https://reviews.llvm.org/D142630

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


[PATCH] D145069: [analyzer][NFC] Split the no state change logic and bug report suppression into two visitors

2023-03-01 Thread Gábor Spaits via Phabricator via cfe-commits
spaits created this revision.
spaits added reviewers: NoQ, steakhal, Szelethus.
Herald added subscribers: manas, ASDenysPetrov, martong, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: All.
spaits requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As discussed in my previous patch (D142354 ) 
the analyzer can understand std::variant and std::any through regular inlining. 
However warnings coming from these classes were suppressed by 
NoStateChangeFuncVisitor, more specificly by an instance of NoStoreFuncVisitor. 
The reason behind that is that we suppress bug reports when a system header 
function was supposed to initialize its parameter but failed to (as you can 
read about it in a comment block visible in this patch).

Now the problem is that these bug report were suppressed, but they had nothing 
to do with uninitialized values. In a follow up patch I intend to fix that and 
see how this suppression logic works as it was meant to be, but my initial 
testing shows that they no longer falsely suppress reports like this:

  std::variant v = 0;
  int i = std::get(v);
  10/i; // FIXME: This should warn for division by zero!

In this patch I only separated these two functionalities because I don't think 
this suppression should be implemented in a NoStateChangeVisitor but in it's 
own.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145069

Files:
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -452,6 +452,58 @@
   CallEventRef<> Call =
   BR.getStateManager().getCallEventManager().getCaller(SCtx, State);
 
+  if (Call->isInSystemHeader())
+return nullptr;
+
+  if (const auto *MC = dyn_cast(Call)) {
+// If we failed to construct a piece for self, we still want to check
+// whether the entity of interest is in a parameter.
+if (PathDiagnosticPieceRef Piece = maybeEmitNoteForObjCSelf(R, *MC, N))
+  return Piece;
+  }
+
+  if (const auto *CCall = dyn_cast(Call)) {
+// Do not generate diagnostics for not modified parameters in
+// constructors.
+return maybeEmitNoteForCXXThis(R, *CCall, N);
+  }
+
+  return maybeEmitNoteForParameters(R, *Call, N);
+}
+
+//===--===//
+// Implementation of SuppressSystemHeaderWarningVistor.
+//===--===//
+
+namespace {
+class SuppressSystemHeaderWarningVisitor : public BugReporterVisitor {
+public:
+  virtual PathDiagnosticPieceRef VisitNode(const ExplodedNode *,
+   BugReporterContext &,
+   PathSensitiveBugReport &) override;
+  void Profile(llvm::FoldingSetNodeID &ID) const override {
+static int Tag = 0;
+ID.AddPointer(&Tag);
+  }
+};
+} // namespace
+
+PathDiagnosticPieceRef
+SuppressSystemHeaderWarningVisitor::VisitNode(const ExplodedNode *Succ,
+  BugReporterContext &BRC,
+  PathSensitiveBugReport &BR) {
+  const LocationContext *Ctx = Succ->getLocationContext();
+  const StackFrameContext *SCtx = Ctx->getStackFrame();
+  ProgramStateRef State = Succ->getState();
+  auto CallExitLoc = Succ->getLocationAs();
+
+  // No diagnostic if region was modified inside the frame.
+  if (!CallExitLoc)
+return nullptr;
+
+  CallEventRef<> Call =
+  BRC.getStateManager().getCallEventManager().getCaller(SCtx, State);
+
   // Optimistically suppress uninitialized value bugs that result
   // from system headers having a chance to initialize the value
   // but failing to do so. It's too unlikely a system header's fault.
@@ -469,27 +521,13 @@
 // One common example of a standard function that doesn't ever initialize
 // its out parameter is operator placement new; it's up to the follow-up
 // constructor (if any) to initialize the memory.
-if (!N->getStackFrame()->getCFG()->isLinear()) {
+
+if (!Succ->getStackFrame()->getCFG()->isLinear()) {
   static int i = 0;
-  R.markInvalid(&i, nullptr);
+  BR.markInvalid(&i, nullptr);
 }
-return nullptr;
-  }
-
-  if (const auto *MC = dyn_cast(Call)) {
-// If we failed to construct a piece for self, we still want to check
-// whether the entity of interest is in a parameter.
-if (PathDiagnosticPieceRef Piece = maybeEmitNoteForObjCSelf(R, *MC, N))
-  return Piece;
-  }
-
-  if (const auto *CCall = dyn_cast(Call)) {
-// Do not generate diagnostics for not modified parameters in
-// constructors.
-return maybeEmitNote

[clang] 34b412d - [clang][RISCV][test] Add coverage for __fp16 support in arguments/returns

2023-03-01 Thread Alex Bradbury via cfe-commits

Author: Alex Bradbury
Date: 2023-03-01T15:20:15Z
New Revision: 34b412dc0efe898b18b7afcf02d9e44d7e05b5ec

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

LOG: [clang][RISCV][test] Add coverage for __fp16 support in arguments/returns

By choice, we don't set HalfArgsAndReturns=true (which would allow
__fp16 in args and returns). Add test coverage for this to ensure it
isn't changed by accident.

Added: 
clang/test/Sema/riscv-fp16.c

Modified: 


Removed: 




diff  --git a/clang/test/Sema/riscv-fp16.c b/clang/test/Sema/riscv-fp16.c
new file mode 100644
index 0..7c39f9f9e7fbc
--- /dev/null
+++ b/clang/test/Sema/riscv-fp16.c
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -fsyntax-only -triple riscv32 -Wno-strict-prototypes 
-verify %s
+// RUN: %clang_cc1 -fsyntax-only -triple riscv64 -Wno-strict-prototypes 
-verify %s
+// REQUIRES: riscv-registered-target
+
+// Functions cannot have parameters of type __fp16.
+extern void f (__fp16); // expected-error {{parameters cannot have __fp16 
type; did you forget * ?}}
+extern void g (__fp16 *);
+
+extern void (*pf) (__fp16);  // expected-error {{parameters cannot have __fp16 
type; did you forget * ?}}
+extern void (*pg) (__fp16*);
+
+typedef void(*tf) (__fp16);  // expected-error {{parameters cannot have __fp16 
type; did you forget * ?}}
+typedef void(*tg) (__fp16*);
+
+void kf(a)
+ __fp16 a; {  // expected-error {{parameters cannot have __fp16 type; did you 
forget * ?}}
+}
+
+void kg(a)
+ __fp16 *a; {
+}
+
+// Functions cannot return type __fp16.
+extern __fp16 f1 (void); // expected-error {{function return value cannot have 
__fp16 type; did you forget * ?}}
+extern __fp16 *g1 (void);
+
+extern __fp16 (*pf1) (void); // expected-error {{function return value cannot 
have __fp16 type; did you forget * ?}}
+extern __fp16 *(*gf1) (void);
+
+typedef __fp16 (*tf1) (void); // expected-error {{function return value cannot 
have __fp16 type; did you forget * ?}}
+typedef __fp16 *(*tg1) (void);
+
+void testComplex() {
+  // FIXME: Should these be valid?
+  _Complex __fp16 a; // expected-error {{'_Complex half' is invalid}}
+  __fp16 b;
+  a = __builtin_complex(b, b); // expected-error {{'_Complex half' is invalid}}
+}



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


[PATCH] D142630: [clang][Interp] Implement virtual function calls

2023-03-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 501506.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D142630

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Context.h
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpState.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/Pointer.h
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -1,8 +1,10 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++14 -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify %s
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple i686 -verify %s
 // RUN: %clang_cc1 -verify=ref %s
 // RUN: %clang_cc1 -verify=ref -std=c++14 %s
+// RUN: %clang_cc1 -verify=ref -std=c++20 %s
 // RUN: %clang_cc1 -verify=ref -triple i686 %s
 
 struct BoolPair {
@@ -286,6 +288,7 @@
 };
 
 namespace DeriveFailures {
+#if __cplusplus < 202002L
   struct Base { // ref-note 2{{declared here}}
 int Val;
   };
@@ -301,10 +304,12 @@
// ref-note {{in call to 'Derived(12)'}} \
// ref-note {{declared here}} \
// expected-error {{must be initialized by a constant expression}}
+
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant expression}} \
  // ref-note {{initializer of 'D' is not a constant expression}} \
  // expected-error {{not an integral constant expression}} \
  // expected-note {{read of object outside its lifetime}}
+#endif
 
   struct AnotherBase {
 int Val;
@@ -354,3 +359,121 @@
   static_assert(getS(true).a == 12, "");
   static_assert(getS(false).a == 13, "");
 };
+
+#if __cplusplus >= 202002L
+namespace VirtualCalls {
+namespace Obvious {
+
+  class A {
+  public:
+constexpr A(){}
+constexpr virtual int foo() {
+  return 3;
+}
+  };
+  class B : public A {
+  public:
+constexpr int foo() override {
+  return 6;
+}
+  };
+
+  constexpr int getFooB(bool b) {
+A *a;
+A myA;
+B myB;
+
+if (b)
+  a = &myA;
+else
+  a = &myB;
+
+return a->foo();
+  }
+  static_assert(getFooB(true) == 3, "");
+  static_assert(getFooB(false) == 6, "");
+}
+
+namespace MultipleBases {
+  class A {
+  public:
+constexpr virtual int getInt() const { return 10; }
+  };
+  class B {
+  public:
+  };
+  class C : public A, public B {
+  public:
+constexpr int getInt() const override { return 20; }
+  };
+
+  constexpr int callGetInt(const A& a) { return a.getInt(); }
+  static_assert(callGetInt(C()) == 20, "");
+  static_assert(callGetInt(A()) == 10, "");
+}
+
+namespace Destructors {
+  class Base {
+  public:
+int i;
+constexpr Base(int &i) : i(i) {i++;}
+constexpr virtual ~Base() {i--;}
+  };
+
+  class Derived : public Base {
+  public:
+constexpr Derived(int &i) : Base(i) {}
+constexpr virtual ~Derived() {i--;}
+  };
+
+  constexpr int test() {
+int i = 0;
+Derived d(i);
+return i;
+  }
+  static_assert(test() == 1);
+}
+
+
+namespace QualifiedCalls {
+  class A {
+  public:
+  constexpr virtual int foo() const {
+  return 5;
+  }
+  };
+  class B : public A {};
+  class C : public B {
+  public:
+  constexpr int foo() const override {
+  return B::foo(); // B doesn't have a foo(), so this should call A::foo().
+  }
+  constexpr int foo2() const {
+return this->A::foo();
+  }
+  };
+  constexpr C c;
+  static_assert(c.foo() == 5);
+  static_assert(c.foo2() == 5);
+
+
+  struct S {
+int _c = 0;
+virtual constexpr int foo() const { return 1; }
+  };
+
+  struct SS : S {
+int a;
+constexpr SS() {
+  a = S::foo();
+}
+constexpr int foo() const override {
+  return S::foo();
+}
+  };
+
+  constexpr SS ss;
+  static_assert(ss.a == 1);
+}
+};
+#endif
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -206,6 +206,8 @@
   /// Returns the type of the innermost field.
   QualType getType() const { return getFieldDesc()->getType(); }
 
+  Pointer getDeclPtr() const { return Pointer(Pointee); }
+
   /// Returns the element size of the innermost field.
   size_t elemSize() const {
 if (Base == RootPtrMark)
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AS

[PATCH] D145007: Driver: introduce GNU spellings to control MSVC paths

2023-03-01 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

Yeah, I suspect that would be difficult.  Additionally, these are aliases, so 
they should already have testing coverage through the existing tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145007

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


[PATCH] D141230: [clang-format-diff.py] give clang-format-diff a job pool (10x speed)

2023-03-01 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D141230#4054768 , @seanptmaher 
wrote:

> I can't actually commit this -- could one of you? Or has it already been 
> done? I remember reading that someone had to manually push the patch upstream.

Can we have the name and email you want to use for your patch? See 
https://llvm.org/docs/Phabricator.html#committing-someone-s-change-from-phabricator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141230

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


[PATCH] D144371: [LLVM-COV] Fix an issue: a statement after calling 'assert()' function is wrongly marked as 'not executed'

2023-03-01 Thread Ying Yi via Phabricator via cfe-commits
MaggieYi updated this revision to Diff 501509.
MaggieYi added a comment.

Thanks Zequan. I have added two tests following your suggestion.

Kind regards,
Maggie


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

https://reviews.llvm.org/D144371

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/terminate-statements.cpp

Index: clang/test/CoverageMapping/terminate-statements.cpp
===
--- clang/test/CoverageMapping/terminate-statements.cpp
+++ clang/test/CoverageMapping/terminate-statements.cpp
@@ -320,6 +320,32 @@
   included_func();
 }
 
+// CHECK-LABEL: _Z7ornoretv:
+void abort() __attribute__((noreturn));
+
+int ornoret(void) {
+  ( true || (abort(), 0) );  // CHECK: Gap,File 0, [[@LINE]]:28 -> [[@LINE+1]]:3 = #0
+  ( false || (abort(), 0) ); // CHECK: Gap,File 0, [[@LINE]]:29 -> [[@LINE+1]]:3 = 0
+  return 0;
+}
+
+// CHECK-LABEL: _Z17abstractcondnoretv:
+int abstractcondnoret(void) {
+  ( true ? void (0) : abort() );  // CHECK: Gap,File 0, [[@LINE]]:33 -> [[@LINE+1]]:3 = #1
+  ( false ? void (0) : abort() ); // CHECK: Gap,File 0, [[@LINE]]:34 -> [[@LINE+1]]:3 = #2
+  ( true ? abort() : void (0) );  // CHECK: Gap,File 0, [[@LINE]]:33 -> [[@LINE+1]]:3 = (#2 - #3)
+  ( false ? abort() : void (0) ); // CHECK: Gap,File 0, [[@LINE]]:34 -> [[@LINE+1]]:3 = ((#2 - #3) - #4)
+  return 0;
+}
+
+// CHECK-LABEL: _Z13elsecondnoretv:
+int elsecondnoret(void) {
+  if (true) {} else {
+true ? void (0) : abort();
+  } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+1]]:3 = (#1 + #2)
+  return 0;
+}
+
 int main() {
   foo(0);
   foo(1);
@@ -339,5 +365,8 @@
   while_loop();
   gotos();
   include();
+  ornoret();
+  abstractcondnoret();
+  elsecondnoret();
   return 0;
 }
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1466,6 +1466,7 @@
 Counter TrueCount = getRegionCounter(E);
 
 propagateCounts(ParentCount, E->getCond());
+Counter OutCount;
 
 if (!isa(E)) {
   // The 'then' count applies to the area immediately after the condition.
@@ -1475,12 +1476,18 @@
 fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), TrueCount);
 
   extendRegion(E->getTrueExpr());
-  propagateCounts(TrueCount, E->getTrueExpr());
+  OutCount = propagateCounts(TrueCount, E->getTrueExpr());
 }
 
 extendRegion(E->getFalseExpr());
-propagateCounts(subtractCounters(ParentCount, TrueCount),
-E->getFalseExpr());
+OutCount = addCounters(
+OutCount, propagateCounts(subtractCounters(ParentCount, TrueCount),
+  E->getFalseExpr()));
+
+if (OutCount != ParentCount) {
+  pushRegion(OutCount);
+  GapRegionCounter = OutCount;
+}
 
 // Create Branch Region around condition.
 createBranchRegion(E->getCond(), TrueCount,
@@ -1514,9 +1521,19 @@
subtractCounters(RHSExecCnt, RHSTrueCnt));
   }
 
+  // Determine whether the right side of OR operation need to be visited.
+  bool shouldVisitRHS(const Expr *LHS) {
+bool LHSIsTrue = false;
+bool LHSIsConst = false;
+if (!LHS->isValueDependent())
+  LHSIsConst = LHS->EvaluateAsBooleanCondition(
+  LHSIsTrue, CVM.getCodeGenModule().getContext());
+return !LHSIsConst || (LHSIsConst && !LHSIsTrue);
+  }
+
   void VisitBinLOr(const BinaryOperator *E) {
 extendRegion(E->getLHS());
-propagateCounts(getRegion().getCounter(), E->getLHS());
+Counter OutCount = propagateCounts(getRegion().getCounter(), E->getLHS());
 handleFileExit(getEnd(E->getLHS()));
 
 // Counter tracks the right hand side of a logical or operator.
@@ -1529,6 +1546,10 @@
 // Extract the RHS's "False" Instance Counter.
 Counter RHSFalseCnt = getRegionCounter(E->getRHS());
 
+if (!shouldVisitRHS(E->getLHS())) {
+  GapRegionCounter = OutCount;
+}
+
 // Extract the Parent Region Counter.
 Counter ParentCnt = getRegion().getCounter();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144371: [LLVM-COV] Fix an issue: a statement after calling 'assert()' function is wrongly marked as 'not executed'

2023-03-01 Thread Ying Yi via Phabricator via cfe-commits
MaggieYi marked an inline comment as done.
MaggieYi added inline comments.



Comment at: clang/test/CoverageMapping/terminate-statements.cpp:335
+  ( true ? void (0) : abort() );  // CHECK: Gap,File 0, [[@LINE]]:33 -> 
[[@LINE+1]]:3 = #1
+  ( false ? void (0) : abort() ); // CHECK: Gap,File 0, [[@LINE]]:34 -> 
[[@LINE+1]]:3 = #2
+  return 0;

zequanwu wrote:
> For completeness, can you add following two tests:
> ```
> ( true ? abort() : void (0) );
> ( false ? abort() : void (0) );
> ```
Thanks, two tests have been added.



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

https://reviews.llvm.org/D144371

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


[PATCH] D143466: [clang][Interp] Fix initializing base class members

2023-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/AST/Interp/records.cpp:260
+  class _C : public _B {};
+  constexpr _C c{12};
+};

We should test that the initialization actually happened.



Comment at: clang/test/AST/Interp/records.cpp:262
+};
+#endif
+

Another test would be for invalid base initialization, like:
```
struct Base {
  int a;
};

struct Intermediate : Base {
  int b;
};

struct Final : Intermediate {
  int c;

  constexpr Final(int a, int b, int c) : c(c) {}
};

static_assert(Final{1, 2, 3}.c == 3, ""); // OK
static_assert(Final{1, 2, 3}.a == 0, ""); // Error, reads uninitialized member
```
or with multiple bases:
```
struct Base {
  int a;
};

struct Mixin  {
  int b;

  constexpr Mixin() = default;
  constexpr Mixin(int b) : b(b) {}
};

struct Final : Base, Mixin {
  int c;

  constexpr Final(int a, int b, int c) : Mixin(b), c(c) {}
  constexpr Final(int a, int b, int c, bool) : c(c) {}
};

static_assert(Final{1, 2, 3}.c == 3, ""); // OK
static_assert(Final{1, 2, 3}.b == 2, ""); // OK
static_assert(Final{1, 2, 3}.a == 0, ""); // Error, reads uninitialized member
```
or in a different form:
```
struct Base {
  int a;
};

struct Mixin  {
  int b;
};

struct Final : Base, Mixin {
  int c;

  constexpr Final(int a, int b, int c) : c(c) { this->b = b; }
  constexpr Final(int a, int b, int c, bool) : c(c) {}
};

static_assert(Final{1, 2, 3}.c == 3, ""); // OK
static_assert(Final{1, 2, 3}.b == 2, ""); // OK
static_assert(Final{1, 2, 3}.a == 0, ""); // Error, reads uninitialized member
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143466

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


[PATCH] D141591: [clang][Interp] Properly identify not-yet-defined functions

2023-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D141591

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


[PATCH] D144273: [clang][ASTImporter] Add VaList declaration to lookup table.

2023-03-01 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 501514.
balazske added a comment.

Add a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144273

Files:
  clang/lib/AST/ASTImporterLookupTable.cpp
  clang/test/Import/cxx-valist/Inputs/I1.cpp
  clang/test/Import/cxx-valist/Inputs/I2.cpp
  clang/test/Import/cxx-valist/test.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8378,6 +8378,42 @@
   EXPECT_TRUE(ToCtx.hasSameType(ToInjTypedef, ToInjParmVar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VaListC) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", Lang_C99);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_C99);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, VaListCpp) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", 
Lang_CXX03);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_CXX03);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/test/Import/cxx-valist/test.cpp
===
--- /dev/null
+++ clang/test/Import/cxx-valist/test.cpp
@@ -0,0 +1,5 @@
+// RUN: clang-import-test -import %S/Inputs/I1.cpp -import %S/Inputs/I2.cpp 
-expression %s
+
+void expr() {
+  use_new(std);
+}
Index: clang/test/Import/cxx-valist/Inputs/I2.cpp
===
--- /dev/null
+++ clang/test/Import/cxx-valist/Inputs/I2.cpp
@@ -0,0 +1 @@
+int std = 17;
Index: clang/test/Import/cxx-valist/Inputs/I1.cpp
===
--- /dev/null
+++ clang/test/Import/cxx-valist/Inputs/I1.cpp
@@ -0,0 +1,3 @@
+int *use_new(int N) {
+  return new int [N];
+}
Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -87,6 +87,18 @@
 ASTImporterLookupTable::ASTImporterLookupTable(TranslationUnitDecl &TU) {
   Builder B(*this);
   B.TraverseDecl(&TU);
+  // The VaList declaration may be created on demand only or not traversed.
+  // To ensure it is present and found during import, add it to the table now.
+  if (auto *D =
+  dyn_cast_or_null(TU.getASTContext().getVaListTagDecl())) {
+// On some platforms (AArch64) the VaList declaration can be inside a 'std'
+// namespace. This is handled specially and not visible by AST traversal.
+// ASTImporter must be able to find this namespace to import the VaList
+// declaration (and the namespace) correctly.
+if (auto *Ns = dyn_cast(D->getDeclContext()))
+  add(&TU, Ns);
+add(D->getDeclContext(), D);
+  }
 }
 
 void ASTImporterLookupTable::add(DeclContext *DC, NamedDecl *ND) {


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8378,6 +8378,42 @@
   EXPECT_TRUE(ToCtx.hasSameType(ToInjTypedef, ToInjParmVar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VaListC) {
+  Decl *FromTU = getTuDecl(R"(typedef __builtin_va_list va_list;)", Lang_C99);
+
+  auto *FromVaList = FirstDeclMatcher().match(
+  FromTU, typedefDecl(hasName("va_list")));
+  ASSERT_TRUE(FromVaList);
+
+  auto *ToVaList = Import(FromVaList, Lang_C99);
+  ASSERT_TRUE(ToVaList);
+
+  auto *ToBuiltinVaList = FirstDeclMatcher().match(
+  ToAST->getASTContext().getTranslationUnitDecl(),
+  typedefDecl(hasName("__builtin_va_list")));
+
+  ASSERT_TRUE(ToAST->getASTContext().hasSameType(
+  ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, VaListCpp) {
+  Decl *FromTU = ge

[PATCH] D144371: [LLVM-COV] Fix an issue: a statement after calling 'assert()' function is wrongly marked as 'not executed'

2023-03-01 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu accepted this revision.
zequanwu added a comment.
This revision is now accepted and ready to land.

LGTM.


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

https://reviews.llvm.org/D144371

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


[PATCH] D144934: [clang] drop buggy use of `-serialize-diagnostics` flag

2023-03-01 Thread Ashay Rane via Phabricator via cfe-commits
ashay-github updated this revision to Diff 501516.
ashay-github added a comment.

Rebased with main branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144934

Files:
  clang/test/ClangScanDeps/P1689.cppm


Index: clang/test/ClangScanDeps/P1689.cppm
===
--- clang/test/ClangScanDeps/P1689.cppm
+++ clang/test/ClangScanDeps/P1689.cppm
@@ -40,7 +40,7 @@
 //
 // Check that we can mix the use of -format=p1689 and -fmodules.
 // RUN: clang-scan-deps -format=p1689 \
-// RUN:   -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache -serialize-diagnostics -c %t/impl_part.cppm -o 
%t/impl_part.o \
+// RUN:   -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache -c %t/impl_part.cppm -o %t/impl_part.o \
 // RUN:   | FileCheck %t/impl_part.cppm -DPREFIX=%/t
 
 //--- P1689.json.in


Index: clang/test/ClangScanDeps/P1689.cppm
===
--- clang/test/ClangScanDeps/P1689.cppm
+++ clang/test/ClangScanDeps/P1689.cppm
@@ -40,7 +40,7 @@
 //
 // Check that we can mix the use of -format=p1689 and -fmodules.
 // RUN: clang-scan-deps -format=p1689 \
-// RUN:   -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -serialize-diagnostics -c %t/impl_part.cppm -o %t/impl_part.o \
+// RUN:   -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -c %t/impl_part.cppm -o %t/impl_part.o \
 // RUN:   | FileCheck %t/impl_part.cppm -DPREFIX=%/t
 
 //--- P1689.json.in
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144273: [clang][ASTImporter] Add VaList declaration to lookup table.

2023-03-01 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

A tried to find out how to add a correct test but could not check if this fails 
or not on AArch64 platform. The test should import the va_list declarations and 
then another variable `std`. I want to touch `ASTContext` only if a test 
failure is found on AArch64 that makes it necessary. In that case I would add a 
non-modifying function `getVaListTagDeclIfExists`, another option is to change 
all other simiar get functions to "getOrCreate" form to have consistent API.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144273

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


[PATCH] D144709: [clang-format] Improve QualifierAlignment

2023-03-01 Thread Alexander Hederstaf via Phabricator via cfe-commits
AlexanderHederstaf added a comment.

In D144709#4160939 , 
@AlexanderHederstaf wrote:

> This code from llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp failed 
> with **Right** but without a full list of specifiers. As **static** was not 
> configured, the } was not discovered by **IsRightQualifier**. Changed some of 
> the qualifier tests to check against the full list instead.
>
>   struct ExecutionClass {
> ExecutionMode Mask;
> const char *Description;
>   } static const kExecutionClasses[] = {
>   {ExecutionMode::ALWAYS_SERIAL_IMPLICIT_REGS_ALIAS |
>ExecutionMode::ALWAYS_SERIAL_TIED_REGS_ALIAS,
>"Repeating a single implicitly serial instruction"},
>   {ExecutionMode::SERIAL_VIA_EXPLICIT_REGS,
>"Repeating a single explicitly serial instruction"},
>   {ExecutionMode::SERIAL_VIA_MEMORY_INSTR |
>ExecutionMode::SERIAL_VIA_NON_MEMORY_INSTR,
>"Repeating two instructions"},
>   };
>
> Resulted in
>
>   } static kExecutionClasses const[] = {
>
> Which is now fixed. This struct will be left unchanged as with other structs.
>
> I used clang-format on all files in clang/ and llvm/, where I had added 
> QualifierAlignment: Right to any .clang-format. I built with
>
>   cmake -S llvm -B build -G Ninja -DCMAKE_BUILD_TYPE=Release 
> -DLLVM_ENABLE_PROJECTS="clang"
>   cmake --build build
>
> Is that sufficient or did you imagine some other build?

Performed the test for
Original -> Right -> compiles


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[clang] 730eca6 - [clang][Interp] Handle DecompositionDecls

2023-03-01 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-03-01T17:11:57+01:00
New Revision: 730eca6a3de85ae66bb905ee32c47332b5395226

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

LOG: [clang][Interp] Handle DecompositionDecls

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

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

Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/Program.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 2b4e324f7b0fa..d4c9292739609 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -28,7 +28,7 @@ namespace interp {
 /// Scope used to handle temporaries in toplevel variable declarations.
 template  class DeclScope final : public LocalScope {
 public:
-  DeclScope(ByteCodeExprGen *Ctx, const VarDecl *VD)
+  DeclScope(ByteCodeExprGen *Ctx, const ValueDecl *VD)
   : LocalScope(Ctx), Scope(Ctx->P, VD) {}
 
   void addExtended(const Scope::Local &Local) override {
@@ -936,11 +936,11 @@ bool ByteCodeExprGen::dereference(
   if (std::optional T = classify(LV->getType())) {
 if (!LV->refersToBitField()) {
   // Only primitive, non bit-field types can be dereferenced directly.
-  if (auto *DE = dyn_cast(LV)) {
+  if (const auto *DE = dyn_cast(LV)) {
 if (!DE->getDecl()->getType()->isReferenceType()) {
-  if (auto *PD = dyn_cast(DE->getDecl()))
+  if (const auto *PD = dyn_cast(DE->getDecl()))
 return dereferenceParam(LV, *T, PD, AK, Direct, Indirect);
-  if (auto *VD = dyn_cast(DE->getDecl()))
+  if (const auto *VD = dyn_cast(DE->getDecl()))
 return dereferenceVar(LV, *T, VD, AK, Direct, Indirect);
 }
   }
@@ -1823,6 +1823,8 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
 }
   } else if (const auto *ECD = dyn_cast(Decl)) {
 return this->emitConst(ECD->getInitVal(), E);
+  } else if (const auto *BD = dyn_cast(Decl)) {
+return this->visit(BD->getBinding());
   }
 
   return false;

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 74cd5984daf55..d6390116010b4 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -235,9 +235,12 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   }
 
   /// Returns whether we should create a global variable for the
-  /// given VarDecl.
-  bool shouldBeGloballyIndexed(const VarDecl *VD) const {
-return VD->hasGlobalStorage() || VD->isConstexpr();
+  /// given ValueDecl.
+  bool shouldBeGloballyIndexed(const ValueDecl *VD) const {
+if (const auto *V = dyn_cast(VD))
+  return V->hasGlobalStorage() || V->isConstexpr();
+
+return false;
   }
 
   llvm::RoundingMode getRoundingMode(const Expr *E) const {

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index 522b04254e85d..ff2727cc4d354 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -205,17 +205,11 @@ bool ByteCodeStmtGen::visitCompoundStmt(
 template 
 bool ByteCodeStmtGen::visitDeclStmt(const DeclStmt *DS) {
   for (auto *D : DS->decls()) {
-// Variable declarator.
-if (auto *VD = dyn_cast(D)) {
-  if (!this->visitVarDecl(VD))
-return false;
-  continue;
-}
-
-// Decomposition declarator.
-if (auto *DD = dyn_cast(D)) {
-  return this->bail(DD);
-}
+const auto *VD = dyn_cast(D);
+if (!VD)
+  return false;
+if (!this->visitVarDecl(VD))
+  return false;
   }
 
   return true;

diff  --git a/clang/lib/AST/Interp/Program.h b/clang/lib/AST/Interp/Program.h
index 5a80dd1ed748e..4547ca7ac69c1 100644
--- a/clang/lib/AST/Interp/Program.h
+++ b/clang/lib/AST/Interp/Program.h
@@ -131,7 +131,9 @@ class Program final {
   /// Context to manage declaration lifetimes.
   class DeclScope {
   public:
-DeclScope(Program &P, const VarDecl *VD) : P(P) { P.startDeclaration(VD); }
+DeclScope(Program &P, const ValueDecl *VD) : P(P) {
+  P.startDeclaration(VD);
+}
 ~DeclScope() { P.endDeclaration(); }
 
   private:
@@ -222,7 +224,7 @@ class Program final {
   unsigned CurrentDeclaration = NoDeclaration;
 
   /// Starts evaluating a declaration.
-  void startDeclaration(const VarDecl *Decl) {
+  void startDeclaration(const ValueDecl *Decl) {
 LastDeclaration += 1;
 CurrentDeclaration = LastDeclaration;
   }

diff  --git a/clang/test/AST/Interp/cxx17.cpp b/clang/test/AST/Interp/cxx17.cpp
new file mode 100644
index 0..e72ff738ff630
--- /dev/null

[PATCH] D138802: [clang][Interp] Implement DecompositionDecls

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

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138802

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/Program.h
  clang/test/AST/Interp/cxx17.cpp

Index: clang/test/AST/Interp/cxx17.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/cxx17.cpp
@@ -0,0 +1,85 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++17 -verify=ref %s
+
+// ref-no-diagnostics
+
+struct F { int a; int b;};
+constexpr F getF() {
+  return {12, 3};
+}
+constexpr int f() {
+  auto [a1, b1] = getF();
+  auto [a2, b2] = getF();
+
+  return a1 + a2 + b1 + b2;
+}
+static_assert(f() == 30);
+
+
+constexpr int structRefs() {
+  const auto &[a, b] = getF();
+
+  return a + b;
+}
+// FIXME: This should work, but the MaterializeTemporaryExpr handling is not ready for it.
+static_assert(structRefs() == 15); // expected-error {{not an integral constant expression}}
+
+constexpr int structRefs2() {
+  F f = getF();
+  const auto &[a, b] = f;
+
+  return a + b;
+}
+static_assert(structRefs2() == 15);
+
+
+template
+struct Tuple {
+  T first;
+  T second;
+  constexpr Tuple(T a, T b) : first(a), second(b) {}
+};
+template
+constexpr T addTuple(const Tuple &Tu) {
+  auto [a, b] = Tu;
+  return a + b;
+}
+
+template
+constexpr T addTuple2(const Tuple &Tu) {
+  auto [a, b] = Tu;
+  return Tu.first + Tu.second;
+}
+
+constexpr Tuple T1 = Tuple(1,2);
+static_assert(addTuple(T1) == 3);
+static_assert(addTuple2(T1) == 3);
+
+constexpr Tuple T2 = Tuple(11,2);
+static_assert(addTuple(T2) == 13);
+static_assert(addTuple2(T2) == 13);
+
+constexpr int Modify() {
+  auto T = Tuple(10, 20);
+  auto &[x, y] = T;
+  x += 1;
+  y += 1;
+  return T.first + T.second;
+}
+static_assert(Modify() == 32, "");
+
+constexpr int a() {
+  int a[2] = {5, 3};
+  auto [x, y] = a;
+  return x + y;
+}
+static_assert(a() == 8);
+
+constexpr int b() {
+  int a[2] = {5, 3};
+  auto &[x, y] = a;
+  x += 1;
+  y += 2;
+  return a[0] + a[1];
+}
+static_assert(b() == 11);
Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -131,7 +131,9 @@
   /// Context to manage declaration lifetimes.
   class DeclScope {
   public:
-DeclScope(Program &P, const VarDecl *VD) : P(P) { P.startDeclaration(VD); }
+DeclScope(Program &P, const ValueDecl *VD) : P(P) {
+  P.startDeclaration(VD);
+}
 ~DeclScope() { P.endDeclaration(); }
 
   private:
@@ -222,7 +224,7 @@
   unsigned CurrentDeclaration = NoDeclaration;
 
   /// Starts evaluating a declaration.
-  void startDeclaration(const VarDecl *Decl) {
+  void startDeclaration(const ValueDecl *Decl) {
 LastDeclaration += 1;
 CurrentDeclaration = LastDeclaration;
   }
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -205,17 +205,11 @@
 template 
 bool ByteCodeStmtGen::visitDeclStmt(const DeclStmt *DS) {
   for (auto *D : DS->decls()) {
-// Variable declarator.
-if (auto *VD = dyn_cast(D)) {
-  if (!this->visitVarDecl(VD))
-return false;
-  continue;
-}
-
-// Decomposition declarator.
-if (auto *DD = dyn_cast(D)) {
-  return this->bail(DD);
-}
+const auto *VD = dyn_cast(D);
+if (!VD)
+  return false;
+if (!this->visitVarDecl(VD))
+  return false;
   }
 
   return true;
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -235,9 +235,12 @@
   }
 
   /// Returns whether we should create a global variable for the
-  /// given VarDecl.
-  bool shouldBeGloballyIndexed(const VarDecl *VD) const {
-return VD->hasGlobalStorage() || VD->isConstexpr();
+  /// given ValueDecl.
+  bool shouldBeGloballyIndexed(const ValueDecl *VD) const {
+if (const auto *V = dyn_cast(VD))
+  return V->hasGlobalStorage() || V->isConstexpr();
+
+return false;
   }
 
   llvm::RoundingMode getRoundingMode(const Expr *E) const {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -28,7 +28,7 @@
 /// Scope used to handle temporaries in toplevel variable declarations.
 template  class DeclScope final : public LocalScope {
 publi

[PATCH] D140891: [analyzer] Fix assertion failure in SMT conversion for unary operator on floats.

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

I'm proposing to backport this fix to clang-16.
https://github.com/llvm/llvm-project/issues/61097


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140891

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


[PATCH] D140075: [libclang] Expose using shadow types and declarations in libclang.

2023-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/tools/libclang/CXCursor.cpp:1279-1281
+  if (const UsingType *Using = Ty->getAs())
+if (const UsingShadowDecl *Shadow = Using->getFoundDecl())
+  if (const auto *TD = dyn_cast_or_null(Shadow->getTargetDecl()))

Hmm, we're exposing `CXType_Using` but here we're not giving back a cursor to 
the `UsingType` but instead looking through that type to get down to a 
declaration and are returning that.

Should we split these in two different cursors?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140075

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


[PATCH] D142617: [clang][Interp] Check This pointer without creating InterpFrame

2023-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


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

https://reviews.llvm.org/D142617

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


[PATCH] D145021: [Clang][AIX][p] Claim -p in front end

2023-03-01 Thread Michael Francis via Phabricator via cfe-commits
francii updated this revision to Diff 501526.
francii added a comment.

Add test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145021

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/unused.c


Index: clang/test/Driver/unused.c
===
--- /dev/null
+++ clang/test/Driver/unused.c
@@ -0,0 +1,8 @@
+// Check that -p is still used when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
+
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6324,7 +6324,7 @@
 << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+  if (Arg *A = Args.getLastArg(options::OPT_p)) {
 if (TC.getTriple().isOSAIX()) {
   CmdArgs.push_back("-pg");
 } else if (!TC.getTriple().isOSOpenBSD()) {


Index: clang/test/Driver/unused.c
===
--- /dev/null
+++ clang/test/Driver/unused.c
@@ -0,0 +1,8 @@
+// Check that -p is still used when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
+
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6324,7 +6324,7 @@
 << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+  if (Arg *A = Args.getLastArg(options::OPT_p)) {
 if (TC.getTriple().isOSAIX()) {
   CmdArgs.push_back("-pg");
 } else if (!TC.getTriple().isOSOpenBSD()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145021: [Clang][AIX][p] Claim -p in front end

2023-03-01 Thread Michael Francis via Phabricator via cfe-commits
francii updated this revision to Diff 501527.
francii added a comment.

Merge z/OS and AIX profiling tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145021

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ibm-profiling.c
  clang/test/Driver/unused.c
  clang/test/Driver/zos-profiling-error.c


Index: clang/test/Driver/zos-profiling-error.c
===
--- clang/test/Driver/zos-profiling-error.c
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck 
-check-prefix=FAIL-PG-NAME %s
-// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
Index: clang/test/Driver/unused.c
===
--- /dev/null
+++ clang/test/Driver/unused.c
@@ -0,0 +1,8 @@
+// Check that -p is still used when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
+
Index: clang/test/Driver/ibm-profiling.c
===
--- /dev/null
+++ clang/test/Driver/ibm-profiling.c
@@ -0,0 +1,10 @@
+// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck 
-check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
+
+// Check that -p is still used when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6324,7 +6324,7 @@
 << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+  if (Arg *A = Args.getLastArg(options::OPT_p)) {
 if (TC.getTriple().isOSAIX()) {
   CmdArgs.push_back("-pg");
 } else if (!TC.getTriple().isOSOpenBSD()) {


Index: clang/test/Driver/zos-profiling-error.c
===
--- clang/test/Driver/zos-profiling-error.c
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck -check-prefix=FAIL-PG-NAME %s
-// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
Index: clang/test/Driver/unused.c
===
--- /dev/null
+++ clang/test/Driver/unused.c
@@ -0,0 +1,8 @@
+// Check that -p is still used when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
+
Index: clang/test/Driver/ibm-profiling.c
===
--- /dev/null
+++ clang/test/Driver/ibm-profiling.c
@@ -0,0 +1,10 @@
+// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck -check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
+
+// Check that -p is still used when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6324,7 +6324,7 @@
 << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+  if (Arg *A = Args.getLastArg(options::OPT_p)) {
 if (TC.getTriple().isOSAIX()) {
   CmdArgs.push_back("-pg");
 } else if (!TC.getTriple().isOSOpenBSD()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145021: [Clang][AIX][p] Claim -p in front end

2023-03-01 Thread Michael Francis via Phabricator via cfe-commits
francii updated this revision to Diff 501529.
francii added a comment.

Remove old test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145021

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ibm-profiling.c
  clang/test/Driver/unused.c
  clang/test/Driver/zos-profiling-error.c


Index: clang/test/Driver/zos-profiling-error.c
===
--- clang/test/Driver/zos-profiling-error.c
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck 
-check-prefix=FAIL-PG-NAME %s
-// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
Index: clang/test/Driver/unused.c
===
--- /dev/null
+++ clang/test/Driver/unused.c
@@ -0,0 +1,8 @@
+// Check that -p is still used when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
+
Index: clang/test/Driver/ibm-profiling.c
===
--- /dev/null
+++ clang/test/Driver/ibm-profiling.c
@@ -0,0 +1,10 @@
+// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck 
-check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
+
+// Check that -p is still used when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6324,7 +6324,7 @@
 << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+  if (Arg *A = Args.getLastArg(options::OPT_p)) {
 if (TC.getTriple().isOSAIX()) {
   CmdArgs.push_back("-pg");
 } else if (!TC.getTriple().isOSOpenBSD()) {


Index: clang/test/Driver/zos-profiling-error.c
===
--- clang/test/Driver/zos-profiling-error.c
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck -check-prefix=FAIL-PG-NAME %s
-// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
Index: clang/test/Driver/unused.c
===
--- /dev/null
+++ clang/test/Driver/unused.c
@@ -0,0 +1,8 @@
+// Check that -p is still used when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
+
Index: clang/test/Driver/ibm-profiling.c
===
--- /dev/null
+++ clang/test/Driver/ibm-profiling.c
@@ -0,0 +1,10 @@
+// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck -check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
+
+// Check that -p is still used when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6324,7 +6324,7 @@
 << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+  if (Arg *A = Args.getLastArg(options::OPT_p)) {
 if (TC.getTriple().isOSAIX()) {
   CmdArgs.push_back("-pg");
 } else if (!TC.getTriple().isOSOpenBSD()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145021: [Clang][AIX][p] Claim -p in front end

2023-03-01 Thread Michael Francis via Phabricator via cfe-commits
francii updated this revision to Diff 501530.
francii added a comment.

Remove old test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145021

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ibm-profiling.c
  clang/test/Driver/zos-profiling-error.c


Index: clang/test/Driver/zos-profiling-error.c
===
--- clang/test/Driver/zos-profiling-error.c
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck 
-check-prefix=FAIL-PG-NAME %s
-// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
Index: clang/test/Driver/ibm-profiling.c
===
--- /dev/null
+++ clang/test/Driver/ibm-profiling.c
@@ -0,0 +1,10 @@
+// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck 
-check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
+
+// Check that -p is still used when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6324,7 +6324,7 @@
 << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+  if (Arg *A = Args.getLastArg(options::OPT_p)) {
 if (TC.getTriple().isOSAIX()) {
   CmdArgs.push_back("-pg");
 } else if (!TC.getTriple().isOSOpenBSD()) {


Index: clang/test/Driver/zos-profiling-error.c
===
--- clang/test/Driver/zos-profiling-error.c
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck -check-prefix=FAIL-PG-NAME %s
-// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
Index: clang/test/Driver/ibm-profiling.c
===
--- /dev/null
+++ clang/test/Driver/ibm-profiling.c
@@ -0,0 +1,10 @@
+// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck -check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
+
+// Check that -p is still used when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6324,7 +6324,7 @@
 << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+  if (Arg *A = Args.getLastArg(options::OPT_p)) {
 if (TC.getTriple().isOSAIX()) {
   CmdArgs.push_back("-pg");
 } else if (!TC.getTriple().isOSOpenBSD()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145074: [clang][RISCV] Fix ABI lowering for _Float16 for FP ABIs

2023-03-01 Thread Alex Bradbury via Phabricator via cfe-commits
asb created this revision.
asb added reviewers: kito-cheng, jrtc27, reames, craig.topper.
Herald added subscribers: luke, wingo, pmatos, VincentWu, vkmr, frasercrmck, 
evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, 
jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, 
zzheng, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added a project: All.
asb requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added a project: clang.

For trivial cases (`_Float16` as a standalone argument), it was previously 
correctly lowered to `half`. But the logic for catching cases involving structs 
was gated off, as at the time that logic was written the ABI for half was 
unclear.

This patch fixes that and adds a release note.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145074

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/RISCV/riscv32-abi.c
  clang/test/CodeGen/RISCV/riscv64-abi.c

Index: clang/test/CodeGen/RISCV/riscv64-abi.c
===
--- clang/test/CodeGen/RISCV/riscv64-abi.c
+++ clang/test/CodeGen/RISCV/riscv64-abi.c
@@ -1492,24 +1492,29 @@
 // separate arguments in IR. They are passed by the same rules for returns,
 // but will be lowered to simple two-element structs if necessary (as LLVM IR
 // functions cannot return multiple values).
-// FIXME: Essentially all test cases below involving _Float16 in structs
-// aren't lowered according to the rules in the FP calling convention (i.e.
-// are incorrect for lp64f/lp64d).
 
 struct float16_s { _Float16 f; };
 
 // A struct containing just one floating-point real is passed as though it
 // were a standalone floating-point real.
 
-// LP64-LP64F-LP64D-LABEL: define dso_local void @f_float16_s_arg
-// LP64-LP64F-LP64D-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] {
-// LP64-LP64F-LP64D:  entry:
+// LP64-LABEL: define dso_local void @f_float16_s_arg
+// LP64-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] {
+// LP64:  entry:
+//
+// LP64F-LP64D-LABEL: define dso_local void @f_float16_s_arg
+// LP64F-LP64D-SAME: (half [[TMP0:%.*]]) #[[ATTR0]] {
+// LP64F-LP64D:  entry:
 //
 void f_float16_s_arg(struct float16_s a) {}
 
-// LP64-LP64F-LP64D-LABEL: define dso_local i64 @f_ret_float16_s
-// LP64-LP64F-LP64D-SAME: () #[[ATTR0]] {
-// LP64-LP64F-LP64D:  entry:
+// LP64-LABEL: define dso_local i64 @f_ret_float16_s
+// LP64-SAME: () #[[ATTR0]] {
+// LP64:  entry:
+//
+// LP64F-LP64D-LABEL: define dso_local half @f_ret_float16_s
+// LP64F-LP64D-SAME: () #[[ATTR0]] {
+// LP64F-LP64D:  entry:
 //
 struct float16_s f_ret_float16_s(void) {
   return (struct float16_s){1.0};
@@ -1521,29 +1526,45 @@
 struct zbf_float16_s { int : 0; _Float16 f; };
 struct zbf_float16_zbf_s { int : 0; _Float16 f; int : 0; };
 
-// LP64-LP64F-LP64D-LABEL: define dso_local void @f_zbf_float16_s_arg
-// LP64-LP64F-LP64D-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] {
-// LP64-LP64F-LP64D:  entry:
+// LP64-LABEL: define dso_local void @f_zbf_float16_s_arg
+// LP64-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] {
+// LP64:  entry:
+//
+// LP64F-LP64D-LABEL: define dso_local void @f_zbf_float16_s_arg
+// LP64F-LP64D-SAME: (half [[TMP0:%.*]]) #[[ATTR0]] {
+// LP64F-LP64D:  entry:
 //
 void f_zbf_float16_s_arg(struct zbf_float16_s a) {}
 
-// LP64-LP64F-LP64D-LABEL: define dso_local i64 @f_ret_zbf_float16_s
-// LP64-LP64F-LP64D-SAME: () #[[ATTR0]] {
-// LP64-LP64F-LP64D:  entry:
+// LP64-LABEL: define dso_local i64 @f_ret_zbf_float16_s
+// LP64-SAME: () #[[ATTR0]] {
+// LP64:  entry:
+//
+// LP64F-LP64D-LABEL: define dso_local half @f_ret_zbf_float16_s
+// LP64F-LP64D-SAME: () #[[ATTR0]] {
+// LP64F-LP64D:  entry:
 //
 struct zbf_float16_s f_ret_zbf_float16_s(void) {
   return (struct zbf_float16_s){1.0};
 }
 
-// LP64-LP64F-LP64D-LABEL: define dso_local void @f_zbf_float16_zbf_s_arg
-// LP64-LP64F-LP64D-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] {
-// LP64-LP64F-LP64D:  entry:
+// LP64-LABEL: define dso_local void @f_zbf_float16_zbf_s_arg
+// LP64-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] {
+// LP64:  entry:
+//
+// LP64F-LP64D-LABEL: define dso_local void @f_zbf_float16_zbf_s_arg
+// LP64F-LP64D-SAME: (half [[TMP0:%.*]]) #[[ATTR0]] {
+// LP64F-LP64D:  entry:
 //
 void f_zbf_float16_zbf_s_arg(struct zbf_float16_zbf_s a) {}
 
-// LP64-LP64F-LP64D-LABEL: define dso_local i64 @f_ret_zbf_float16_zbf_s
-// LP64-LP64F-LP64D-SAME: () #[[ATTR0]] {
-// LP64-LP64F-LP64D:  entry:
+// LP64-LABEL: define dso_local i64 @f_ret_zbf_float16_zbf_s
+// LP64-SAME: () #[[ATTR0]] {
+// LP64:  entry:
+//
+// LP64F-LP64D-LABEL: define dso_local half @f_ret_zbf_float16_zbf_s
+// LP64F-LP64D-SAME: () #[[ATTR0]] {
+// LP64F-LP64D:  entry:
 //
 struct zbf_float16_zbf_s f_ret_zbf_float16_zbf_s(void) {
   return (struct zbf_float16_zbf_s){1.0};
@@ -1554,15 +1575,23 @@
 
 struct double_float16_s { double f; _Float16 g; };
 
-/

[PATCH] D145021: [Clang][AIX][p] Claim -p in front end

2023-03-01 Thread Michael Francis via Phabricator via cfe-commits
francii updated this revision to Diff 501531.
francii added a comment.

Add test case descriptions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145021

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ibm-profiling.c
  clang/test/Driver/zos-profiling-error.c


Index: clang/test/Driver/zos-profiling-error.c
===
--- clang/test/Driver/zos-profiling-error.c
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck 
-check-prefix=FAIL-PG-NAME %s
-// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
Index: clang/test/Driver/ibm-profiling.c
===
--- /dev/null
+++ clang/test/Driver/ibm-profiling.c
@@ -0,0 +1,11 @@
+// Check that g-profiling is disabled on z/OS.
+// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck 
-check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
+
+// Check that -p does not claim to be unused when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6324,7 +6324,7 @@
 << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+  if (Arg *A = Args.getLastArg(options::OPT_p)) {
 if (TC.getTriple().isOSAIX()) {
   CmdArgs.push_back("-pg");
 } else if (!TC.getTriple().isOSOpenBSD()) {


Index: clang/test/Driver/zos-profiling-error.c
===
--- clang/test/Driver/zos-profiling-error.c
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck -check-prefix=FAIL-PG-NAME %s
-// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
Index: clang/test/Driver/ibm-profiling.c
===
--- /dev/null
+++ clang/test/Driver/ibm-profiling.c
@@ -0,0 +1,11 @@
+// Check that g-profiling is disabled on z/OS.
+// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck -check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
+
+// Check that -p does not claim to be unused when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6324,7 +6324,7 @@
 << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+  if (Arg *A = Args.getLastArg(options::OPT_p)) {
 if (TC.getTriple().isOSAIX()) {
   CmdArgs.push_back("-pg");
 } else if (!TC.getTriple().isOSOpenBSD()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145021: [Clang][AIX][p] Claim -p in front end

2023-03-01 Thread Michael Francis via Phabricator via cfe-commits
francii updated this revision to Diff 501533.
francii added a comment.

nit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145021

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ibm-profiling.c
  clang/test/Driver/zos-profiling-error.c


Index: clang/test/Driver/zos-profiling-error.c
===
--- clang/test/Driver/zos-profiling-error.c
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck 
-check-prefix=FAIL-PG-NAME %s
-// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
Index: clang/test/Driver/ibm-profiling.c
===
--- /dev/null
+++ clang/test/Driver/ibm-profiling.c
@@ -0,0 +1,11 @@
+// Check that -pg is disabled on z/OS.
+// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck 
-check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
+
+// Check that -p does not claim to be unused when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6324,7 +6324,7 @@
 << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+  if (Arg *A = Args.getLastArg(options::OPT_p)) {
 if (TC.getTriple().isOSAIX()) {
   CmdArgs.push_back("-pg");
 } else if (!TC.getTriple().isOSOpenBSD()) {


Index: clang/test/Driver/zos-profiling-error.c
===
--- clang/test/Driver/zos-profiling-error.c
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck -check-prefix=FAIL-PG-NAME %s
-// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
Index: clang/test/Driver/ibm-profiling.c
===
--- /dev/null
+++ clang/test/Driver/ibm-profiling.c
@@ -0,0 +1,11 @@
+// Check that -pg is disabled on z/OS.
+// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck -check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
+
+// Check that -p does not claim to be unused when not linking on AIX.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-p \
+// RUN:-S \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6324,7 +6324,7 @@
 << A->getAsString(Args) << TripleStr;
 }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+  if (Arg *A = Args.getLastArg(options::OPT_p)) {
 if (TC.getTriple().isOSAIX()) {
   CmdArgs.push_back("-pg");
 } else if (!TC.getTriple().isOSOpenBSD()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145075: [clangd] Show used symbol on include hover.

2023-03-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145075

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h

Index: clang-tools-extra/clangd/Hover.h
===
--- clang-tools-extra/clangd/Hover.h
+++ clang-tools-extra/clangd/Hover.h
@@ -18,6 +18,14 @@
 namespace clang {
 namespace clangd {
 
+struct UsedSymbol {
+  std::string Name;
+  Position Pos;
+};
+inline bool operator<(const UsedSymbol &FstSym, const UsedSymbol &SndSym) {
+  return FstSym.Name < SndSym.Name;
+}
+
 /// Contains detailed information about a Symbol. Especially useful when
 /// generating hover responses. It can be rendered as a hover panel, or
 /// embedding clients can use the structured information to provide their own
@@ -96,6 +104,8 @@
   // Set when symbol is inside function call. Contains information extracted
   // from the callee definition about the argument this is passed as.
   std::optional CalleeArgInfo;
+
+  std::optional> UsedSymbols;
   struct PassType {
 // How the variable is passed to callee.
 enum PassMode { Ref, ConstRef, Value };
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -13,8 +13,10 @@
 #include "Config.h"
 #include "FindTarget.h"
 #include "ParsedAST.h"
+#include "Protocol.h"
 #include "Selection.h"
 #include "SourceCode.h"
+#include "clang-include-cleaner/Analysis.h"
 #include "index/SymbolCollector.h"
 #include "support/Markup.h"
 #include "clang/AST/ASTContext.h"
@@ -1084,6 +1086,81 @@
   return Candidates.front();
 }
 
+// FIXME(bakalova): Remove after merging https://reviews.llvm.org/D143496
+std::vector
+collectMacroReferences(ParsedAST &AST) {
+  const auto &SM = AST.getSourceManager();
+  //  FIXME: !!this is a hacky way to collect macro references.
+  std::vector Macros;
+  auto &PP = AST.getPreprocessor();
+  for (const syntax::Token &Tok :
+   AST.getTokens().spelledTokens(SM.getMainFileID())) {
+auto Macro = locateMacroAt(Tok, PP);
+if (!Macro)
+  continue;
+if (auto DefLoc = Macro->Info->getDefinitionLoc(); DefLoc.isValid())
+  Macros.push_back(
+  {Tok.location(),
+   include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok.text(SM)),
+  DefLoc},
+   include_cleaner::RefType::Explicit});
+  }
+  return Macros;
+}
+
+void addUsedSymbols(const Inclusion &Inc, ParsedAST &AST,
+const std::vector &Macros,
+HoverInfo &HI) {
+  const SourceManager &SM = AST.getSourceManager();
+  std::set UsedSymbols;
+  include_cleaner::walkUsed(
+  AST.getLocalTopLevelDecls(), Macros, AST.getPragmaIncludes(), SM,
+  [&](const include_cleaner::SymbolReference &Ref,
+  llvm::ArrayRef Providers) {
+if (Ref.RT != include_cleaner::RefType::Explicit ||
+ !Ref.RefLocation.isFileID() ||
+!SM.isWrittenInMainFile(SM.getSpellingLoc(Ref.RefLocation)) 
+   ) {
+  return;
+}
+std::string Name;
+switch (Ref.Target.kind()) {
+case include_cleaner::Symbol::Declaration:
+  Name = cast(Ref.Target.declaration())
+ .getDeclName()
+ .getAsString();
+  break;
+case include_cleaner::Symbol::Macro:
+  Name = Ref.Target.macro().Name->getName();
+  break;
+}
+
+Position Pos = sourceLocToPosition(SM, Ref.RefLocation);
+for (const include_cleaner::Header &H : Providers) {
+  switch (H.kind()) {
+  case include_cleaner::Header::Physical:
+if (H.physical()->tryGetRealPathName() == Inc.Resolved) {
+  UsedSymbols.insert({Name, Pos});
+}
+break;
+  case include_cleaner::Header::Standard:
+if (Inc.Written == H.standard().name()) {
+  UsedSymbols.insert({Name, Pos});
+}
+break;
+  case include_cleaner::Header::Verbatim:
+if (Inc.Written == H.verbatim()) {
+  UsedSymbols.insert({Name, Pos});
+}
+break;
+  }
+}
+  });
+
+  if (!UsedSymbols.empty()) {
+HI.UsedSymbols = std::optional>{std::move(UsedSymbols)};
+  }
+}
 } // namespace
 
 std::optional getHover(ParsedAST &AST, Position Pos,
@@ -1103,6 +1180,7 @@
   if (TokensTouchingCursor.empty())
 return std::nullopt;
 
+  const auto &Macros = collectMacroReferences(AST);
   // Show full header file path if cursor is on include directive.
   for (const auto &Inc : AST.getIncludeStructure().M

[PATCH] D140794: [ASTMatcher] Add coroutineBodyStmt matcher

2023-03-01 Thread Aaron Ballman 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 rGdcf5ad89dcc5: [ASTMatcher] Add coroutineBodyStmt matcher 
(authored by ccotter, committed by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140794

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp

Index: clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -364,7 +364,8 @@
 "to build matcher: mapAnyOf.",
 ParseWithError("mapAnyOf(\"foo\")"));
   EXPECT_EQ("Input value has unresolved overloaded type: "
-"Matcher",
+"Matcher",
 ParseMatcherWithError("hasBody(stmt())"));
   EXPECT_EQ(
   "1:1: Error parsing argument 1 for matcher decl.\n"
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -678,6 +678,48 @@
   EXPECT_TRUE(matchesConditionally(CoYieldCode, 
coyieldExpr(isExpansionInMainFile()), 
true, {"-std=c++20", "-I/"}, M));
+
+  StringRef NonCoroCode = R"cpp(
+#include 
+void non_coro_function() {
+}
+)cpp";
+
+  EXPECT_TRUE(matchesConditionally(CoReturnCode, coroutineBodyStmt(), true,
+   {"-std=c++20", "-I/"}, M));
+  EXPECT_TRUE(matchesConditionally(CoAwaitCode, coroutineBodyStmt(), true,
+   {"-std=c++20", "-I/"}, M));
+  EXPECT_TRUE(matchesConditionally(CoYieldCode, coroutineBodyStmt(), true,
+   {"-std=c++20", "-I/"}, M));
+
+  EXPECT_FALSE(matchesConditionally(NonCoroCode, coroutineBodyStmt(), true,
+{"-std=c++20", "-I/"}, M));
+
+  StringRef CoroWithDeclCode = R"cpp(
+#include 
+void coro() {
+  int thevar;
+  co_return 1;
+}
+)cpp";
+  EXPECT_TRUE(matchesConditionally(
+  CoroWithDeclCode,
+  coroutineBodyStmt(hasBody(compoundStmt(
+  has(declStmt(containsDeclaration(0, varDecl(hasName("thevar",
+  true, {"-std=c++20", "-I/"}, M));
+
+  StringRef CoroWithTryCatchDeclCode = R"cpp(
+#include 
+void coro() try {
+  int thevar;
+  co_return 1;
+} catch (...) {}
+)cpp";
+  EXPECT_TRUE(matchesConditionally(
+  CoroWithTryCatchDeclCode,
+  coroutineBodyStmt(hasBody(cxxTryStmt(has(compoundStmt(has(
+  declStmt(containsDeclaration(0, varDecl(hasName("thevar")),
+  true, {"-std=c++20", "-I/"}, M));
 }
 
 TEST(Matcher, isClassMessage) {
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -175,6 +175,7 @@
   REGISTER_MATCHER(containsDeclaration);
   REGISTER_MATCHER(continueStmt);
   REGISTER_MATCHER(coreturnStmt);
+  REGISTER_MATCHER(coroutineBodyStmt);
   REGISTER_MATCHER(coyieldExpr);
   REGISTER_MATCHER(cudaKernelCallExpr);
   REGISTER_MATCHER(cxxBaseSpecifier);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -910,6 +910,8 @@
 const internal::VariadicDynCastAllOfMatcher caseStmt;
 const internal::VariadicDynCastAllOfMatcher defaultStmt;
 const internal::VariadicDynCastAllOfMatcher compoundStmt;
+const internal::VariadicDynCastAllOfMatcher
+coroutineBodyStmt;
 const internal::VariadicDynCastAllOfMatcher cxxCatchStmt;
 const internal::VariadicDynCastAllOfMatcher cxxTryStmt;
 const internal::VariadicDynCastAllOfMatcher cxxThrowExpr;
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2450,6 +2450,17 @@
 extern const internal::VariadicDynCastAllOfMatcher
 coyieldExpr;
 
+/// Matches coroutine body statements.
+///
+/// coroutineBodyStmt() matches the coroutine below
+/// \code
+///   generator gen() {
+/// co_return;
+///   }
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher
+coroutineBodyStmt;
+
 /// Matches nullptr literal.
 extern const internal::VariadicDynCastAllOfMatcher
 cxxNullPtrLiter

[clang] dcf5ad8 - [ASTMatcher] Add coroutineBodyStmt matcher

2023-03-01 Thread Aaron Ballman via cfe-commits

Author: Chris Cotter
Date: 2023-03-01T11:51:46-05:00
New Revision: dcf5ad89dcc5cc69b9df3e5dd9be71c65642f519

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

LOG: [ASTMatcher] Add coroutineBodyStmt matcher

The coroutineBodyStmt matcher matches CoroutineBodyStmt AST nodes.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d609f365bbcb5..ce37020aa86fb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -258,6 +258,11 @@ Floating Point Support in Clang
 AST Matchers
 
 
+- Add ``coroutineBodyStmt`` matcher.
+
+- The ``hasBody`` matcher now matches coroutine body nodes in
+  ``CoroutineBodyStmts``.
+
 clang-format
 
 

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 98b727e6940b5..7a69f86844671 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2450,6 +2450,17 @@ extern const internal::VariadicDynCastAllOfMatcher
 extern const internal::VariadicDynCastAllOfMatcher
 coyieldExpr;
 
+/// Matches coroutine body statements.
+///
+/// coroutineBodyStmt() matches the coroutine below
+/// \code
+///   generator gen() {
+/// co_return;
+///   }
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher
+coroutineBodyStmt;
+
 /// Matches nullptr literal.
 extern const internal::VariadicDynCastAllOfMatcher
 cxxNullPtrLiteralExpr;
@@ -5460,9 +5471,10 @@ AST_MATCHER_P(ArraySubscriptExpr, hasBase,
   return false;
 }
 
-/// Matches a 'for', 'while', 'do' statement or a function definition that has
-/// a given body. Note that in case of functions this matcher only matches the
-/// definition itself and not the other declarations of the same function.
+/// Matches a 'for', 'while', 'while' statement or a function or coroutine
+/// definition that has a given body. Note that in case of functions or
+/// coroutines this matcher only matches the definition itself and not the
+/// other declarations of the same function or coroutine.
 ///
 /// Given
 /// \code
@@ -5483,12 +5495,11 @@ AST_MATCHER_P(ArraySubscriptExpr, hasBase,
 /// with compoundStmt()
 ///   matching '{}'
 ///   but does not match 'void f();'
-AST_POLYMORPHIC_MATCHER_P(hasBody,
-  AST_POLYMORPHIC_SUPPORTED_TYPES(DoStmt, ForStmt,
-  WhileStmt,
-  CXXForRangeStmt,
-  FunctionDecl),
-  internal::Matcher, InnerMatcher) {
+AST_POLYMORPHIC_MATCHER_P(
+hasBody,
+AST_POLYMORPHIC_SUPPORTED_TYPES(DoStmt, ForStmt, WhileStmt, 
CXXForRangeStmt,
+FunctionDecl, CoroutineBodyStmt),
+internal::Matcher, InnerMatcher) {
   if (Finder->isTraversalIgnoringImplicitNodes() && isDefaultedHelper(&Node))
 return false;
   const Stmt *const Statement = internal::GetBodyMatcher::get(Node);

diff  --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index f1f73fc42075d..26e40c4ed36a5 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -910,6 +910,8 @@ const internal::VariadicDynCastAllOfMatcher switchCase;
 const internal::VariadicDynCastAllOfMatcher caseStmt;
 const internal::VariadicDynCastAllOfMatcher defaultStmt;
 const internal::VariadicDynCastAllOfMatcher compoundStmt;
+const internal::VariadicDynCastAllOfMatcher
+coroutineBodyStmt;
 const internal::VariadicDynCastAllOfMatcher cxxCatchStmt;
 const internal::VariadicDynCastAllOfMatcher cxxTryStmt;
 const internal::VariadicDynCastAllOfMatcher cxxThrowExpr;

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 0d436fa29a791..9bbb291df0639 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -175,6 +175,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(containsDeclaration);
   REGISTER_MATCHER(continueStmt);
   REGISTER_MATCHER(coreturnStmt);
+  REGISTER_MATCHER(coroutineBodyStmt);
   REGISTER_MATCHER(coyieldExpr);
   REGISTER_MATCHER(cudaKernelCallExpr);
   REGISTER_MATCHER(cxxBaseSpecifier);

diff  --git a/clang

[PATCH] D140794: [ASTMatcher] Add coroutineBodyStmt matcher

2023-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D140794#4160358 , @ccotter wrote:

> Thanks both! Assuming this passes build, would one of you mind committing 
> this for me? `Chris Cotter `

Happy to do so! I've landed it on your behalf in 
dcf5ad89dcc5cc69b9df3e5dd9be71c65642f519 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140794

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


[clang] 969ab71 - [clang] drop buggy use of `-serialize-diagnostics` flag

2023-03-01 Thread Ashay Rane via cfe-commits

Author: Ashay Rane
Date: 2023-03-01T10:53:39-06:00
New Revision: 969ab7134f4df52a5887a49006c703515163ee22

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

LOG: [clang] drop buggy use of `-serialize-diagnostics` flag

The `-serialize-diagnostics` flag requires a filename to be passed
immediately after it, but the filename argument was skipped in the
P1689.cppm clang test.  This caused the code to incorrectly consume the
argument that followed as the dignostics file.

Since the `-serialize-diagnostics` flag isn't needed for this test to
work, this patch removes it instead of passing a file argument.

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

Added: 


Modified: 
clang/test/ClangScanDeps/P1689.cppm

Removed: 




diff  --git a/clang/test/ClangScanDeps/P1689.cppm 
b/clang/test/ClangScanDeps/P1689.cppm
index bbe9cc3b2d332..dffb16974a3e4 100644
--- a/clang/test/ClangScanDeps/P1689.cppm
+++ b/clang/test/ClangScanDeps/P1689.cppm
@@ -40,7 +40,7 @@
 //
 // Check that we can mix the use of -format=p1689 and -fmodules.
 // RUN: clang-scan-deps -format=p1689 \
-// RUN:   -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache -serialize-diagnostics -c %t/impl_part.cppm -o 
%t/impl_part.o \
+// RUN:   -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache -c %t/impl_part.cppm -o %t/impl_part.o \
 // RUN:   | FileCheck %t/impl_part.cppm -DPREFIX=%/t
 
 //--- P1689.json.in



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


[PATCH] D144934: [clang] drop buggy use of `-serialize-diagnostics` flag

2023-03-01 Thread Ashay Rane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG969ab7134f4d: [clang] drop buggy use of 
`-serialize-diagnostics` flag (authored by ashay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144934

Files:
  clang/test/ClangScanDeps/P1689.cppm


Index: clang/test/ClangScanDeps/P1689.cppm
===
--- clang/test/ClangScanDeps/P1689.cppm
+++ clang/test/ClangScanDeps/P1689.cppm
@@ -40,7 +40,7 @@
 //
 // Check that we can mix the use of -format=p1689 and -fmodules.
 // RUN: clang-scan-deps -format=p1689 \
-// RUN:   -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache -serialize-diagnostics -c %t/impl_part.cppm -o 
%t/impl_part.o \
+// RUN:   -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache -c %t/impl_part.cppm -o %t/impl_part.o \
 // RUN:   | FileCheck %t/impl_part.cppm -DPREFIX=%/t
 
 //--- P1689.json.in


Index: clang/test/ClangScanDeps/P1689.cppm
===
--- clang/test/ClangScanDeps/P1689.cppm
+++ clang/test/ClangScanDeps/P1689.cppm
@@ -40,7 +40,7 @@
 //
 // Check that we can mix the use of -format=p1689 and -fmodules.
 // RUN: clang-scan-deps -format=p1689 \
-// RUN:   -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -serialize-diagnostics -c %t/impl_part.cppm -o %t/impl_part.o \
+// RUN:   -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -c %t/impl_part.cppm -o %t/impl_part.o \
 // RUN:   | FileCheck %t/impl_part.cppm -DPREFIX=%/t
 
 //--- P1689.json.in
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145077: [clang][DebugInfo] Support DW_AT_LLVM_preferred_name attribute

2023-03-01 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, dblaikie.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

With this patch, we now emit a `DW_AT_LLVM_preferred_name` for
the `[clang::preferred_name]]` attribute attached to a class template.

This is useful for consumers in case they want to display the
name in terms of the preferred name, e.g., LLDB's type-summaries.

For now this is behind an LLDB tuning.

E.g., for following code:

  template struct Foo;
  
  typedef Foo BarInt;
  typedef Foo BarDouble;
  
  template
  struct [[clang::preferred_name(BarInt),
   clang::preferred_name(BarDouble)]] Foo {};

...the generated DWARF with this patch looks as follows:

  0x006b:   DW_TAG_structure_type
  DW_AT_LLVM_preferred_name   (0x0082)
  DW_AT_name  ("Foo")
  
  0x0082:   DW_TAG_typedef
 DW_AT_type  (0x006b "Foo")
 DW_AT_name  ("BarInt")
  
  0x008d:   DW_TAG_structure_type
  DW_AT_LLVM_preferred_name   (0x00ab)
  DW_AT_name  ("Foo")
  
  0x00ab:   DW_TAG_typedef
  DW_AT_type  (0x008d "Foo")
  DW_AT_name  ("BarDouble")


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145077

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/attr-preferred_name-alias-template.cpp
  clang/test/CodeGen/attr-preferred_name-typedef.cpp

Index: clang/test/CodeGen/attr-preferred_name-typedef.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-typedef.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template
+struct Foo;
+
+typedef Foo BarInt;
+typedef Foo BarDouble;
+
+template
+struct [[clang::preferred_name(BarInt),
+ clang::preferred_name(BarDouble)]] Foo {};
+
+Foo varInt;
+Foo varDouble;
+
+// LLDB:  ![[FOO_DOUBLE:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarDouble",
+// LLDB-SAME: baseType: ![[FOO_DOUBLE]])
+
+// LLDB:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarInt",
+// LLDB-SAME: baseType: ![[FOO_INT]])
Index: clang/test/CodeGen/attr-preferred_name-alias-template.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-alias-template.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template
+struct Foo;
+
+template
+using Bar = Foo;
+
+template
+struct [[clang::preferred_name(Bar)]] Foo {};
+
+Foo varInt;
+
+// LLDB:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "Bar",
+// LLDB-SAME: baseType: ![[FOO_INT]])
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -267,6 +267,11 @@
SmallVectorImpl &EltTys,
llvm::DIType *RecordTy);
 
+  /// Helper class that retrieves returns llvm::DIType the that
+  /// PreferredNameAttr attribute on \ref RD refers to. If no such
+  /// attribute exists, returns nullptr.
+  llvm::DIType * GetPreferredNameType(const CXXRecordDecl *RD, llvm::DIFile *Unit);
+
   /// Helper function for CollectCXXBases.
   /// Adds debug info entries for types in Bases that are not in SeenTypes.
   void CollectCXXBasesAux(
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1301,6 +1301,8 @@
   llvm::raw_svector_ostream OS(NS);
 
   auto PP = getPrintingPolicy();
+  // TODO: Not strictly needed for std::string?
+  PP.UsePreferredNames = CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB;
   Ty->getTemplateName().print(OS, PP, TemplateName::Qualified::None);
 
   // Disable PrintCanonicalTypes here because we want
@@ -2

[PATCH] D144622: [clang][ASTImporter] Import TemplateName correctly

2023-03-01 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 501539.
balazske added a comment.

Updated the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144622

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8137,6 +8137,66 @@
   EXPECT_FALSE(SharedStatePtr->isNewDecl(ToBar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportCorrectTemplateName) {
+  constexpr auto TestCode = R"(
+  template 
+  struct A;
+  template 
+  struct A {};
+  template  class T = A>
+  struct B {};
+  using C = B<>;
+  )";
+  Decl *ToTU = getToTuDecl(TestCode, Lang_CXX11);
+  Decl *FromTU = getTuDecl(TestCode, Lang_CXX11);
+
+  auto *ToUsingFirst = FirstDeclMatcher().match(
+  ToTU, typeAliasDecl(hasName("C")));
+
+  auto *FromUsing = FirstDeclMatcher().match(
+  FromTU, typeAliasDecl(hasName("C")));
+  auto *ToUsing = Import(FromUsing, Lang_CXX11);
+  EXPECT_TRUE(ToUsing);
+
+  auto *ToB = FirstDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("B")));
+  auto *ToB1 = LastDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("B")));
+  // One template definition of 'B' should exist.
+  EXPECT_EQ(ToB, ToB1);
+
+  // These declarations are imported separately.
+  EXPECT_NE(ToUsingFirst, ToUsing);
+
+  auto SpB = ToB->spec_begin();
+  auto SpE = ToB->spec_end();
+  EXPECT_TRUE(SpB != SpE);
+  ClassTemplateSpecializationDecl *Spec1 = *SpB;
+  ++SpB;
+  // The template 'B' should have one specialization (with default argument).
+  EXPECT_TRUE(SpB == SpE);
+
+  // Even if 'B' has one specialization with the default arguments, the AST
+  // contains after the import two specializations that are linked in the
+  // declaration chain. The 'spec_begin' iteration does not find these because
+  // the template arguments are the same. But the imported type alias has the
+  // link to the second specialization. The template name object in these
+  // specializations must point to the same (and one) instance of definition of
+  // 'B'.
+  auto *Spec2 = cast(
+  ToUsing->getUnderlyingType()
+  ->getAs()
+  ->getAsRecordDecl());
+  EXPECT_NE(Spec1, Spec2);
+  EXPECT_TRUE(Spec1->getPreviousDecl() == Spec2 ||
+  Spec2->getPreviousDecl() == Spec1);
+  TemplateDecl *Templ1 =
+  Spec1->getTemplateArgs()[0].getAsTemplate().getAsTemplateDecl();
+  TemplateDecl *Templ2 =
+  Spec2->getTemplateArgs()[0].getAsTemplate().getAsTemplateDecl();
+  EXPECT_EQ(Templ1, Templ2);
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -9376,7 +9376,7 @@
   switch (From.getKind()) {
   case TemplateName::Template:
 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
-  return TemplateName(cast(*ToTemplateOrErr));
+  return 
TemplateName(cast((*ToTemplateOrErr)->getCanonicalDecl()));
 else
   return ToTemplateOrErr.takeError();
 


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8137,6 +8137,66 @@
   EXPECT_FALSE(SharedStatePtr->isNewDecl(ToBar));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportCorrectTemplateName) {
+  constexpr auto TestCode = R"(
+  template 
+  struct A;
+  template 
+  struct A {};
+  template  class T = A>
+  struct B {};
+  using C = B<>;
+  )";
+  Decl *ToTU = getToTuDecl(TestCode, Lang_CXX11);
+  Decl *FromTU = getTuDecl(TestCode, Lang_CXX11);
+
+  auto *ToUsingFirst = FirstDeclMatcher().match(
+  ToTU, typeAliasDecl(hasName("C")));
+
+  auto *FromUsing = FirstDeclMatcher().match(
+  FromTU, typeAliasDecl(hasName("C")));
+  auto *ToUsing = Import(FromUsing, Lang_CXX11);
+  EXPECT_TRUE(ToUsing);
+
+  auto *ToB = FirstDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("B")));
+  auto *ToB1 = LastDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("B")));
+  // One template definition of 'B' should exist.
+  EXPECT_EQ(ToB, ToB1);
+
+  // These declarations are imported separately.
+  EXPECT_NE(ToUsingFirst, ToUsing);
+
+  auto SpB = ToB->spec_begin();
+  auto SpE = ToB->spec_end();
+  EXPECT_TRUE(SpB != SpE);
+  ClassTemplateSpecializationDecl *Spec1 = *SpB;
+  ++SpB;
+  // The template 'B' should have one specialization (with default argument).
+  EXPECT_TRUE(SpB == SpE);
+
+  // Even if 'B' has one specialization with the defa

[PATCH] D145021: [Clang][AIX][p] Claim -p in front end

2023-03-01 Thread David Tenty via Phabricator via cfe-commits
daltenty accepted this revision.
daltenty added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145021

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


[PATCH] D145077: [clang][DebugInfo] Support DW_AT_LLVM_preferred_name attribute

2023-03-01 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 501540.
Michael137 added a comment.

- Remove redundant TODO


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145077

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/attr-preferred_name-alias-template.cpp
  clang/test/CodeGen/attr-preferred_name-typedef.cpp

Index: clang/test/CodeGen/attr-preferred_name-typedef.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-typedef.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template
+struct Foo;
+
+typedef Foo BarInt;
+typedef Foo BarDouble;
+
+template
+struct [[clang::preferred_name(BarInt),
+ clang::preferred_name(BarDouble)]] Foo {};
+
+Foo varInt;
+Foo varDouble;
+
+// LLDB:  ![[FOO_DOUBLE:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarDouble",
+// LLDB-SAME: baseType: ![[FOO_DOUBLE]])
+
+// LLDB:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarInt",
+// LLDB-SAME: baseType: ![[FOO_INT]])
Index: clang/test/CodeGen/attr-preferred_name-alias-template.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-alias-template.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template
+struct Foo;
+
+template
+using Bar = Foo;
+
+template
+struct [[clang::preferred_name(Bar)]] Foo {};
+
+Foo varInt;
+
+// LLDB:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "Bar",
+// LLDB-SAME: baseType: ![[FOO_INT]])
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -267,6 +267,11 @@
SmallVectorImpl &EltTys,
llvm::DIType *RecordTy);
 
+  /// Helper class that retrieves returns llvm::DIType the that
+  /// PreferredNameAttr attribute on \ref RD refers to. If no such
+  /// attribute exists, returns nullptr.
+  llvm::DIType * GetPreferredNameType(const CXXRecordDecl *RD, llvm::DIFile *Unit);
+
   /// Helper function for CollectCXXBases.
   /// Adds debug info entries for types in Bases that are not in SeenTypes.
   void CollectCXXBasesAux(
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2576,6 +2576,18 @@
   return CreateTypeDefinition(Ty);
 }
 
+llvm::DIType * CGDebugInfo::GetPreferredNameType(
+const CXXRecordDecl *RD, llvm::DIFile *Unit) {
+  if (!RD)
+return nullptr;
+
+  auto const* PNA = RD->getAttr();
+  if (!PNA)
+return nullptr;
+
+  return getOrCreateType(PNA->getTypedefType(), Unit);
+}
+
 llvm::DIType *CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
   RecordDecl *RD = Ty->getDecl();
 
@@ -2630,6 +2642,9 @@
 FwdDecl =
 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
 
+  if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB)
+FwdDecl->replacePreferredName(GetPreferredNameType(CXXDecl, DefUnit));
+
   RegionMap[Ty->getDecl()].reset(FwdDecl);
   return FwdDecl;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145021: [Clang][AIX][p] Claim -p in front end

2023-03-01 Thread David Tenty via Phabricator via cfe-commits
daltenty added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:6327
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+  if (Arg *A = Args.getLastArg(options::OPT_p)) {
 if (TC.getTriple().isOSAIX()) {

Actually, a question here. Does this now result in the arg being claimed even 
if nothing was done it? Since there are case we don't go into the error path.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145021

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


[PATCH] D143233: [Clang][CodeGen] Fix this argument type for certain destructors

2023-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D143233#4160206 , @efriedma wrote:

> Maybe worth cherry-picking to 16 branch?  I think someone will need to rebase 
> onto the branch for that, though; there was merge conflict on the 
> microsoft-abi-eh-cleanups.cpp change.

I wouldn't be opposed to picking this onto 16 given that it's fixing an ABI 
issue, if someone wants to do the work to cherry-pick it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143233

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


[PATCH] D145077: [clang][DebugInfo] Support DW_AT_LLVM_preferred_name attribute

2023-03-01 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 501544.
Michael137 added a comment.

- clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145077

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/attr-preferred_name-alias-template.cpp
  clang/test/CodeGen/attr-preferred_name-typedef.cpp

Index: clang/test/CodeGen/attr-preferred_name-typedef.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-typedef.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template
+struct Foo;
+
+typedef Foo BarInt;
+typedef Foo BarDouble;
+
+template
+struct [[clang::preferred_name(BarInt),
+ clang::preferred_name(BarDouble)]] Foo {};
+
+Foo varInt;
+Foo varDouble;
+
+// LLDB:  ![[FOO_DOUBLE:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarDouble",
+// LLDB-SAME: baseType: ![[FOO_DOUBLE]])
+
+// LLDB:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarInt",
+// LLDB-SAME: baseType: ![[FOO_INT]])
Index: clang/test/CodeGen/attr-preferred_name-alias-template.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-alias-template.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template
+struct Foo;
+
+template
+using Bar = Foo;
+
+template
+struct [[clang::preferred_name(Bar)]] Foo {};
+
+Foo varInt;
+Foo> varFooInt;
+
+// LLDB:  ![[FOO_FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo >"
+// GDB-NOT:   preferredName: ![[FOO_INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[FOO_INT_PREF:[0-9]+]])
+
+// LLDB:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "Bar",
+// LLDB-SAME: baseType: ![[FOO_INT]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "Bar >",
+// LLDB-SAME: baseType: ![[FOO_FOO_INT]])
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -267,6 +267,12 @@
SmallVectorImpl &EltTys,
llvm::DIType *RecordTy);
 
+  /// Helper class that retrieves returns llvm::DIType the that
+  /// PreferredNameAttr attribute on \ref RD refers to. If no such
+  /// attribute exists, returns nullptr.
+  llvm::DIType *GetPreferredNameType(const CXXRecordDecl *RD,
+ llvm::DIFile *Unit);
+
   /// Helper function for CollectCXXBases.
   /// Adds debug info entries for types in Bases that are not in SeenTypes.
   void CollectCXXBasesAux(
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2576,6 +2576,18 @@
   return CreateTypeDefinition(Ty);
 }
 
+llvm::DIType *CGDebugInfo::GetPreferredNameType(const CXXRecordDecl *RD,
+llvm::DIFile *Unit) {
+  if (!RD)
+return nullptr;
+
+  auto const *PNA = RD->getAttr();
+  if (!PNA)
+return nullptr;
+
+  return getOrCreateType(PNA->getTypedefType(), Unit);
+}
+
 llvm::DIType *CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
   RecordDecl *RD = Ty->getDecl();
 
@@ -2630,6 +2642,9 @@
 FwdDecl =
 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
 
+  if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB)
+FwdDecl->replacePreferredName(GetPreferredNameType(CXXDecl, DefUnit));
+
   RegionMap[Ty->getDecl()].reset(FwdDecl);
   return FwdDecl;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145077: [clang][DebugInfo] Support DW_AT_LLVM_preferred_name attribute

2023-03-01 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Since the new attribute only gets attached to a structure definition, and the 
preferred_name attribute is currently only really used in a handful of places 
in libcxx, this practically doesn't affect debug-info size


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145077

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


[PATCH] D144878: __builtin_FILE_NAME()

2023-03-01 Thread Ilya Karapsin via Phabricator via cfe-commits
karapsinie marked an inline comment as done.
karapsinie added a comment.

If all is well, approve and merge the commit.


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

https://reviews.llvm.org/D144878

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


[PATCH] D128648: [Clang][AArch64][SME] Add vector read/write (mova) intrinsics

2023-03-01 Thread Bryan Chan via Phabricator via cfe-commits
bryanpkc added inline comments.



Comment at: clang/include/clang/Basic/arm_sme.td:103
+def NAME # _H : SInst<"svwrite_hor_" # n_suffix # "[_{d}]", "vimiPd", t, 
MergeOp1,
+  "aarch64_sme_write" # !cond(!eq(n_suffix, "za128") : 
"q", true: "") # "_horiz",
+  [IsWrite, IsStreaming, IsSharedZA], ch>;

kmclaughlin wrote:
> This is only a suggestion, but would it make the multiclasses simpler to just 
> pass in either `"q"` or `""` depending on the instruction, and append this to 
> `aarch64_sme_read/write`?
Thanks for the suggestion, but simplifying the definition at the cost of 
complicating the interface does not seem worthwhile. I think the current 
implementation is more self-documenting and clearer about the intent, and 
reduces the cognitive burden for a future reader, to whom the uses of `""` and 
`"q"` may not be obvious.



Comment at: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_read.c:2
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefixes=CHECK,CHECK-CXX

kmclaughlin wrote:
> I think `-target-feature +sve` can be removed from this test and 
> `acle_sme_write.c`
Doing that will cause errors like these:
```
error: SVE vector type 'svbool_t' (aka '__SVBool_t') cannot be used in a target 
without sve
```
As I have explained in [D127910](https://reviews.llvm.org/D127910#4137844), 
`-target-feature +sme` does not imply `-target-feature +sve`. But `-march=` 
processing will work as expected when D142702 lands.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128648

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


[PATCH] D143418: [libclang] Add API to override preamble storage path

2023-03-01 Thread Igor Kushnir via Phabricator via cfe-commits
vedgy updated this revision to Diff 501559.
vedgy added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143418

Files:
  clang-tools-extra/clangd/Preamble.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/include/clang/Frontend/ASTUnit.h
  clang/include/clang/Frontend/PrecompiledPreamble.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CIndexer.h
  clang/tools/libclang/libclang.map
  clang/unittests/Frontend/ASTUnitTest.cpp
  clang/unittests/libclang/LibclangTest.cpp
  clang/unittests/libclang/TestUtils.h

Index: clang/unittests/libclang/TestUtils.h
===
--- clang/unittests/libclang/TestUtils.h
+++ clang/unittests/libclang/TestUtils.h
@@ -22,11 +22,11 @@
 #include 
 
 class LibclangParseTest : public ::testing::Test {
-  // std::greater<> to remove files before their parent dirs in TearDown().
-  std::set> Files;
   typedef std::unique_ptr fixed_addr_string;
   std::map UnsavedFileContents;
 public:
+  // std::greater<> to remove files before their parent dirs in TearDown().
+  std::set> FilesAndDirsToRemove;
   std::string TestDir;
   bool RemoveTestDirRecursivelyDuringTeardown = false;
   CXIndex Index;
@@ -40,7 +40,7 @@
 TestDir = std::string(Dir.str());
 TUFlags = CXTranslationUnit_DetailedPreprocessingRecord |
   clang_defaultEditingTranslationUnitOptions();
-Index = clang_createIndex(0, 0);
+CreateIndex();
 ClangTU = nullptr;
   }
   void TearDown() override {
@@ -48,7 +48,7 @@
 clang_disposeIndex(Index);
 
 namespace fs = llvm::sys::fs;
-for (const std::string &Path : Files)
+for (const std::string &Path : FilesAndDirsToRemove)
   EXPECT_FALSE(fs::remove(Path, /*IgnoreNonExisting=*/false));
 if (RemoveTestDirRecursivelyDuringTeardown)
   EXPECT_FALSE(fs::remove_directories(TestDir, /*IgnoreErrors=*/false));
@@ -63,7 +63,7 @@
FileI != FileEnd; ++FileI) {
 ASSERT_NE(*FileI, ".");
 path::append(Path, *FileI);
-Files.emplace(Path.str());
+FilesAndDirsToRemove.emplace(Path.str());
   }
   Filename = std::string(Path.str());
 }
@@ -101,6 +101,9 @@
 return string;
   };
 
+protected:
+  virtual void CreateIndex() { Index = clang_createIndex(0, 0); }
+
 private:
   template
   static CXChildVisitResult TraverseStateless(CXCursor cx, CXCursor parent,
Index: clang/unittests/libclang/LibclangTest.cpp
===
--- clang/unittests/libclang/LibclangTest.cpp
+++ clang/unittests/libclang/LibclangTest.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "TestUtils.h"
 #include "clang-c/Index.h"
 #include "clang-c/Rewrite.h"
 #include "llvm/ADT/StringRef.h"
@@ -14,7 +15,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include "gtest/gtest.h"
-#include "TestUtils.h"
+#include 
 #include 
 #include 
 #include 
@@ -355,6 +356,110 @@
   clang_ModuleMapDescriptor_dispose(MMD);
 }
 
+class LibclangPreambleStorageTest : public LibclangParseTest {
+  std::string Main = "main.cpp";
+
+protected:
+  std::string PreambleDir;
+  void InitializePreambleDir() {
+llvm::SmallString<128> PathBuffer(TestDir);
+llvm::sys::path::append(PathBuffer, "preambles");
+namespace fs = llvm::sys::fs;
+ASSERT_FALSE(fs::create_directory(PathBuffer, false, fs::perms::owner_all));
+
+PreambleDir = static_cast(PathBuffer);
+FilesAndDirsToRemove.insert(PreambleDir);
+  }
+
+public:
+  void CountPreamblesInPreambleDir(int PreambleCount) {
+// For some reason, the preamble is not created without '\n' before `int`.
+WriteFile(Main, "\nint main() {}");
+
+TUFlags |= CXTranslationUnit_CreatePreambleOnFirstParse;
+ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0,
+ nullptr, 0, TUFlags);
+
+int FileCount = 0;
+
+namespace fs = llvm::sys::fs;
+std::error_code EC;
+for (fs::directory_iterator File(PreambleDir, EC), FileEnd;
+ File != FileEnd && !EC; File.increment(EC)) {
+  ++FileCount;
+
+  EXPECT_EQ(File->type(), fs::file_type::regular_file);
+
+  const auto Filename = llvm::sys::path::filename(File->path());
+  EXPECT_EQ(Filename.size(), std::strlen("preamble-%%.pch"));
+  EXPECT_TRUE(Filename.startswith("preamble-"));
+  EXPECT_TRUE(Filename.endswith(".pch"));
+
+  const auto Status = File->status();
+  ASSERT_TRUE(Status);
+  if (false) {
+// The permissions assertion below fails, because the .pch.tmp file is
+// created with default permissions and replaces the .pch file along
+   

[PATCH] D144603: Add option to disable compiler launcher on external projects

2023-03-01 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Hmm, what cache key does ccache use for compilers? Is it the `--version` output 
string, the path, or some combination? If the path is involved then I don't see 
any value in using ccache for configuring anything past stage1, since the 
compiler will (presumably) be installed somewhere else afterwards and not used 
directly from the build tree. If it's just `--version`, what are the cache 
pollution concerns? The compiler binaries output by all the stages should 
produce the same outputs given the same inputs (and presumably have the same 
`--version`), right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144603

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


[PATCH] D143418: [libclang] Add API to override preamble storage path

2023-03-01 Thread Igor Kushnir via Phabricator via cfe-commits
vedgy marked 2 inline comments as done.
vedgy added inline comments.



Comment at: clang/include/clang-c/Index.h:329
+ * CXIndexOptions Opts = { sizeof(CXIndexOptions),
+ * clang_getDefaultGlobalOptions() };
+ * \endcode

When I almost finished the requested changes, I remembered that the return 
value of `clang_getDefaultGlobalOptions()` depends on environment variables, 
and thus `0` is not necessarily the default. Adjusted the changes and updated 
this revision.

Does the extra requirement to non-zero initialize this second member sway your 
opinion on the usefulness of the helper function `inline CXIndexOptions 
clang_getDefaultIndexOptions()`? Note that there may be same (environment) or 
other important reasons why future new options couldn't be zeroes by default.



Comment at: clang/tools/c-index-test/c-index-test.c:79
+Opts.PreambleStoragePath = NULL;
+Opts.InvocationEmissionPath = 
getenv("CINDEXTEST_INVOCATION_EMISSION_PATH");
+

aaron.ballman wrote:
> vedgy wrote:
> > aaron.ballman wrote:
> > > vedgy wrote:
> > > > aaron.ballman wrote:
> > > > > vedgy wrote:
> > > > > > When a libclang user needs to override a single option in 
> > > > > > `CXIndexOptions`, [s]he has to set every member of the struct 
> > > > > > explicitly. When new options are added, each libclang user needs to 
> > > > > > update the code that sets the options under `CINDEX_VERSION_MINOR` 
> > > > > > `#if`s. Accidentally omitting even one member assignment risks 
> > > > > > undefined or wrong behavior. How about adding an `inline` helper 
> > > > > > function `CXIndexOptions clang_getDefaultIndexOptions()`, which 
> > > > > > assigns default values to all struct members? Libclang users can 
> > > > > > then call this function to obtain the default configuration, then 
> > > > > > tweak only the members they want to override.
> > > > > > 
> > > > > > If this suggestion is to be implemented, how to deal with 
> > > > > > [[https://stackoverflow.com/questions/68004269/differences-of-the-inline-keyword-in-c-and-c|the
> > > > > >  differences of the inline keyword in C and C++]]?
> > > > > By default, `0` should give you the most reasonable default behavior 
> > > > > for most of the existing options (and new options should follow the 
> > > > > same pattern). Ideally, users should be able to do:
> > > > > ```
> > > > > CXIndexOptions Opts;
> > > > > memset(&Opts, 0, sizeof(Opts));
> > > > > Opts.Size = sizeof(Opts);
> > > > > Opts.Whatever = 12;
> > > > > CXIndex Idx = clang_createIndexWithOptions(&Opts);
> > > > > ```
> > > > > Global options defaulting to 0 is fine (uses regular thread 
> > > > > priorities), we don't think want to default to excluding declarations 
> > > > > from PCH, and we want to use the default preamble and invocation 
> > > > > emission paths (if any). The only option that nonzero as a default 
> > > > > *might* make sense for is displaying diagnostics, but even that seems 
> > > > > reasonable to expect the developer to manually enable.
> > > > > 
> > > > > So I don't know that we need a function to get us default indexing 
> > > > > options as `0` should be a reasonable default for all of the options. 
> > > > > As we add new options, we need to be careful to add them in backwards 
> > > > > compatible ways where `0` means "do the most likely thing".
> > > > > 
> > > > > WDYT?
> > > > The disadvantages of committing to defaulting to `0`:
> > > > 1. The usage you propose is still more verbose and error-prone than
> > > > ```
> > > > CXIndexOptions Opts = clang_getDefaultIndexOptions();
> > > > Opts.Whatever = 12;
> > > > CXIndex Idx = clang_createIndexWithOptions(&Opts);
> > > > ```
> > > > 2. The `memset` would look very unclean in modern C++ code.
> > > > 3. The `0` commitment may force unnatural naming of a future option to 
> > > > invert its meaning.
> > > > 
> > > > The advantages:
> > > > 1. No need to implement the inline function now.
> > > > 2. Faster, but I am sure this performance difference doesn't matter. 
> > > > Even a non-inline function call itself (even if it did nothing) to 
> > > > `clang_createIndexWithOptions()` should take longer than assigning a 
> > > > few values to built-in-typed members.
> > > > 
> > > > Another advantage of not having to remember to update the inline 
> > > > function's implementation when new options are added is counterbalanced 
> > > > by the need to be careful to add new options in backwards compatible 
> > > > way where `0` is the default.
> > > > 
> > > > Any other advantages of the `0` that I miss? Maybe there are some 
> > > > advantages for C users, but I suspect most libclang users are C++.
> > > >The usage you propose is still more verbose and error-prone than
> > > > ```
> > > > CXIndexOptions Opts = clang_getDefaultIndexOptions();
> > > > Opts.Whatever = 12;
> > > > CXIndex Idx = clang_createIndexWithOptions(&Opts);
> > > > ```
> > > 
> > > I see 

[PATCH] D145077: [clang][DebugInfo] Support DW_AT_LLVM_preferred_name attribute

2023-03-01 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl accepted this revision.
aprantl added a comment.
This revision is now accepted and ready to land.

I originally was hoping we wouldn't have to introduce a new attribute for this, 
but it looks like there are legitimate concerns about the alternatives, so in 
that sense this looks good!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145077

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


  1   2   >