[PATCH] D156693: [clang][ASTImporter]Skip check depth of friend template parameter

2023-08-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/unittests/AST/StructuralEquivalenceTest.cpp:1697
+TEST_F(StructuralEquivalenceTemplateTest,
+   ClassTemplateEquivalentFriendClassTemplate) {
+  auto t = makeDecls(

   IgnoreTemplateParmDepth) {



Comment at: clang/unittests/AST/StructuralEquivalenceTest.cpp:1732
+  EXPECT_FALSE(testStructuralMatch(Friend->getFriendDecl(), get<1>(t)));
+  EXPECT_TRUE(testStructuralMatch(Friend->getFriendDecl(), get<1>(t), true));
+}

It should work with more simple code like:
```
makeDecls(
  R"(
template struct A;
  )",
  R"(
template struct S {
  template friend struct A;
};
  )",
  Lang_CXX03, classTemplateDecl(hasName("A")), classTemplateDecl(hasName("A"))
);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

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


[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-15 Thread Artem Labazov via Phabricator via cfe-commits
artem added a comment.

Thanks for the review.

I do not have commit rights, could you please push it? Artem Labazov 
<123321art...@gmail.com>


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

https://reviews.llvm.org/D156821

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


[PATCH] D155290: [PGO] Use Unique Profile Files when New Processes are Forked

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

Can we avoid the use of `pthread_atfork` and the dependency on pthreads? Using 
pthreads inside the profile runtime implementation is problematic in the case 
where you want to instrument the libc itself which is used on some platforms 
and it's one of the reasons why we would like to eliminate the dependency on 
libc altogether and use `sanitizer_common` instead, see 
https://discourse.llvm.org/t/using-c-and-sanitizer-common-in-profile-runtime/58629.

In D155290#4585607 , @qiongsiwu1 
wrote:

> In D155290#4582825 , @MaskRay wrote:
>
>> Using `%p` should not magically change the behavior and I am unsure the 
>> result is better for PGO. 
>> If we decide to provide such a mode, it needs to be opt-in by adding a new 
>> format specifier or API.
>> Can you elaborate separate profile files are going to be useful?
>
> Thanks again for taking a look at this patch!
>
> Sure! We are generating separate profiles through `%p` for two reasons. 
> First, we think that `%p` implies a profile per process, even if `exec` is 
> not called after `fork`. It is unexpected that with `%p`, a program that 
> forks child processes only create one profile file from the parent. This is 
> why we did not create a new API or create a new pattern. Second, we are 
> trying to catch non-gracefully terminated processes during profile generate. 
> We observed a scenario where a hot function having all 0 counters. The 
> reasons was the child process was created by a fork (but no `exec` followed), 
> and then was terminated probably by a signal, instead of going through 
> `exit()`. Such a process did not have a chance to write back the profile for 
> merging. The parent process took a different call path and never called the 
> hot function. We would like to detect such a situation for a particular 
> process. Hence this patch creates an empty profile file if a process is not 
> terminated gracefully. Using `%p` is probably the most natural choice when 
> debugging such issues.
>
> One can argue that we may look into the continuous mode to manage abnormal 
> terminations during profile generate. I have not looked too closely at that, 
> but we think it is still useful for a user to tell that some processes did 
> not write any profile back, for debugging, or for diagnostics.

Handling cases like these is exactly why the continous mode was created. Your 
solution only covers a single case, but there's many scenarios where process 
can terminate abnormally and fail to invoke `atexit` hooks which would results 
in profile not being written out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155290

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


[PATCH] D157953: [CGCall][RISCV] Handle function calls with parameters of RVV tuple type

2023-08-15 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD created this revision.
eopXD added reviewers: craig.topper, kito-cheng, rogfer01, wangpc.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, 
shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, arichardson.
Herald added a project: All.
eopXD requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

This is an oversight in D146872 , where 
function calls with tuple type
was not covered. This commit fixes this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157953

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type.c
  llvm/test/Transforms/SROA/scalable-vector-struct.ll

Index: llvm/test/Transforms/SROA/scalable-vector-struct.ll
===
--- llvm/test/Transforms/SROA/scalable-vector-struct.ll
+++ llvm/test/Transforms/SROA/scalable-vector-struct.ll
@@ -20,3 +20,34 @@
   %val = load %struct.test, %struct.test* %addr, align 4
   ret %struct.test %val
 }
+
+
+define { ,  } @return_tuple( %v_tuple.coerce0,  %v_tuple.coerce1) {
+; CHECK-LABEL: @return_tuple(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[TMP0:%.*]] = insertvalue { ,  } poison,  [[V_TUPLE_COERCE0:%.*]], 0
+; CHECK-NEXT:[[TMP1:%.*]] = insertvalue { ,  } [[TMP0]],  [[V_TUPLE_COERCE1:%.*]], 1
+; CHECK-NEXT:[[COERCE_EXTRACT0:%.*]] = extractvalue { ,  } [[TMP1]], 0
+; CHECK-NEXT:[[COERCE_EXTRACT1:%.*]] = extractvalue { ,  } [[TMP1]], 1
+; CHECK-NEXT:[[CALL:%.*]] = call { ,  } @foo( [[COERCE_EXTRACT0]],  [[COERCE_EXTRACT1]])
+; CHECK-NEXT:ret { ,  } [[CALL]]
+;
+entry:
+  %v_tuple = alloca { ,  }, align 4
+  %v_tuple.addr = alloca { ,  }, align 4
+  %coerce = alloca { ,  }, align 4
+  %0 = insertvalue { ,  } poison,  %v_tuple.coerce0, 0
+  %1 = insertvalue { ,  } %0,  %v_tuple.coerce1, 1
+  store { ,  } %1, ptr %v_tuple, align 4
+  %v_tuple1 = load { ,  }, ptr %v_tuple, align 4
+  store { ,  } %v_tuple1, ptr %v_tuple.addr, align 4
+  %2 = load { ,  }, ptr %v_tuple.addr, align 4
+  store { ,  } %2, ptr %coerce, align 4
+  %coerce.tuple = load { ,  }, ptr %coerce, align 4
+  %coerce.extract0 = extractvalue { ,  } %coerce.tuple, 0
+  %coerce.extract1 = extractvalue { ,  } %coerce.tuple, 1
+  %call = call { ,  } @foo( %coerce.extract0,  %coerce.extract1)
+  ret { ,  } %call
+}
+
+declare { ,  } @foo(, )
Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type.c
+++ clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type.c
@@ -90,3 +90,36 @@
 __rvv_int32m1x2_t qux(__rvv_int32m1x2_t v_tuple) {
   return v_tuple;
 }
+
+// O0-LABEL: define dso_local { ,  } @quux
+// O0-SAME: ( [[V_TUPLE_COERCE0:%.*]],  [[V_TUPLE_COERCE1:%.*]]) #[[ATTR0]] {
+// O0-NEXT:  entry:
+// O0-NEXT:[[V_TUPLE:%.*]] = alloca { ,  }, align 4
+// O0-NEXT:[[V_TUPLE_ADDR:%.*]] = alloca { ,  }, align 4
+// O0-NEXT:[[COERCE:%.*]] = alloca { ,  }, align 4
+// O0-NEXT:[[TMP0:%.*]] = insertvalue { ,  } poison,  [[V_TUPLE_COERCE0]], 0
+// O0-NEXT:[[TMP1:%.*]] = insertvalue { ,  } [[TMP0]],  [[V_TUPLE_COERCE1]], 1
+// O0-NEXT:store { ,  } [[TMP1]], ptr [[V_TUPLE]], align 4
+// O0-NEXT:[[V_TUPLE1:%.*]] = load { ,  }, ptr [[V_TUPLE]], align 4
+// O0-NEXT:store { ,  } [[V_TUPLE1]], ptr [[V_TUPLE_ADDR]], align 4
+// O0-NEXT:[[TMP2:%.*]] = load { ,  }, ptr [[V_TUPLE_ADDR]], align 4
+// O0-NEXT:store { ,  } [[TMP2]], ptr [[COERCE]], align 4
+// O0-NEXT:[[COERCE_TUPLE:%.*]] = load { ,  }, ptr [[COERCE]], align 4
+// O0-NEXT:[[COERCE_EXTRACT0:%.*]] = extractvalue { ,  } [[COERCE_TUPLE]], 0
+// O0-NEXT:[[COERCE_EXTRACT1:%.*]] = extractvalue { ,  } [[COERCE_TUPLE]], 1
+// O0-NEXT:[[CALL:%.*]] = call { ,  } @qux( [[COERCE_EXTRACT0]],  [[COERCE_EXTRACT1]])
+// O0-NEXT:ret { ,  } [[CALL]]
+//
+// AFTER_MEM2REG-LABEL: define dso_local { ,  } @quux
+// AFTER_MEM2REG-SAME: ( [[V_TUPLE_COERCE0:%.*]],  [[V_TUPLE_COERCE1:%.*]]) #[[ATTR0]] {
+// AFTER_MEM2REG-NEXT:  entry:
+// AFTER_MEM2REG-NEXT:[[TMP0:%.*]] = insertvalue { ,  } poison,  [[V_TUPLE_COERCE0]], 0
+// AFTER_MEM2REG-NEXT:[[TMP1:%.*]] = insertvalue { ,  } [[TMP0]],  [[V_TUPLE_COERCE1]], 1
+// AFTER_MEM2REG-NEXT:[[COERCE_EXTRACT0:%.*]] = extractvalue { ,  } [[TMP1]], 0
+// AFTER_MEM2REG-NEXT:[[COERCE_EXTRACT1:%.*]] = extractvalue { ,  } [[TMP1]], 1
+// AFTER_MEM2REG-NEXT:[[CALL:%.*]] = call { ,  } @qux( [[COERCE_EXTRACT0]],  [[COERCE_EXTRACT1]])
+// AFTER_MEM2REG-NEXT:ret { ,  } [[CALL]]
+//
+__rvv_int32m1x2_t quux(__rvv_int32m1x2_t v_tuple) {
+  return qux(v_tuple);
+}
In

[PATCH] D142660: [AIX] supporting -X options for llvm-ranlib in AIX OS

2023-08-15 Thread James Henderson via Phabricator via cfe-commits
jhenderson accepted this revision.
jhenderson added a comment.

I'm going to accept this change, although I still have significant concerns 
about how the whole parsing logic seems more complicated than it needs to be.




Comment at: llvm/tools/llvm-ar/llvm-ar.cpp:74
+ << "  -X{32|64|32_64|any}   - Specify which archive symbol tables "
+"should be generated if they do not already exist (AIX OS only)\n";
 }

DiggerLin wrote:
> jhenderson wrote:
> > Strictly speaking, this should be "Big Archive formats only" not "AIX OS 
> > only" since theoretically you could have Big Archive archives on other 
> > platforms. However, I'm not bothered if you don't want to change this. The 
> > same probably goes for other tools for that matter, but don't change them 
> > now.
> Strictly speaking, this should be "Big Archive format on AIX OS only" ,
> in AIX OS , you can still input the -X option , but the X option not work for 
> gnu archive format.
Ah, sorry, I misremembered the code, you are right.

It does raise a question whether the -X option at least should be available on 
non-AIX platforms, because otherwise there's no way of controlling the symbol 
table behaviour like there is on AIX. However, that's probably a different 
patch (series) and not necessarily one we need to worry about unless somebody 
has an actual use-case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142660

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


[PATCH] D156344: Disable call to fma for soft-float

2023-08-15 Thread ChenZheng via Phabricator via cfe-commits
shchenz added a comment.

In D156344#4583767 , @long5hot wrote:

> In D156344#4583559 , @shchenz wrote:
>
>> compiler-rt builtins library should not just undefining fma for PPC, right 
>> (see 
>> https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html)? If 
>> so, maybe we should at least first try not generating fma for soft-float at 
>> the first place where fmul + fadd is fused, like `tryEmitFMulAdd` in clang 
>> front end?
>
> I actually raised D154605  for that one, 
> but it's only for X86.
> I was relying on target-features containing "+fma", which is wrong. The 
> review was raised just to get feedback from community working on various 
> targets.
> Plan is to disable fma-intrinsic from IR for all targets which doesn't 
> support fma.

Thanks. I think `soft-float` looks like a candidate for the `hasFMA` function 
in D154605 .


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

https://reviews.llvm.org/D156344

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


[PATCH] D156693: [clang][ASTImporter]Skip check depth of friend template parameter

2023-08-15 Thread Qizhi Hu via Phabricator via cfe-commits
jcsxky updated this revision to Diff 550208.
jcsxky added a comment.

Add more simple testcase to StructuralEquivalenceTest.cpp.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

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

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1,5 +1,6 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTStructuralEquivalence.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Testing/CommandLineArgs.h"
@@ -130,15 +131,18 @@
 return makeStmts(Wrap(SrcCode0), Wrap(SrcCode1), Lang, AMatcher);
   }
 
-  bool testStructuralMatch(Decl *D0, Decl *D1) {
+  bool testStructuralMatch(Decl *D0, Decl *D1,
+   bool IgnoreTemplateParmDepth = false) {
 llvm::DenseSet> NonEquivalentDecls01;
 llvm::DenseSet> NonEquivalentDecls10;
 StructuralEquivalenceContext Ctx01(
-D0->getASTContext(), D1->getASTContext(),
-NonEquivalentDecls01, StructuralEquivalenceKind::Default, false, false);
+D0->getASTContext(), D1->getASTContext(), NonEquivalentDecls01,
+StructuralEquivalenceKind::Default, false, false, false,
+IgnoreTemplateParmDepth);
 StructuralEquivalenceContext Ctx10(
-D1->getASTContext(), D0->getASTContext(),
-NonEquivalentDecls10, StructuralEquivalenceKind::Default, false, false);
+D1->getASTContext(), D0->getASTContext(), NonEquivalentDecls10,
+StructuralEquivalenceKind::Default, false, false, false,
+IgnoreTemplateParmDepth);
 bool Eq01 = Ctx01.IsEquivalent(D0, D1);
 bool Eq10 = Ctx10.IsEquivalent(D1, D0);
 EXPECT_EQ(Eq01, Eq10);
@@ -165,8 +169,9 @@
 return testStructuralMatch(get<0>(t), get<1>(t));
   }
 
-  bool testStructuralMatch(std::tuple t) {
-return testStructuralMatch(get<0>(t), get<1>(t));
+  bool testStructuralMatch(std::tuple t,
+   bool IgnoreTemplateParmDepth = false) {
+return testStructuralMatch(get<0>(t), get<1>(t), IgnoreTemplateParmDepth);
   }
 };
 
@@ -1689,6 +1694,61 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceTemplateTest, IgnoreTemplateParmDepthEquivalent) {
+  auto t = makeDecls(
+  R"(
+template struct A;
+  )",
+  R"(
+template struct S {
+  template friend struct A;
+};
+  )",
+  Lang_CXX03, classTemplateDecl(hasName("A")),
+  classTemplateDecl(hasName("A")));
+  EXPECT_TRUE(testStructuralMatch(t));
+  EXPECT_TRUE(testStructuralMatch(t, true));
+}
+
+TEST_F(StructuralEquivalenceTemplateTest,
+   ClassTemplateEquivalentFriendClassTemplate) {
+  auto t = makeDecls(
+  R"(
+  template 
+  class A {
+  public:
+template 
+friend class A;
+
+A(T x)  :x(x) {}
+
+  private:
+T x;
+  };
+  )",
+
+  R"(
+  template 
+  class A {
+  public:
+template 
+friend class A;
+
+A(T x) : x(x) {}
+
+  private:
+T x;
+  };
+
+  A a1(0);
+  )",
+  Lang_CXX03, friendDecl(),
+  classTemplateDecl(has(cxxRecordDecl(hasDefinition(), hasName("A");
+  auto *Friend = cast(get<0>(t));
+  EXPECT_FALSE(testStructuralMatch(Friend->getFriendDecl(), get<1>(t)));
+  EXPECT_TRUE(testStructuralMatch(Friend->getFriendDecl(), get<1>(t), true));
+}
+
 TEST_F(
 StructuralEquivalenceTemplateTest,
 ClassTemplSpecWithInequivalentShadowedTemplArg) {
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4246,6 +4246,58 @@
   EXPECT_TRUE(Imported->getPreviousDecl());
 }
 
+TEST_P(ImportFriendClasses, SkipComparingFriendTemplateDepth) {
+  Decl *ToTU = getToTuDecl(
+  R"(
+  template 
+  class A;
+
+  template 
+  class A {
+  public:
+template 
+friend class A;
+
+A(T x)  :x(x) {}
+
+  private:
+T x;
+  };
+  )",
+  Lang_CXX11);
+
+  auto *Fwd = FirstDeclMatcher().match(
+  ToTU,
+  classTemplateDecl(has(cxxRecordDecl(hasDefinition(), hasName("A");
+  Decl *FromTU = getTuDecl(
+  R"(
+  template 
+  class A;
+
+  template 
+  class A {
+  public:
+template 
+friend class A;
+
+A(T x) : x(x) {}
+
+  private:
+T x;
+  };
+
+  A a1(0);
+  )",
+  Lang_CXX11,

[PATCH] D157691: [ASTImporter] Remove extranous FunctionTemplateDecl introduced by templated friend

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

When committing this patch, the commit message should not contain the whole AST 
and crash dump (phabricator takes the "summary" text), this looks too much in a 
commit message. One AST dump from the wrong To AST is enough.




Comment at: clang/test/Import/templated-friend/test.cpp:5
+  A a;
+}

These test files are really not needed. The same AST import is performed in the 
unit test.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:5644
+)",
+   Lang_CXX03, "", Lang_CXX03, "X");
+

This formatting looks not correct.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157691

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


[clang] d60c3d0 - [clang] Skip stores in init for fields that are empty structs

2023-08-15 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2023-08-15T10:59:23+03:00
New Revision: d60c3d08e78dfbb4b180776b83e910d810e1f36a

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

LOG: [clang] Skip stores in init for fields that are empty structs

An empty struct is handled as a struct with a dummy i8, on all targets.

Most targets treat an empty struct return value as essentially
void - but some don't. (Currently, at least x86_64-windows-* and
powerpc64le-* don't treat it as void.)

When intializing a struct with such a no_unique_address member,
make sure we don't write the dummy i8 into the struct where there's
no space allocated for it.

Previously it would clobber the actual valid data of the struct.

Fixes https://github.com/llvm/llvm-project/issues/64253, and
possibly https://github.com/llvm/llvm-project/issues/64077
and https://github.com/llvm/llvm-project/issues/64427 as well.

We should omit the store for any empty record (not only ones
declared with no_unique_address); we can have a situation where a
class doesn't have the no_unique_address attribute, but is embedded
in an outer struct with the no_unique_address attribute - like this:

struct S {};
S f();
struct S2 : public S { S2();};
S2::S2() : S(f()) {}
struct S3 { int x; [[no_unique_address]] S2 y; S3(); };
S3::S3() : x(1), y() {}

Here, the problematic store (which this patch omits) is in
the constructor of S2. In the case of S3, S2 has no valid storage
and aliases x - thus the constructor of S2 should omit the dummy
store.

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

Added: 
clang/test/CodeGenCXX/ctor-empty-nounique.cpp

Modified: 
clang/lib/CodeGen/CGCall.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 2b5121a7b23063..920a219205a21f 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -13,6 +13,7 @@
 
 #include "CGCall.h"
 #include "ABIInfo.h"
+#include "ABIInfoImpl.h"
 #include "CGBlocks.h"
 #include "CGCXXABI.h"
 #include "CGCleanup.h"
@@ -5781,9 +5782,14 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 DestIsVolatile = false;
   }
 
-  // If the value is offset in memory, apply the offset now.
-  Address StorePtr = emitAddressAtOffset(*this, DestPtr, RetAI);
-  CreateCoercedStore(CI, StorePtr, DestIsVolatile, *this);
+  // An empty record can overlap other data (if declared with
+  // no_unique_address); omit the store for such types - as there is no
+  // actual data to store.
+  if (!isEmptyRecord(getContext(), RetTy, true)) {
+// If the value is offset in memory, apply the offset now.
+Address StorePtr = emitAddressAtOffset(*this, DestPtr, RetAI);
+CreateCoercedStore(CI, StorePtr, DestIsVolatile, *this);
+  }
 
   return convertTempToRValue(DestPtr, RetTy, SourceLocation());
 }

diff  --git a/clang/test/CodeGenCXX/ctor-empty-nounique.cpp 
b/clang/test/CodeGenCXX/ctor-empty-nounique.cpp
new file mode 100644
index 00..f01cad1dacf266
--- /dev/null
+++ b/clang/test/CodeGenCXX/ctor-empty-nounique.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64le-windows-gnu -emit-llvm -o - %s | 
FileCheck %s
+
+// An empty struct is handled as a struct with a dummy i8, on all targets.
+// Most targets treat an empty struct return value as essentially void - but
+// some don't. (Currently, at least x86_64-windows-* and powerpc64le-* don't
+// treat it as void.)
+//
+// When intializing a struct with such a no_unique_address member, make sure we
+// don't write the dummy i8 into the struct where there's no space allocated 
for
+// it.
+//
+// This can only be tested with targets that don't treat empty struct returns 
as
+// void.
+
+struct S {};
+S f();
+struct Z {
+  int x;
+  [[no_unique_address]] S y;
+  Z();
+};
+Z::Z() : x(111), y(f()) {}
+
+// CHECK: define {{.*}} @_ZN1ZC2Ev
+// CHECK: %call = call i8 @_Z1fv()
+// CHECK-NEXT: ret void
+
+
+// Check that the constructor for an empty member gets called with the right
+// 'this' pointer.
+
+struct S2 {
+  S2();
+};
+struct Z2 {
+  int x;
+  [[no_unique_address]] S2 y;
+  Z2();
+};
+Z2::Z2() : x(111) {}
+
+// CHECK: define {{.*}} @_ZN2Z2C2Ev(ptr {{.*}} %this)
+// CHECK: %this.addr = alloca ptr
+// CHECK: store ptr %this, ptr %this.addr
+// CHECK: %this1 = load ptr, ptr %this.addr
+// CHECK: call void @_ZN2S2C1Ev(ptr {{.*}} %this1)



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


[PATCH] D157332: [clang] Make init for empty no_unique_address fields a no-op write

2023-08-15 Thread Martin Storsjö 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 rGd60c3d08e78d: [clang] Skip stores in init for fields that 
are empty structs (authored by mstorsjo).

Changed prior to commit:
  https://reviews.llvm.org/D157332?vs=549575&id=550209#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157332

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGenCXX/ctor-empty-nounique.cpp


Index: clang/test/CodeGenCXX/ctor-empty-nounique.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/ctor-empty-nounique.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64le-windows-gnu -emit-llvm -o - %s | 
FileCheck %s
+
+// An empty struct is handled as a struct with a dummy i8, on all targets.
+// Most targets treat an empty struct return value as essentially void - but
+// some don't. (Currently, at least x86_64-windows-* and powerpc64le-* don't
+// treat it as void.)
+//
+// When intializing a struct with such a no_unique_address member, make sure we
+// don't write the dummy i8 into the struct where there's no space allocated 
for
+// it.
+//
+// This can only be tested with targets that don't treat empty struct returns 
as
+// void.
+
+struct S {};
+S f();
+struct Z {
+  int x;
+  [[no_unique_address]] S y;
+  Z();
+};
+Z::Z() : x(111), y(f()) {}
+
+// CHECK: define {{.*}} @_ZN1ZC2Ev
+// CHECK: %call = call i8 @_Z1fv()
+// CHECK-NEXT: ret void
+
+
+// Check that the constructor for an empty member gets called with the right
+// 'this' pointer.
+
+struct S2 {
+  S2();
+};
+struct Z2 {
+  int x;
+  [[no_unique_address]] S2 y;
+  Z2();
+};
+Z2::Z2() : x(111) {}
+
+// CHECK: define {{.*}} @_ZN2Z2C2Ev(ptr {{.*}} %this)
+// CHECK: %this.addr = alloca ptr
+// CHECK: store ptr %this, ptr %this.addr
+// CHECK: %this1 = load ptr, ptr %this.addr
+// CHECK: call void @_ZN2S2C1Ev(ptr {{.*}} %this1)
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -13,6 +13,7 @@
 
 #include "CGCall.h"
 #include "ABIInfo.h"
+#include "ABIInfoImpl.h"
 #include "CGBlocks.h"
 #include "CGCXXABI.h"
 #include "CGCleanup.h"
@@ -5781,9 +5782,14 @@
 DestIsVolatile = false;
   }
 
-  // If the value is offset in memory, apply the offset now.
-  Address StorePtr = emitAddressAtOffset(*this, DestPtr, RetAI);
-  CreateCoercedStore(CI, StorePtr, DestIsVolatile, *this);
+  // An empty record can overlap other data (if declared with
+  // no_unique_address); omit the store for such types - as there is no
+  // actual data to store.
+  if (!isEmptyRecord(getContext(), RetTy, true)) {
+// If the value is offset in memory, apply the offset now.
+Address StorePtr = emitAddressAtOffset(*this, DestPtr, RetAI);
+CreateCoercedStore(CI, StorePtr, DestIsVolatile, *this);
+  }
 
   return convertTempToRValue(DestPtr, RetTy, SourceLocation());
 }


Index: clang/test/CodeGenCXX/ctor-empty-nounique.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/ctor-empty-nounique.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64le-windows-gnu -emit-llvm -o - %s | FileCheck %s
+
+// An empty struct is handled as a struct with a dummy i8, on all targets.
+// Most targets treat an empty struct return value as essentially void - but
+// some don't. (Currently, at least x86_64-windows-* and powerpc64le-* don't
+// treat it as void.)
+//
+// When intializing a struct with such a no_unique_address member, make sure we
+// don't write the dummy i8 into the struct where there's no space allocated for
+// it.
+//
+// This can only be tested with targets that don't treat empty struct returns as
+// void.
+
+struct S {};
+S f();
+struct Z {
+  int x;
+  [[no_unique_address]] S y;
+  Z();
+};
+Z::Z() : x(111), y(f()) {}
+
+// CHECK: define {{.*}} @_ZN1ZC2Ev
+// CHECK: %call = call i8 @_Z1fv()
+// CHECK-NEXT: ret void
+
+
+// Check that the constructor for an empty member gets called with the right
+// 'this' pointer.
+
+struct S2 {
+  S2();
+};
+struct Z2 {
+  int x;
+  [[no_unique_address]] S2 y;
+  Z2();
+};
+Z2::Z2() : x(111) {}
+
+// CHECK: define {{.*}} @_ZN2Z2C2Ev(ptr {{.*}} %this)
+// CHECK: %this.addr = alloca ptr
+// CHECK: store ptr %this, ptr %this.addr
+// CHECK: %this1 = load ptr, ptr %this.addr
+// CHECK: call void @_ZN2S2C1Ev(ptr {{.*}} %this1)
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -13,6 +13,

[PATCH] D157691: [ASTImporter] Remove extranous FunctionTemplateDecl introduced by templated friend

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

In D157691#4587490 , @balazske wrote:

> When committing this patch, the commit message should not contain the whole 
> AST and crash dump (phabricator takes the "summary" text), this looks too 
> much in a commit message. One AST dump from the wrong To AST is enough.

👍


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157691

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


[PATCH] D157691: [ASTImporter] Remove extranous FunctionTemplateDecl introduced by templated friend

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

1. Remove unnecessary testcase.
2. Format unittest code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157691

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
@@ -5634,6 +5634,43 @@
   EXPECT_EQ(Imported->getPreviousDecl(), Friend);
 }
 
+TEST_P(ImportFriendFunctionTemplates, ImportFriendFunctionInsideClassTemplate) 
{
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"(
+  template  struct X {
+template  friend void f();
+  };
+  )",
+  Lang_CXX03, "", Lang_CXX03, "X");
+
+  auto *FromFriend = FirstDeclMatcher().match(From, friendDecl());
+  auto *ToFriend = FirstDeclMatcher().match(To, friendDecl());
+
+  EXPECT_TRUE(FromFriend ==
+  LastDeclMatcher().match(From, friendDecl()));
+  EXPECT_TRUE(ToFriend ==
+  LastDeclMatcher().match(To, friendDecl()));
+
+  auto *FromDecl = FromFriend->getFriendDecl();
+  auto *FromDC = FromFriend->getDeclContext();
+  auto *FromLexicalDC = FromFriend->getLexicalDeclContext();
+
+  EXPECT_TRUE(FromDC->containsDecl(FromFriend));
+  EXPECT_FALSE(FromDC->containsDecl(FromDecl));
+  EXPECT_TRUE(FromLexicalDC->containsDecl(FromFriend));
+  EXPECT_FALSE(FromLexicalDC->containsDecl(FromDecl));
+
+  auto *ToDecl = ToFriend->getFriendDecl();
+  auto *ToDC = ToFriend->getDeclContext();
+  auto *ToLexicalDC = ToFriend->getLexicalDeclContext();
+
+  EXPECT_TRUE(ToDC->containsDecl(ToFriend));
+  EXPECT_FALSE(ToDC->containsDecl(ToDecl));
+  EXPECT_TRUE(ToLexicalDC->containsDecl(ToFriend));
+  EXPECT_FALSE(ToLexicalDC->containsDecl(ToDecl));
+}
+
 struct ASTImporterWithFakeErrors : ASTImporter {
   using ASTImporter::ASTImporter;
   bool returnWithErrorInTest() override { return true; }
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -6447,7 +6447,7 @@
 
   ToFunc->setAccess(D->getAccess());
   ToFunc->setLexicalDeclContext(LexicalDC);
-  LexicalDC->addDeclInternal(ToFunc);
+  addDeclToContexts(D, ToFunc);
 
   ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
   if (LT && !OldParamDC.empty()) {


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5634,6 +5634,43 @@
   EXPECT_EQ(Imported->getPreviousDecl(), Friend);
 }
 
+TEST_P(ImportFriendFunctionTemplates, ImportFriendFunctionInsideClassTemplate) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"(
+  template  struct X {
+template  friend void f();
+  };
+  )",
+  Lang_CXX03, "", Lang_CXX03, "X");
+
+  auto *FromFriend = FirstDeclMatcher().match(From, friendDecl());
+  auto *ToFriend = FirstDeclMatcher().match(To, friendDecl());
+
+  EXPECT_TRUE(FromFriend ==
+  LastDeclMatcher().match(From, friendDecl()));
+  EXPECT_TRUE(ToFriend ==
+  LastDeclMatcher().match(To, friendDecl()));
+
+  auto *FromDecl = FromFriend->getFriendDecl();
+  auto *FromDC = FromFriend->getDeclContext();
+  auto *FromLexicalDC = FromFriend->getLexicalDeclContext();
+
+  EXPECT_TRUE(FromDC->containsDecl(FromFriend));
+  EXPECT_FALSE(FromDC->containsDecl(FromDecl));
+  EXPECT_TRUE(FromLexicalDC->containsDecl(FromFriend));
+  EXPECT_FALSE(FromLexicalDC->containsDecl(FromDecl));
+
+  auto *ToDecl = ToFriend->getFriendDecl();
+  auto *ToDC = ToFriend->getDeclContext();
+  auto *ToLexicalDC = ToFriend->getLexicalDeclContext();
+
+  EXPECT_TRUE(ToDC->containsDecl(ToFriend));
+  EXPECT_FALSE(ToDC->containsDecl(ToDecl));
+  EXPECT_TRUE(ToLexicalDC->containsDecl(ToFriend));
+  EXPECT_FALSE(ToLexicalDC->containsDecl(ToDecl));
+}
+
 struct ASTImporterWithFakeErrors : ASTImporter {
   using ASTImporter::ASTImporter;
   bool returnWithErrorInTest() override { return true; }
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -6447,7 +6447,7 @@
 
   ToFunc->setAccess(D->getAccess());
   ToFunc->setLexicalDeclContext(LexicalDC);
-  LexicalDC->addDeclInternal(ToFunc);
+  addDeclToContexts(D, ToFunc);
 
   ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
   if (LT && !OldParamDC.empty()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156693: [clang][ASTImporter]Skip check depth of friend template parameter

2023-08-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/unittests/AST/StructuralEquivalenceTest.cpp:1709
+  classTemplateDecl(hasName("A")));
+  EXPECT_TRUE(testStructuralMatch(t));
+  EXPECT_TRUE(testStructuralMatch(t, true));

The intent was to have `EXPECT_FALSE` without ignore depth, and the next test 
would be not needed. If it does not work with this code a different code can be 
found. The depth of the (unnamed) template parameter is really different in 
these cases too, but it is probably not detected by structural equivalence. 
Maybe `template` or `template` is needed. But to document 
this behavior the current test can be added too, with name 
`IgnoreTemplateParmDepthAtTemplateTypeParmDecl`, and the new one with name 
`IgnoreTemplateParmDepthAtNonTypeTemplateParmDecl`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

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


[PATCH] D157952: [clang] Support function pointer types with attributes when extracting parameter names for signature help

2023-08-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:6073
 
+  if (auto A = Target.getAs()) {
+Target = A.getModifiedLoc();

By unwrapping these in a fixed order, we'll successfully unwrap a pointer to an 
attributed function type, but not an attributed pointer to function type.

Maybe extract a recursive function so we can unwrap arbitrary sequences of 
sugar?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157952

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


[clang] 8e329ca - Reland "[Clang][SemaCXX] Add unused warning for variables declared in condition expressions"

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

Author: Takuya Shimizu
Date: 2023-08-15T17:24:13+09:00
New Revision: 8e329caa944c377c51ef567d5aa67cfac9ffd0fa

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

LOG: Reland "[Clang][SemaCXX] Add unused warning for variables declared in 
condition expressions"

This patch marks the declarations with initializations in condition expressions 
such as
if (int var = init) as unreferenced so that -Wunused can warn on them.

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

Reviewed By: cor3ntin
Differential Revision: https://reviews.llvm.org/D152495

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaCXX/warn-unused-variables.cpp
llvm/lib/Support/VirtualFileSystem.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cd7beff546c932..96a9ec14112292 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -129,6 +129,9 @@ Improvements to Clang's diagnostics
   of a base class is not called in the constructor of its derived class.
 - Clang no longer emits ``-Wmissing-variable-declarations`` for variables 
declared
   with the ``register`` storage class.
+- Clang now warns on unused variables declared and initialized in condition
+  expressions.
+  (`#61681: `_)
 
 Bug Fixes in This Version
 -

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0ad807cca36c7b..db1cd28f7b5a93 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1995,7 +1995,7 @@ static bool ShouldDiagnoseUnusedDecl(const LangOptions 
&LangOpts,
   return false;
   } else if (!D->getDeclName()) {
 return false;
-  } else if (D->isReferenced() || D->isUsed()) {
+  } else if (D->isReferenced() || (!isa(D) && D->isUsed())) {
 return false;
   }
 

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index e6eb9508f8e6ff..17fda20c1ca11c 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4015,6 +4015,10 @@ ExprResult Sema::CheckConditionVariable(VarDecl 
*ConditionVar,
   ConditionVar, ConditionVar->getType().getNonReferenceType(), VK_LValue,
   ConditionVar->getLocation());
 
+  // Ensure that `-Wunused-variable` will be emitted for condition variables
+  // that are not referenced later. e.g.: if (int var = init());
+  ConditionVar->setReferenced(/*R=*/false);
+
   switch (CK) {
   case ConditionKind::Boolean:
 return CheckBooleanCondition(StmtLoc, Condition.get());

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index f78d46f5950360..522ec12de3d368 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5352,7 +5352,7 @@ void Sema::BuildVariableInstantiation(
   // will have been deferred.
   if (!NewVar->isInvalidDecl() &&
   NewVar->getDeclContext()->isFunctionOrMethod() &&
-  OldVar->getType()->isDependentType())
+  OldVar->getType()->isDependentType() && !OldVar->isImplicit())
 DiagnoseUnusedDecl(NewVar);
 }
 

diff  --git a/clang/test/SemaCXX/warn-unused-variables.cpp 
b/clang/test/SemaCXX/warn-unused-variables.cpp
index 4db8bdf12e5de0..db33086436d3af 100644
--- a/clang/test/SemaCXX/warn-unused-variables.cpp
+++ b/clang/test/SemaCXX/warn-unused-variables.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++1y-extensions -verify %s
-// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++1y-extensions -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++14-extensions -Wno-c++17-extensions -verify -std=c++11 %s
 template void f() {
   T t;
   t = 17;
@@ -294,3 +294,115 @@ void RAIIWrapperTest() {
 }
 
 } // namespace gh54489
+
+namespace inside_condition {
+  void ifs() {
+if (int hoge = 0) // expected-warning {{unused variable 'hoge'}}
+  return;
+if (const int const_hoge = 0) // expected-warning {{unused variable 
'const_hoge'}}
+  return;
+else if (int fuga = 0)
+  (void)fuga;
+else if (int used = 1; int catched = used) // expected-warning {{unused 
variable 'catched'}}
+  return;
+else if (int refed = 1; int used = refed)
+  (void)used;
+else if (int unused1 = 2; int unused2 = 3) // expected-warning {{unused 
variable 'unused1'}} \
+   // expected-warning {{unused 
variable 'unused2'}}
+  return;
+else if (int unused = 4; int used = 5) // expected-warning {{unused 
var

[PATCH] D157691: [ASTImporter] Remove extranous FunctionTemplateDecl introduced by templated friend

2023-08-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske accepted this revision.
balazske added a comment.
This revision is now accepted and ready to land.

Additionally, use the "[clang][ASTImporter]" tags at commit message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157691

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


[PATCH] D157151: [Driver] Refactor to use llvm Option's new Visibility flags

2023-08-15 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski accepted this revision.
awarzynski added a comment.
This revision is now accepted and ready to land.

While quite extensive, I find the overall logic in this patch very well 
structured and executed in a very clean manner. It removes a lot of ambiguity, 
makes the overall design much easier to reason about and will definitely 
improve the overall health of the project. The benefits for LLVM Flang are 
almost immediate, see https://reviews.llvm.org/D157837. Thank you for 
implementing this, reviewing such patches is very satisfying and rewarding.

This might cause some disruption to downstream consumers of this API and 
Options.td. Hopefully, "update_options_td_flags.py" that you've included should 
minimise that. I suggest "advertising" it in the summary a bit more.

LGTM, great work, thank you!




Comment at: clang/lib/Driver/Driver.cpp:1941-1945
+  // TODO: We're overriding the mask for flang here to keep this NFC for the
+  // option refactoring, but what we really need to do is annotate the flags
+  // that Flang uses.
   if (IsFlangMode())
+VisibilityMask = llvm::opt::Visibility(options::FlangOption);

Note to myself - I should update this in https://reviews.llvm.org/D157837.



Comment at: flang/docs/FlangDriver.md:248-250
+Options that are also supported by clang should explicitly specify `Default` in
+`Vis`, and options that are only supported in Flang should not specify
+`Default`.

For consistency



Comment at: llvm/unittests/Option/OptionParsingTest.cpp:18
 
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+

Why not just update the test?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157151

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


[PATCH] D156312: [analyzer] Upstream BitwiseShiftChecker

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

The test coverage is also impressive. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156312

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


[PATCH] D156693: [clang][ASTImporter]Skip check depth of friend template parameter

2023-08-15 Thread Qizhi Hu via Phabricator via cfe-commits
jcsxky added inline comments.



Comment at: clang/unittests/AST/StructuralEquivalenceTest.cpp:1709
+  classTemplateDecl(hasName("A")));
+  EXPECT_TRUE(testStructuralMatch(t));
+  EXPECT_TRUE(testStructuralMatch(t, true));

balazske wrote:
> The intent was to have `EXPECT_FALSE` without ignore depth, and the next test 
> would be not needed. If it does not work with this code a different code can 
> be found. The depth of the (unnamed) template parameter is really different 
> in these cases too, but it is probably not detected by structural 
> equivalence. Maybe `template` or `template` is needed. 
> But to document this behavior the current test can be added too, with name 
> `IgnoreTemplateParmDepthAtTemplateTypeParmDecl`, and the new one with name 
> `IgnoreTemplateParmDepthAtNonTypeTemplateParmDecl`.
1. The reason why it's true without ignore depth is that template parameter is 
'TemplateTypeParm' in this case. So 
```
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
 TemplateTypeParmDecl *D1,
 TemplateTypeParmDecl *D2)
```
will be called and return true. 
2. When process 'NonTypeTemplateParm', 
```
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
 QualType T1, QualType T2)
```
is called and return false as the different depth.
I will add `IgnoreTemplateParmDepthAtNonTypeTemplateParmDecl` to illustrate the 
difference. Also, next test will be removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

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


[PATCH] D156693: [clang][ASTImporter]Skip check depth of friend template parameter

2023-08-15 Thread Qizhi Hu via Phabricator via cfe-commits
jcsxky updated this revision to Diff 550214.
jcsxky added a comment.

Add testcase to illustrate the difference between `TemplateTypeParm` and 
`NonTypeTemplateParm` in detecting by structural equivalence.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

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

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1,5 +1,6 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTStructuralEquivalence.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Testing/CommandLineArgs.h"
@@ -130,15 +131,18 @@
 return makeStmts(Wrap(SrcCode0), Wrap(SrcCode1), Lang, AMatcher);
   }
 
-  bool testStructuralMatch(Decl *D0, Decl *D1) {
+  bool testStructuralMatch(Decl *D0, Decl *D1,
+   bool IgnoreTemplateParmDepth = false) {
 llvm::DenseSet> NonEquivalentDecls01;
 llvm::DenseSet> NonEquivalentDecls10;
 StructuralEquivalenceContext Ctx01(
-D0->getASTContext(), D1->getASTContext(),
-NonEquivalentDecls01, StructuralEquivalenceKind::Default, false, false);
+D0->getASTContext(), D1->getASTContext(), NonEquivalentDecls01,
+StructuralEquivalenceKind::Default, false, false, false,
+IgnoreTemplateParmDepth);
 StructuralEquivalenceContext Ctx10(
-D1->getASTContext(), D0->getASTContext(),
-NonEquivalentDecls10, StructuralEquivalenceKind::Default, false, false);
+D1->getASTContext(), D0->getASTContext(), NonEquivalentDecls10,
+StructuralEquivalenceKind::Default, false, false, false,
+IgnoreTemplateParmDepth);
 bool Eq01 = Ctx01.IsEquivalent(D0, D1);
 bool Eq10 = Ctx10.IsEquivalent(D1, D0);
 EXPECT_EQ(Eq01, Eq10);
@@ -165,8 +169,9 @@
 return testStructuralMatch(get<0>(t), get<1>(t));
   }
 
-  bool testStructuralMatch(std::tuple t) {
-return testStructuralMatch(get<0>(t), get<1>(t));
+  bool testStructuralMatch(std::tuple t,
+   bool IgnoreTemplateParmDepth = false) {
+return testStructuralMatch(get<0>(t), get<1>(t), IgnoreTemplateParmDepth);
   }
 };
 
@@ -1689,6 +1694,40 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceTemplateTest,
+   IgnoreTemplateParmDepthAtTemplateTypeParmDecl) {
+  auto t = makeDecls(
+  R"(
+template struct A;
+  )",
+  R"(
+template struct S {
+  template friend struct A;
+};
+  )",
+  Lang_CXX03, classTemplateDecl(hasName("A")),
+  classTemplateDecl(hasName("A")));
+  EXPECT_TRUE(testStructuralMatch(t));
+  EXPECT_TRUE(testStructuralMatch(t, true));
+}
+
+TEST_F(StructuralEquivalenceTemplateTest,
+   IgnoreTemplateParmDepthAtNonTypeTemplateParmDecl) {
+  auto t = makeDecls(
+  R"(
+template struct A;
+  )",
+  R"(
+template struct S {
+  template friend struct A;
+};
+  )",
+  Lang_CXX03, classTemplateDecl(hasName("A")),
+  classTemplateDecl(hasName("A")));
+  EXPECT_FALSE(testStructuralMatch(t));
+  EXPECT_TRUE(testStructuralMatch(t, true));
+}
+
 TEST_F(
 StructuralEquivalenceTemplateTest,
 ClassTemplSpecWithInequivalentShadowedTemplArg) {
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4246,6 +4246,58 @@
   EXPECT_TRUE(Imported->getPreviousDecl());
 }
 
+TEST_P(ImportFriendClasses, SkipComparingFriendTemplateDepth) {
+  Decl *ToTU = getToTuDecl(
+  R"(
+  template 
+  class A;
+
+  template 
+  class A {
+  public:
+template 
+friend class A;
+
+A(T x)  :x(x) {}
+
+  private:
+T x;
+  };
+  )",
+  Lang_CXX11);
+
+  auto *Fwd = FirstDeclMatcher().match(
+  ToTU,
+  classTemplateDecl(has(cxxRecordDecl(hasDefinition(), hasName("A");
+  Decl *FromTU = getTuDecl(
+  R"(
+  template 
+  class A;
+
+  template 
+  class A {
+  public:
+template 
+friend class A;
+
+A(T x) : x(x) {}
+
+  private:
+T x;
+  };
+
+  A a1(0);
+  )",
+  Lang_CXX11, "input1.cc");
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU,
+  classTemplateDecl(has(cxxRecordDecl(hasDefinition(), hasName("A");
+  auto *ToA = Import(FromA, Lang_CXX11);
+  EXPECT_TRUE(ToA);
+  EXPECT_EQ(Fwd->getTemplatedDecl()->getT

[PATCH] D157855: [clang][ExprConstant] Improve error message of compound assignment against uninitialized object

2023-08-15 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet updated this revision to Diff 550216.
hazohelet marked an inline comment as done.
hazohelet added a comment.

Address comments from Timm

- Moved test to C++14,20,23 test file from C++20-only one
- NFC stylistic changes


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

https://reviews.llvm.org/D157855

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constant-expression-cxx14.cpp


Index: clang/test/SemaCXX/constant-expression-cxx14.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx14.cpp
+++ clang/test/SemaCXX/constant-expression-cxx14.cpp
@@ -1275,3 +1275,33 @@
 (dbt2.wp = nullptr, 0)
   };
 }
+
+namespace UninitCompoundAssign {
+constexpr int scalar(int a) {
+  int sum; // cxx14-warning {{uninitialized variable in a constexpr function 
is a C++20 extension}}
+  sum += a; // expected-note {{read of uninitialized object}};
+  return 0;
+}
+static_assert(scalar(3), ""); // expected-error {{constant expression}} \
+  // expected-note {{in call to 'scalar(3)'}}
+
+constexpr int array(int a) {
+  int arr[3]; // cxx14-warning {{uninitialized variable in a constexpr 
function is a C++20 extension}}
+  arr[1] += a; // expected-note {{read of uninitialized object}};
+  return 0;
+}
+static_assert(array(3), ""); // expected-error {{constant expression}} \
+ // expected-note {{in call to 'array(3)'}}
+
+struct Foo {
+  int val; // cxx14-note{{member not initialized by constructor}}
+  constexpr Foo() {} // cxx14-warning {{constexpr constructor that does not 
initialize all members is a C++20 extension}}
+};
+constexpr int field(int a) {
+  Foo f;
+  f.val += a; // expected-note {{read of uninitialized object}};
+  return 0;
+}
+static_assert(field(3), ""); // expected-error {{constant expression}} \
+ // expected-note {{in call to 'field(3)'}}
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -4442,6 +4442,10 @@
   return foundPointer(Subobj, SubobjType);
 case APValue::Vector:
   return foundVector(Subobj, SubobjType);
+case APValue::Indeterminate:
+  Info.FFDiag(E, diag::note_constexpr_access_uninit)
+  << /*read of=*/0 << /*uninitialized object=*/1;
+  return false;
 default:
   // FIXME: can this happen?
   Info.FFDiag(E);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -132,6 +132,9 @@
 - Clang now warns on unused variables declared and initialized in condition
   expressions.
   (`#61681: `_)
+- Clang constexpr evaluator now diagnoses compound assignment operators against
+  uninitialized variables as a read of uninitialized object.
+  (`#51536 _`)
 
 Bug Fixes in This Version
 -


Index: clang/test/SemaCXX/constant-expression-cxx14.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx14.cpp
+++ clang/test/SemaCXX/constant-expression-cxx14.cpp
@@ -1275,3 +1275,33 @@
 (dbt2.wp = nullptr, 0)
   };
 }
+
+namespace UninitCompoundAssign {
+constexpr int scalar(int a) {
+  int sum; // cxx14-warning {{uninitialized variable in a constexpr function is a C++20 extension}}
+  sum += a; // expected-note {{read of uninitialized object}};
+  return 0;
+}
+static_assert(scalar(3), ""); // expected-error {{constant expression}} \
+  // expected-note {{in call to 'scalar(3)'}}
+
+constexpr int array(int a) {
+  int arr[3]; // cxx14-warning {{uninitialized variable in a constexpr function is a C++20 extension}}
+  arr[1] += a; // expected-note {{read of uninitialized object}};
+  return 0;
+}
+static_assert(array(3), ""); // expected-error {{constant expression}} \
+ // expected-note {{in call to 'array(3)'}}
+
+struct Foo {
+  int val; // cxx14-note{{member not initialized by constructor}}
+  constexpr Foo() {} // cxx14-warning {{constexpr constructor that does not initialize all members is a C++20 extension}}
+};
+constexpr int field(int a) {
+  Foo f;
+  f.val += a; // expected-note {{read of uninitialized object}};
+  return 0;
+}
+static_assert(field(3), ""); // expected-error {{constant expression}} \
+ // expected-note {{in call to 'field(3)'}}
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -4442,6 +4442,10 @@
   return foundPointer(Subobj, SubobjType);
 case APValue::Vector:
   return 

[PATCH] D157956: [clangd] don't add inlay hint for dependent type in structured binding

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

Currently clangd will display useless inlay hint for dependent type in
structured binding, e.g.

  template 
  void foobar(T arg) {
auto [a/*: */, b/*: */] = arg;
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157956

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1333,6 +1333,11 @@
   // FIXME: It would be nice to show "T" as the hint.
   auto $var2[[var2]] = arg;
 }
+
+template 
+void bar(T arg) {
+  auto [a, b] = arg;
+}
   )cpp");
 }
 
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -676,7 +676,8 @@
 // For structured bindings, print canonical types. This is important
 // because for bindings that use the tuple_element protocol, the
 // non-canonical types would be "tuple_element::type".
-if (auto Type = Binding->getType(); !Type.isNull())
+if (auto Type = Binding->getType();
+!Type.isNull() && !Type->isDependentType())
   addTypeHint(Binding->getLocation(), Type.getCanonicalType(),
   /*Prefix=*/": ");
   }


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1333,6 +1333,11 @@
   // FIXME: It would be nice to show "T" as the hint.
   auto $var2[[var2]] = arg;
 }
+
+template 
+void bar(T arg) {
+  auto [a, b] = arg;
+}
   )cpp");
 }
 
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -676,7 +676,8 @@
 // For structured bindings, print canonical types. This is important
 // because for bindings that use the tuple_element protocol, the
 // non-canonical types would be "tuple_element::type".
-if (auto Type = Binding->getType(); !Type.isNull())
+if (auto Type = Binding->getType();
+!Type.isNull() && !Type->isDependentType())
   addTypeHint(Binding->getLocation(), Type.getCanonicalType(),
   /*Prefix=*/": ");
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157837: [flang][driver] Update the visibility of Clang options in Flang

2023-08-15 Thread Tom Eccles via Phabricator via cfe-commits
tblah accepted this revision.
tblah added a comment.

Looks good to me, thanks for this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157837

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


[PATCH] D157151: [Driver] Refactor to use llvm Option's new Visibility flags

2023-08-15 Thread Justin Bogner via Phabricator via cfe-commits
bogner added a comment.

In D157151#4587522 , @awarzynski 
wrote:

> This might cause some disruption to downstream consumers of this API and 
> Options.td. Hopefully, "update_options_td_flags.py" that you've included 
> should minimise that. I suggest "advertising" it in the summary a bit more.
>
> LGTM, great work, thank you!
>
> When landing this, could you send a PSA to Discourse to make folks aware of 
> what's coming? I am primarily concerned about our downstream users.

Good call, and that should help a bit with advertising what to do if a 
downstream breaks. I'll do so




Comment at: llvm/unittests/Option/OptionParsingTest.cpp:18
 
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+

awarzynski wrote:
> Why not just update the test?
I'd rather not remove the tests for the old API until we actually remove the API


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157151

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


[PATCH] D157150: [Driver] Update BoolOption to handle Visibility. NFC

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

Rebase on top of "Visibility" naming.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157150

Files:
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td

Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -79,6 +79,23 @@
 // target will lead to an err_drv_unsupported_opt_for_target error.
 def TargetSpecific : OptionFlag;
 
+// Indicates that this warning is ignored, but accepted with a warning for
+// GCC compatibility.
+class IgnoredGCCCompat : Flags<[HelpHidden]> {}
+
+class TargetSpecific : Flags<[TargetSpecific]> {}
+
+/
+// Visibility
+
+// We prefer the name "ClangOption" here rather than "Default" to make
+// it clear that these options will be visible in the clang driver (as
+// opposed to clang -cc1, the CL driver, or the flang driver).
+defvar ClangOption = DefaultVis;
+
+/
+// Docs
+
 // A short name to show in documentation. The name will be interpreted as rST.
 class DocName { string DocName = name; }
 
@@ -89,12 +106,6 @@
 // documentation.
 class DocFlatten { bit DocFlatten = 1; }
 
-// Indicates that this warning is ignored, but accepted with a warning for
-// GCC compatibility.
-class IgnoredGCCCompat : Flags<[HelpHidden]> {}
-
-class TargetSpecific : Flags<[TargetSpecific]> {}
-
 /
 // Groups
 
@@ -381,7 +392,8 @@
 
 // Definition of single command line flag. This is an implementation detail, use
 // SetTrueBy or SetFalseBy instead.
-class FlagDef option_flags,
+class FlagDef option_flags, list option_vis,
   string help, list implied_by_expressions = []> {
   // The polarity. Besides spelling, this also decides whether the TableGen
   // record will be prefixed with "no_".
@@ -390,9 +402,12 @@
   // The value assigned to key path when the flag is present on command line.
   bit Value = value;
 
-  // OptionFlags that control visibility of the flag in different tools.
+  // OptionFlags in different tools.
   list OptionFlags = option_flags;
 
+  // OptionVisibility flags for different tools.
+  list OptionVisibility = option_vis;
+
   // The help text associated with the flag.
   string Help = help;
 
@@ -401,8 +416,11 @@
 }
 
 // Additional information to be appended to both positive and negative flag.
-class BothFlags option_flags, string help = ""> {
+class BothFlags option_flags,
+list option_vis = [ClangOption],
+string help = ""> {
   list OptionFlags = option_flags;
+  list OptionVisibility = option_vis;
   string Help = help;
 }
 
@@ -411,23 +429,26 @@
   FlagDef Result
 = FlagDef;
 }
 
 // Definition of the command line flag with positive spelling, e.g. "-ffoo".
-class PosFlag flags = [], string help = "",
-  list implied_by_expressions = []>
-  : FlagDef {}
+class PosFlag flags = [], list vis = [],
+  string help = "", list implied_by_expressions = []>
+  : FlagDef {}
 
 // Definition of the command line flag with negative spelling, e.g. "-fno-foo".
-class NegFlag flags = [], string help = "",
-  list implied_by_expressions = []>
-  : FlagDef {}
+class NegFlag flags = [], list vis = [],
+  string help = "", list implied_by_expressions = []>
+  : FlagDef {}
 
 // Expanded FlagDef that's convenient for creation of TableGen records.
 class FlagDefExpanded
-  : FlagDef {
+  : FlagDef {
   // Name of the TableGen record.
   string RecordName = prefix # !if(flag.Polarity, "", "no_") # name;
 
@@ -445,7 +466,8 @@
 class MarshalledFlagRec
-  : Flag<["-"], flag.Spelling>, Flags, HelpText,
+  : Flag<["-"], flag.Spelling>, Flags,
+Visibility, HelpText,
 MarshallingInfoBooleanFlag,
 ImpliedByAnyOf {}
@@ -459,7 +481,7 @@
 multiclass BoolOption> {
+  BothFlags suffix = BothFlags<[]>> {
   defvar flag1 = FlagDefExpanded.Result, prefix,
  NAME, spelling_base>;
 
@@ -490,7 +512,7 @@
 /// CompilerInvocation.
 multiclass BoolFOption> {
+   BothFlags both = BothFlags<[]>> {
   defm NAME : BoolOption<"f", flag_base, kpm, default, flag1, flag2, both>,
   Group;
 }
@@ -501,7 +523,7 @@
 // CompilerInvocation.
 multiclass BoolGOption> {
+   BothFlags both = BothFlags<[]>> {
   defm NAME : BoolOption<"g", flag_base, kpm, default, flag1, flag2, both>,
   Group;
 }
@@ -509,7 +531,7 @@
 // Works like BoolOption except without marshalling
 multiclass BoolOptionWithoutMarshalling> {
+BothFlags suffix = BothFlags<[]>> {
   defvar flag1 = FlagDefExpanded.Result, prefix,
  NAME, spelling_base>;
 
@@ -531,10 +553,12 @@
   defvar implied = !if(flag1.CanBeImplied, flag1, fla

[PATCH] D156320: [Flang][Driver] Add support for Rpass and related options

2023-08-15 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Some high level comments:

- The logic in `parseCodeGenArgs` in CompilerInvocation.cpp is a bit complex 
and quite specialized - could you move it to a dedicated method?
- In a fair few places this patch make references to "diagnostic flags" or 
"diagnostic options". That's borrowed from Clang where there's one code path 
for `-W` and `-R` flags. Note that in Clang the logic for `-W` 
is vastly more complex. This is completely absent in Flang. So, everything 
that's added here is added specifically for "remarks" and it would be helpful 
to be explicit about that.  For example, `processWarningOptions` is misleading. 
`processRemakrsOptions` would be more accurate.

Thank you :)




Comment at: flang/lib/Frontend/CompilerInvocation.cpp:227
 
+  // Specifies what passes to include. If not provided
+  // -fsave-optimization-record will include all passes.

> // Specifies what passes to include.

Could you be more specific, what passes are you referring to? Included where?



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:242
+
+  // Specify which missed passes should be reported using a regex.
+  opts.OptimizationRemarkMissed = parseOptimizationRemark(

>   // Specify which missed passes should be reported using a regex.

Reported where?



Comment at: flang/lib/Frontend/TextDiagnosticPrinter.cpp:37
+// Print any diagnostic option information to a raw_ostream.
+static void printDiagnosticOptions(llvm::raw_ostream &os,
+   clang::DiagnosticsEngine::Level level,

victorkingi wrote:
> awarzynski wrote:
> > Why is this method needed and can it be tested?
> This method prints out the pass that was done e.g. [-Rpass=inline ], 
> [-Rpass=loop-delete] next to the optimization message.
> It is tested by the full remark message emitted test in 
> flang/test/Driver/optimization-remark.f90
Flang has very _very_ limited support for warning flags. So this is going to be 
used specifically for Remarks. Please update and document accordingly.



Comment at: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:30
 #include "llvm/Support/CommandLine.h"
+#include 
 

No longer needed, right? Also, please use the the format consistent with the 
other `#include`s.



Comment at: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:117
+
+void processWarningOptions(clang::DiagnosticsEngine &diags,
+   const clang::DiagnosticOptions &opts,

awarzynski wrote:
> ?
I find this method quite confusing.

1. It doesn't process warning options - it processes remarks options (so the 
name is inaccurate).
2. It deals with `-Rpass -Rno-pass` cases (i.e. postive + negative flag), but 
that's normally done in CompilerInvocation when parsing other options. See e.g. 
https://github.com/llvm/llvm-project/blob/c52d9509d40d3048914b144618232213e6076e05/flang/lib/Frontend/CompilerInvocation.cpp#L161-L163.
 Why not use that logic instead?
3. It's been extracted from Clang - it would be very helpful to note that and 
highlight the difference between this method and similar method in Clang.
4. You can safely trim it to only deal with Remarks (so e.g. update `const 
clang::DiagnosticOptions &opts,` in the signature)

Now, I am not requesting any major refactor here - I appreciate that e.g. these 
remark flags are defined a bit differently to other flags. But this method can 
be simplified and should be documented.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156320

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


[PATCH] D157275: [Driver] Select newest GCC installation on Solaris

2023-08-15 Thread Rainer Orth via Phabricator via cfe-commits
ro marked an inline comment as done.
ro added a comment.

In D157275#4585184 , @MaskRay wrote:

> Thanks for the update. Regarding testing, it seems that unittests will be 
> more convenience than creating so many placeholder files in `Inputs/`. 
> `clang/unittests/Driver/ToolChainTest.cpp` `TEST(ToolChainTest, 
> VFSGCCInstallation)` has an example for Linux. You can add another for 
> Solaris.

TBH, I'm quite sceptical about the unittest framework here: we already have 
2300+ empty files in `clang/test/Driver`, so adding 12 more shouldn't be such a 
big deal.  With a real in-filesystem tree, I can quickly test various 
scenarious with `clang -v --sysroot`, while this isn't possible with the 
unittest framework (which I find way harder to read).  I'm adding the unittest 
nonetheless, but would prefer to keep the `lit`-based test instead.




Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2258
 
-  Prefixes.push_back(CandidatePrefix);
+  SolarisPrefixes.push_back(CandidatePrefix);
 }

MaskRay wrote:
> It's better to use https://en.wikipedia.org/wiki/Schwartzian_transform here 
> to avoid calling `llvm::sys::path::filename` and 
> `Generic_GCC::GCCVersion::Parse` in the comparator. Then the comparator is 
> just `A < B` and can just be removed.
This is way shorter and efficient indeed.  Patch updated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157275

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


[PATCH] D157275: [Driver] Select newest GCC installation on Solaris

2023-08-15 Thread Rainer Orth via Phabricator via cfe-commits
ro updated this revision to Diff 550226.
ro marked an inline comment as done.
ro added a comment.
Herald added a subscriber: ormris.

- Simplify `SolarisPrefixes` sorting.
- Switch to unitest`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157275

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/unittests/Driver/ToolChainTest.cpp

Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -168,6 +168,155 @@
 S);
 }
 
+TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  struct TestDiagnosticConsumer : public DiagnosticConsumer {};
+  IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+
+  const char *EmptyFiles[] = {
+  // Sort entries so the latest version doesn't come first.
+  "/usr/gcc/7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0/32/crtbegin.o",
+  "/usr/gcc/7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0/crtbegin.o",
+  "/usr/gcc/7/lib/gcc/x86_64-pc-solaris2.11/7.5.0/32/crtbegin.o",
+  "/usr/gcc/7/lib/gcc/x86_64-pc-solaris2.11/7.5.0/crtbegin.o",
+  "/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0/crtbegin.o",
+  "/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0/sparcv8plus/"
+  "crtbegin.o",
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0/32/crtbegin.o",
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0/crtbegin.o",
+  "/usr/gcc/4.7/lib/gcc/i386-pc-solaris2.11/4.7.3/amd64/crtbegin.o",
+  "/usr/gcc/4.7/lib/gcc/i386-pc-solaris2.11/4.7.3/crtbegin.o",
+  "/usr/gcc/4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3/crtbegin.o",
+  "/usr/gcc/4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3/sparcv9/crtbegin.o",
+  };
+
+  for (const char *Path : EmptyFiles)
+InMemoryFileSystem->addFile(Path, 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+
+  {
+DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+Driver TheDriver("/bin/clang", "i386-pc-solaris2.11", Diags,
+ "clang LLVM compiler", InMemoryFileSystem);
+std::unique_ptr C(
+TheDriver.BuildCompilation({"-v", "--gcc-toolchain=", "--sysroot="}));
+ASSERT_TRUE(C);
+std::string S;
+{
+  llvm::raw_string_ostream OS(S);
+  C->getDefaultToolChain().printVerboseInfo(OS);
+}
+if (is_style_windows(llvm::sys::path::Style::native))
+  std::replace(S.begin(), S.end(), '\\', '/');
+EXPECT_EQ("Found candidate GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Selected GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Candidate multilib: .;@m64\n"
+  "Candidate multilib: 32;@m32\n"
+  "Selected multilib: 32;@m32\n",
+  S);
+  }
+
+  {
+DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+Driver TheDriver("/bin/clang", "amd64-pc-solaris2.11", Diags,
+ "clang LLVM compiler", InMemoryFileSystem);
+std::unique_ptr C(
+TheDriver.BuildCompilation({"-v", "--gcc-toolchain=", "--sysroot="}));
+ASSERT_TRUE(C);
+std::string S;
+{
+  llvm::raw_string_ostream OS(S);
+  C->getDefaultToolChain().printVerboseInfo(OS);
+}
+if (is_style_windows(llvm::sys::path::Style::native))
+  std::replace(S.begin(), S.end(), '\\', '/');
+EXPECT_EQ("Found candidate GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Selected GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Candidate multilib: .;@m64\n"
+  "Candidate multilib: 32;@m32\n"
+  "Selected multilib: .;@m64\n",
+  S);
+  }
+
+  {
+DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+Driver TheDriver("/bin/clang", "x86_64-pc-solaris2.11", Diags,
+ "clang LLVM compiler", InMemoryFileSystem);
+std::unique_ptr C(
+TheDriver.BuildCompilation({"-v", "--gcc-toolchain=", "--sysroot="}));
+ASSERT_TRUE(C);
+std::string S;
+{
+  llvm::raw_string_ostream OS(S);
+  C->getDefaultToolChain().printVerboseInfo(OS);
+}
+if (is_style_windows(llvm::sys::path::Style::native))
+  std::replace(S.begin(), S.end(), '\\', '/');
+EXPECT_EQ("Found candidate GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Selected GCC installation: "
+  "/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0\n"
+  "Candidate multilib: .;@m64\n"
+  "Candidate multilib: 32;@m32\n"
+  

[PATCH] D156320: [Flang][Driver] Add support for Rpass and related options

2023-08-15 Thread victorkingi via Phabricator via cfe-commits
victorkingi updated this revision to Diff 550232.
victorkingi marked 5 inline comments as done.
victorkingi added a comment.

code refactoring


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156320

Files:
  flang/include/flang/Frontend/CodeGenOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/Frontend/TextDiagnosticPrinter.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/optimization-remark.f90

Index: flang/test/Driver/optimization-remark.f90
===
--- /dev/null
+++ flang/test/Driver/optimization-remark.f90
@@ -0,0 +1,52 @@
+! This file tests the -Rpass family of flags (-Rpass, -Rpass-missed
+! and -Rpass-analysis)
+! loop-delete isn't enabled at O0 so we use at least O1
+
+! Check that we can override -Rpass= with -Rno-pass.
+! RUN: %flang_fc1 %s -O1 -Rpass -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
+! RUN: %flang_fc1 %s -O1 -Rpass -Rno-pass -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-REMARKS
+
+! Check "unknown remark option" warning
+! RUN: %flang %s -O1 -R 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-WARN
+
+! Check "unknown remark option" warning with suggestion
+! RUN: %flang %s -O1 -Rpas 2>&1 | FileCheck %s --check-prefix=CHECK-WARN-SUGGEST
+
+! Check -Rno-pass, -Rno-pass-analysis, -Rno-pass-missed nothing emitted
+! RUN: %flang %s -O1 -Rno-pass 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+! RUN: %flang %s -O1 -Rno-pass-missed 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+! RUN: %flang %s -O1 -Rno-pass-analysis 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+
+! Check full -Rpass message is emitted
+! RUN: %flang %s -O1 -Rpass 2>&1 | FileCheck %s
+
+! Check full -Rpass-missed message is emitted
+! RUN: %flang %s -O1 -Rpass-missed 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-MISSED
+
+! Check full -Rpass-analysis message is emitted
+! RUN: %flang %s -O1 -Rpass-analysis 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-ANALYSIS
+
+! CHECK: optimization-remark.f90:48:5: remark: Loop deleted because it is invariant [-Rpass=loop-delete]
+! CHECK-REMARKS-MISSED: optimization-remark.f90:43:5: remark: loop not vectorized [-Rpass-missed=loop-vectorize]
+! CHECK-REMARKS-ANALYSIS: optimization-remark.f90:43:5: remark: loop not vectorized: instruction cannot be vectorized [-Rpass-analysis=loop-vectorize]
+! CHECK-REMARKS: remark:
+! CHECK-NO-REMARKS-NOT: remark:
+
+! CHECK-REMARKS-WARN: warning: unknown remark option '-R' [-Wunknown-warning-option]
+! CHECK-WARN-SUGGEST: warning: unknown remark option '-Rpas'; did you mean '-Rpass'? [-Wunknown-warning-option]
+
+program forttest
+implicit none
+real, dimension(1:50) :: aR1
+integer :: n
+
+do n = 1,50
+aR1(n) = n * 1.34
+print *, "hello"
+end do
+
+do n = 1,50
+aR1(n) = n * 1.34
+end do
+
+end program forttest
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -27,6 +27,7 @@
 #include "llvm/Option/Option.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/CommandLine.h"
+#include 
 
 namespace Fortran::frontend {
 
@@ -100,6 +101,61 @@
   llvm_unreachable("Invalid program action!");
 }
 
+// Emit a warning and typo hint for unknown warning opts
+static void emitUnknownDiagWarning(clang::DiagnosticsEngine &diags,
+   clang::diag::Flavor flavor,
+   llvm::StringRef prefix,
+   llvm::StringRef opt) {
+  llvm::StringRef suggestion =
+  clang::DiagnosticIDs::getNearestOption(flavor, opt);
+  diags.Report(clang::diag::warn_unknown_diag_option)
+  << (flavor == clang::diag::Flavor::WarningOrError ? 0 : 1)
+  << (prefix.str() += std::string(opt)) << !suggestion.empty()
+  << (prefix.str() += std::string(suggestion));
+}
+
+static void processWarningOptions(clang::DiagnosticsEngine &diags,
+  const clang::DiagnosticOptions &opts,
+  bool reportDiags = true) {
+
+  llvm::SmallVector _diags;
+  const llvm::IntrusiveRefCntPtr diagIDs =
+  diags.getDiagnosticIDs();
+  // We parse the warning options twice.  The first pass sets diagnostic state,
+  // while the second pass reports warnings/errors.  This has the effect that
+  // we follow the more canonical "last option wins" paradigm when there are
+  // conflicting options.
+  for (unsigned report = 0, reportEnd = 2; report != reportEnd; ++report) {
+bool setDiagnostic = (report == 0);
+
+// If we've set the diagnostic state and are not reporting 

[PATCH] D151730: [RISCV] Support target attribute for function

2023-08-15 Thread Piyou Chen via Phabricator via cfe-commits
BeMg updated this revision to Diff 550237.
BeMg added a comment.

rebase and update testcase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151730

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/test/CodeGen/RISCV/riscv-func-attr-target.c

Index: clang/test/CodeGen/RISCV/riscv-func-attr-target.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/riscv-func-attr-target.c
@@ -0,0 +1,19 @@
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +zifencei \
+// RUN:  -target-feature +m -target-feature +a   \
+// RUN:  -target-feature +f -target-feature +d   \
+// RUN:  -emit-llvm %s -o - | FileCheck %s   \
+// RUN:  --check-prefix=CHECK-IR
+
+// CHECK-IR: void @test1() #0
+__attribute__((target("arch=-a,+v,+zbb,+zicond1p0"))) void test1() {}
+
+// CHECK-IR: void @test2() #1
+__attribute__((target("arch=rv64gc_zbb"))) void test2 () {}
+
+// CHECK-IR: void @test3() #2
+__attribute__((target("cpu=rocket-rv64;tune=generic-rv64;arch=+v"))) void test3 () {}
+
+// CHECK-IR: attributes #0 {{.*}}+experimental-zicond{{.*}}+v,+zbb{{.*}}+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-a{{.*}}
+// CHECK-IR: attributes #1 {{.*}}+c{{.*}}+zbb{{.*}}
+// CHECK-IR: attributes #2 {{.*}} "target-cpu"="rocket-rv64" {{.*}}+v{{.*}} "tune-cpu"="generic-rv64" {{.*}}
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -114,6 +114,9 @@
   void fillValidCPUList(SmallVectorImpl &Values) const override;
   bool isValidTuneCPUName(StringRef Name) const override;
   void fillValidTuneCPUList(SmallVectorImpl &Values) const override;
+  bool supportsTargetAttributeTune() const override { return true; }
+  bool validateCpuSupports(StringRef FeatureStr) const override;
+  ParsedTargetAttr parseTargetAttr(StringRef Str) const override;
 };
 class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
 public:
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -250,12 +250,17 @@
 
   // RISCVISAInfo makes implications for ISA features
   std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  std::vector UpdatedFeatures;
+
   // Add non-ISA features like `relax` and `save-restore` back
   for (const std::string &Feature : FeaturesVec)
 if (!llvm::is_contained(ImpliedFeatures, Feature))
-  ImpliedFeatures.push_back(Feature);
+  UpdatedFeatures.push_back(Feature);
+
+  UpdatedFeatures.insert(UpdatedFeatures.end(), ImpliedFeatures.begin(),
+ ImpliedFeatures.end());
 
-  return TargetInfo::initFeatureMap(Features, Diags, CPU, ImpliedFeatures);
+  return TargetInfo::initFeatureMap(Features, Diags, CPU, UpdatedFeatures);
 }
 
 std::optional>
@@ -346,3 +351,77 @@
   bool Is64Bit = getTriple().isArch64Bit();
   llvm::RISCV::fillValidTuneCPUArchList(Values, Is64Bit);
 }
+
+// Parse RISC-V Target attributes, which are a comma separated list of:
+//  "arch=" - parsed to features as per -march=..
+//  "cpu=" - parsed to features as per -mcpu=.., with CPU set to 
+//  "tune=" - TuneCPU set to 
+ParsedTargetAttr RISCVTargetInfo::parseTargetAttr(StringRef Features) const {
+  ParsedTargetAttr Ret;
+  if (Features == "default")
+return Ret;
+  SmallVector AttrFeatures;
+  Features.split(AttrFeatures, ";");
+  bool FoundArch = false;
+
+  for (auto &Feature : AttrFeatures) {
+Feature = Feature.trim();
+StringRef AttrString = Feature.split("=").second.trim();
+
+if (Feature.startswith("arch=")) {
+  if (FoundArch)
+Ret.Duplicate = "arch=";
+  FoundArch = true;
+
+  if (AttrString.startswith("+") || AttrString.startswith("-")) {
+// EXTENSION like arch=+v,+zbb,-c
+SmallVector Exts;
+AttrString.split(Exts, ",");
+for (auto Ext : Exts) {
+  if (Ext.empty())
+continue;
+
+  StringRef ExtName = Ext.substr(1);
+  std::string TargetFeature =
+  llvm::RISCVISAInfo::getTargetFeatureForExtension(ExtName);
+  if (!TargetFeature.empty())
+Ret.Features.push_back(Ext.front() + TargetFeature);
+  else
+Ret.Features.push_back(Ext.str());
+}
+  } else {
+// full-arch-string like arch=rv64gcv
+auto RII = llvm::RISCVISAInfo::parseArchString(
+AttrString, /* EnableExperimentalExtension */ true);
+if (!RII) {
+  consumeError(RII.takeError());
+} else {
+  std::vector FeatStrings = (*RII)->toFeatureVector();
+  for (auto FeatString : FeatStrings)
+Ret

[PATCH] D152423: [RISCV] Add function that check extension name with version

2023-08-15 Thread Piyou Chen via Phabricator via cfe-commits
BeMg updated this revision to Diff 550238.
BeMg added a comment.

revert last patch because it's wrong one


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152423

Files:
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/unittests/Support/RISCVISAInfoTest.cpp


Index: llvm/unittests/Support/RISCVISAInfoTest.cpp
===
--- llvm/unittests/Support/RISCVISAInfoTest.cpp
+++ llvm/unittests/Support/RISCVISAInfoTest.cpp
@@ -604,3 +604,25 @@
   EXPECT_EQ(ExtsRV64IDZce.count("zcmp"), 1U);
   EXPECT_EQ(ExtsRV64IDZce.count("zcmt"), 1U);
 }
+
+TEST(isSupportedExtensionWithVersion, AcceptsSingleExtensionWithVersion) {
+  EXPECT_TRUE(RISCVISAInfo::isSupportedExtensionWithVersion("zbb1p0"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zbb"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zfoo1p0"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zfoo"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion(""));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("c2p0zbb1p0"));
+}
+
+TEST(getTargetFeatureForExtension, RetrieveTargetFeatureFromOneExt) {
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zbb"), "zbb");
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zicond1p0"),
+"experimental-zicond");
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zicond"),
+"experimental-zicond");
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zihintntl1234p4321"),
+"");
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zfoo"), "");
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension(""), "");
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zbbzihintntl"), "");
+}
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -1249,3 +1249,40 @@
   }
   llvm_unreachable("Invalid XLEN");
 }
+
+bool RISCVISAInfo::isSupportedExtensionWithVersion(StringRef Ext) {
+  if (Ext.empty())
+return false;
+
+  auto Pos = findLastNonVersionCharacter(Ext) + 1;
+  StringRef Name = Ext.substr(0, Pos);
+  StringRef Vers = Ext.substr(Pos);
+  if (Vers.empty())
+return false;
+
+  unsigned Major, Minor, ConsumeLength;
+  if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
+   true, true)) {
+consumeError(std::move(E));
+return false;
+  }
+
+  return true;
+}
+
+std::string RISCVISAInfo::getTargetFeatureForExtension(StringRef Ext) {
+  if (Ext.empty())
+return std::string();
+
+  auto Pos = findLastNonVersionCharacter(Ext) + 1;
+  StringRef Name = Ext.substr(0, Pos);
+
+  if (Pos != Ext.size() && !isSupportedExtensionWithVersion(Ext))
+return std::string();
+
+  if (!isSupportedExtension(Name))
+return std::string();
+
+  return isExperimentalExtension(Name) ? "experimental-" + Name.str()
+   : Name.str();
+}
Index: llvm/include/llvm/Support/RISCVISAInfo.h
===
--- llvm/include/llvm/Support/RISCVISAInfo.h
+++ llvm/include/llvm/Support/RISCVISAInfo.h
@@ -85,10 +85,12 @@
 
   static bool isSupportedExtensionFeature(StringRef Ext);
   static bool isSupportedExtension(StringRef Ext);
+  static bool isSupportedExtensionWithVersion(StringRef Ext);
   static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
unsigned MinorVersion);
   static llvm::Expected>
   postProcessAndChecking(std::unique_ptr &&ISAInfo);
+  static std::string getTargetFeatureForExtension(StringRef Ext);
 
 private:
   RISCVISAInfo(unsigned XLen)


Index: llvm/unittests/Support/RISCVISAInfoTest.cpp
===
--- llvm/unittests/Support/RISCVISAInfoTest.cpp
+++ llvm/unittests/Support/RISCVISAInfoTest.cpp
@@ -604,3 +604,25 @@
   EXPECT_EQ(ExtsRV64IDZce.count("zcmp"), 1U);
   EXPECT_EQ(ExtsRV64IDZce.count("zcmt"), 1U);
 }
+
+TEST(isSupportedExtensionWithVersion, AcceptsSingleExtensionWithVersion) {
+  EXPECT_TRUE(RISCVISAInfo::isSupportedExtensionWithVersion("zbb1p0"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zbb"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zfoo1p0"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zfoo"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion(""));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("c2p0zbb1p0"));
+}
+
+TEST(getTargetFeatureForExtension, RetrieveTargetFeatureFromOneExt) {
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zbb"), "zbb");
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zicond1p0"),
+  

[PATCH] D152495: [Clang][SemaCXX] Add unused warning for variables declared in condition expressions

2023-08-15 Thread NAKAMURA Takumi via Phabricator via cfe-commits
chapuni added a comment.

Would this cause many warnings in Clang/LLVM tree?
https://lab.llvm.org/buildbot/#/builders/36/builds/36560

I hope you to fix possible warnings at first.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152495

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


[PATCH] D152495: [Clang][SemaCXX] Add unused warning for variables declared in condition expressions

2023-08-15 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added a comment.

In D152495#4587804 , @chapuni wrote:

> Would this cause many warnings in Clang/LLVM tree?
> https://lab.llvm.org/buildbot/#/builders/36/builds/36560
>
> I hope you to fix possible warnings at first.

Thanks. I'll revert this change.
I was thinking of pushing speculative fixes upstream, but the lines that need 
fixing are not only a few lines, so I now think it needs a review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152495

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


[PATCH] D157379: [CodeGen] Restrict addEmittedDeferredDecl to incremental extensions

2023-08-15 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev accepted this revision.
v.g.vassilev added a comment.
This revision is now accepted and ready to land.

@Hahnfeld, let's move forward and rely on a post-commit review here if 
necessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157379

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


[clang] 5aded52 - Revert "Reland "[Clang][SemaCXX] Add unused warning for variables declared in condition expressions""

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

Author: Takuya Shimizu
Date: 2023-08-15T19:54:51+09:00
New Revision: 5aded521ea94810b81369eaa951dcf59ad5ab82d

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

LOG: Revert "Reland "[Clang][SemaCXX] Add unused warning for variables declared 
in condition expressions""

This causes a lot of warning in sanitizer build:
https://lab.llvm.org/buildbot/#/builders/258/builds/5424
https://lab.llvm.org/buildbot/#/builders/36/builds/36560

This reverts commit 8e329caa944c377c51ef567d5aa67cfac9ffd0fa.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaCXX/warn-unused-variables.cpp
llvm/lib/Support/VirtualFileSystem.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 96a9ec14112292..cd7beff546c932 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -129,9 +129,6 @@ Improvements to Clang's diagnostics
   of a base class is not called in the constructor of its derived class.
 - Clang no longer emits ``-Wmissing-variable-declarations`` for variables 
declared
   with the ``register`` storage class.
-- Clang now warns on unused variables declared and initialized in condition
-  expressions.
-  (`#61681: `_)
 
 Bug Fixes in This Version
 -

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index db1cd28f7b5a93..0ad807cca36c7b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1995,7 +1995,7 @@ static bool ShouldDiagnoseUnusedDecl(const LangOptions 
&LangOpts,
   return false;
   } else if (!D->getDeclName()) {
 return false;
-  } else if (D->isReferenced() || (!isa(D) && D->isUsed())) {
+  } else if (D->isReferenced() || D->isUsed()) {
 return false;
   }
 

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 17fda20c1ca11c..e6eb9508f8e6ff 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4015,10 +4015,6 @@ ExprResult Sema::CheckConditionVariable(VarDecl 
*ConditionVar,
   ConditionVar, ConditionVar->getType().getNonReferenceType(), VK_LValue,
   ConditionVar->getLocation());
 
-  // Ensure that `-Wunused-variable` will be emitted for condition variables
-  // that are not referenced later. e.g.: if (int var = init());
-  ConditionVar->setReferenced(/*R=*/false);
-
   switch (CK) {
   case ConditionKind::Boolean:
 return CheckBooleanCondition(StmtLoc, Condition.get());

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 522ec12de3d368..f78d46f5950360 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5352,7 +5352,7 @@ void Sema::BuildVariableInstantiation(
   // will have been deferred.
   if (!NewVar->isInvalidDecl() &&
   NewVar->getDeclContext()->isFunctionOrMethod() &&
-  OldVar->getType()->isDependentType() && !OldVar->isImplicit())
+  OldVar->getType()->isDependentType())
 DiagnoseUnusedDecl(NewVar);
 }
 

diff  --git a/clang/test/SemaCXX/warn-unused-variables.cpp 
b/clang/test/SemaCXX/warn-unused-variables.cpp
index db33086436d3af..4db8bdf12e5de0 100644
--- a/clang/test/SemaCXX/warn-unused-variables.cpp
+++ b/clang/test/SemaCXX/warn-unused-variables.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++1y-extensions -verify %s
-// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++14-extensions -Wno-c++17-extensions -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++1y-extensions -verify -std=c++11 %s
 template void f() {
   T t;
   t = 17;
@@ -294,115 +294,3 @@ void RAIIWrapperTest() {
 }
 
 } // namespace gh54489
-
-namespace inside_condition {
-  void ifs() {
-if (int hoge = 0) // expected-warning {{unused variable 'hoge'}}
-  return;
-if (const int const_hoge = 0) // expected-warning {{unused variable 
'const_hoge'}}
-  return;
-else if (int fuga = 0)
-  (void)fuga;
-else if (int used = 1; int catched = used) // expected-warning {{unused 
variable 'catched'}}
-  return;
-else if (int refed = 1; int used = refed)
-  (void)used;
-else if (int unused1 = 2; int unused2 = 3) // expected-warning {{unused 
variable 'unused1'}} \
-   // expected-warning {{unused 
variable 'unused2'}}
-  return;
-else if (int unused = 4; int used = 5) // expected-warning {{unused 
variable 'unused'}}
-  (void)used;
-else if (int used = 

[PATCH] D156537: [CodeGen] Keep track of eagerly emitted globals

2023-08-15 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev accepted this revision.
v.g.vassilev added a comment.
This revision is now accepted and ready to land.

@Hahnfeld, let's move forward and rely on a post-commit review here if 
necessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156537

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


[PATCH] D157962: [GNU ObjC] Unconditionally emit section markers.

2023-08-15 Thread David Chisnall via Phabricator via cfe-commits
theraven created this revision.
Herald added a project: All.
theraven requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In the GNUstep v2 ABI (on ELF), we rely on the linker-inserted section
start and stop markers.  These only exist when binary has something in
the relevant sections.  To ensure that they exist, compilation units
that omit one of the components emit an empty object into the section
that it's not putting anything in.  These empty objects are COMDATs and
are merged in the final version.

Unfortunately, there is a corner case where the entry exists in the code
emitted by the front end but is then elided during optimisation.  We
already unconditionally emitted an empty selector to avoid this case for
message sends but it was still a problem for constant strings.

This change unconditionally emits these placeholders for everything.
This results in very slightly larger .o files but ensures that any
future optimisation that elides more things will not prevent compilation
and so reduces fragility.

Fixes #47536


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157962

Files:
  clang/lib/CodeGen/CGObjCGNU.cpp


Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1614,32 +1614,24 @@
 if (!CGM.getTriple().isOSBinFormatCOFF()) {
   createNullGlobal(".objc_null_selector", {NULLPtr, NULLPtr},
   sectionName());
-  if (Categories.empty())
-createNullGlobal(".objc_null_category", {NULLPtr, NULLPtr,
-  NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr},
-sectionName());
-  if (!EmittedClass) {
-createNullGlobal(".objc_null_cls_init_ref", NULLPtr,
-sectionName());
-createNullGlobal(".objc_null_class_ref", { NULLPtr, NULLPtr },
-sectionName());
-  }
-  if (!EmittedProtocol)
-createNullGlobal(".objc_null_protocol", {NULLPtr, NULLPtr, NULLPtr,
-NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr,
-NULLPtr}, sectionName());
-  if (!EmittedProtocolRef)
-createNullGlobal(".objc_null_protocol_ref", {NULLPtr},
-sectionName());
-  if (ClassAliases.empty())
-createNullGlobal(".objc_null_class_alias", { NULLPtr, NULLPtr },
-sectionName());
-  if (ConstantStrings.empty()) {
-auto i32Zero = llvm::ConstantInt::get(Int32Ty, 0);
-createNullGlobal(".objc_null_constant_string", { NULLPtr, i32Zero,
-i32Zero, i32Zero, i32Zero, NULLPtr },
-sectionName());
-  }
+  createNullGlobal(".objc_null_category", {NULLPtr, NULLPtr,
+NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr},
+  sectionName());
+  createNullGlobal(".objc_null_cls_init_ref", NULLPtr,
+  sectionName());
+  createNullGlobal(".objc_null_class_ref", { NULLPtr, NULLPtr },
+  sectionName());
+  createNullGlobal(".objc_null_protocol", {NULLPtr, NULLPtr, NULLPtr,
+  NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr,
+  NULLPtr}, sectionName());
+  createNullGlobal(".objc_null_protocol_ref", {NULLPtr},
+  sectionName());
+  createNullGlobal(".objc_null_class_alias", { NULLPtr, NULLPtr },
+  sectionName());
+  auto i32Zero = llvm::ConstantInt::get(Int32Ty, 0);
+  createNullGlobal(".objc_null_constant_string", { NULLPtr, i32Zero,
+  i32Zero, i32Zero, i32Zero, NULLPtr },
+  sectionName());
 }
 ConstantStrings.clear();
 Categories.clear();


Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1614,32 +1614,24 @@
 if (!CGM.getTriple().isOSBinFormatCOFF()) {
   createNullGlobal(".objc_null_selector", {NULLPtr, NULLPtr},
   sectionName());
-  if (Categories.empty())
-createNullGlobal(".objc_null_category", {NULLPtr, NULLPtr,
-  NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr},
-sectionName());
-  if (!EmittedClass) {
-createNullGlobal(".objc_null_cls_init_ref", NULLPtr,
-sectionName());
-createNullGlobal(".objc_null_class_ref", { NULLPtr, NULLPtr },
-sectionName());
-  }
-  if (!EmittedProtocol)
-createNullGlobal(".objc_null_protocol", {NULLPtr, NULLPtr, NULLPtr,
-NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr,
-NULLPtr}, sectionName());
-  if (!EmittedProtocolRef)
-createNullGlobal(".objc_null_protocol_ref", {NULLPtr},
-sectionName());
-  if (ClassAliases.empty())
-createNullGlobal(".objc_null_class_alias", { NULLPtr, NULLPtr },
-sectionName());
-  if (ConstantStrings.e

[PATCH] D156537: [CodeGen] Keep track of eagerly emitted globals

2023-08-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D156537#4587832 , @v.g.vassilev 
wrote:

> @Hahnfeld, let's move forward and rely on a post-commit review here if 
> necessary.

Because one of the codegen code owners has been active on the thread with 
concerns, I think it's better to wait a bit longer for an explicit sign-off 
that those concerns are addressed (this code impacts more than clang-repl).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156537

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


[PATCH] D157963: [clang-format] Annotate constructor/destructor names

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

Annotate constructor/destructor names as `FunctionDeclarationName`.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157963

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1589,6 +1589,54 @@
   Tokens = annotate("void f [[noreturn]] () {}");
   ASSERT_EQ(Tokens.size(), 12u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("class Foo { public: Foo(); };");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("class Foo { public: ~Foo(); };");
+  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("struct Foo { [[deprecated]] Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { [[deprecated]] ~Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { Foo() [[deprecated]] {} };");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { ~Foo() [[deprecated]] {} };");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { [[deprecated]] explicit Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { virtual [[deprecated]] ~Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("Foo::Foo() {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("Foo::~Foo() {}");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_FunctionLBrace);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsC11GenericSelection) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16537,7 +16537,7 @@
 
   verifyFormat("int f();", SpaceFuncDef);
   verifyFormat("void f (int a, T b) {}", SpaceFuncDef);
-  verifyFormat("A::A() : a(1) {}", SpaceFuncDef);
+  verifyFormat("A::A () : a(1) {}", SpaceFuncDef);
   verifyFormat("void f() __attribute__((asdf));", SpaceFuncDef);
   verifyFormat("#define A(x) x", SpaceFuncDef);
   verifyFormat("#define A (x) x", SpaceFuncDef);
@@ -16562,7 +16562,7 @@
   // verifyFormat("T A::operator() () {}", SpaceFuncDef);
   verifyFormat("auto lambda = [] () { return 0; };", SpaceFuncDef);
   verifyFormat("int x = int(y);", SpaceFuncDef);
-  verifyFormat("M(std::size_t R, std::size_t C) : C(C), data(R) {}",
+  verifyFormat("M (std::size_t R, std::size_t C) : C(C), data(R) {}",
SpaceFuncDef);
 
   FormatStyle SpaceIfMacros = getLLVMStyle();
@@ -26220,18 +26220,18 @@
   FormatStyle Style = getLLVMStyle();
   EXPECT_EQ(Style.BreakAfterAttributes, FormatStyle::ABS_Never);
 
-  const StringRef Code("[[nodiscard]] inline int f(int &i);\n"
-   "[[foo([[]])]] [[nodiscard]]\n"
-   "int g(int &i);\n"
-   "[[nodiscard]]\n"
-   "inline int f(int &i) {\n"
-   "  i = 1;\n"
-   "  return 0;\n"
-   "}\n"
-   "[[foo([[]])]] [[nodiscard]] int g(int &i) {\n"
-   "  i = 0;\n"
-   "  return 1;\n"
-  

[PATCH] D155081: Specify the developer policy around links to external resources

2023-08-15 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG677326999f27: Specify the developer policy around links to 
external resources (authored by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155081

Files:
  llvm/docs/DeveloperPolicy.rst


Index: llvm/docs/DeveloperPolicy.rst
===
--- llvm/docs/DeveloperPolicy.rst
+++ llvm/docs/DeveloperPolicy.rst
@@ -201,6 +201,11 @@
   entire failing program into ``llvm/test`` as this creates a *time-to-test*
   burden on all developers. Please keep them short.
 
+* Avoid adding links to resources that are not available to the entire
+  community, such as links to private bug trackers, internal corporate
+  documentation, etc. Instead, add sufficient comments to the test to provide
+  the context behind such links.
+
 Note that llvm/test and clang/test are designed for regression and small 
feature
 tests only. More extensive test cases (e.g., entire applications, benchmarks,
 etc) should be added to the ``llvm-test`` test suite.  The llvm-test suite is
@@ -256,6 +261,11 @@
the change (more invasive changes require more testing). A reasonable subset
might be something like "``llvm-test/MultiSource/Benchmarks``".
 
+#. Ensure that links in source code and test files point to publicly available
+   resources and are used primarily to add additional information rather than
+   to supply critical context. The surrounding comments should be sufficient
+   to provide the context behind such links.
+
 Additionally, the committer is responsible for addressing any problems found in
 the future that the change is responsible for.  For example:
 
@@ -336,8 +346,6 @@
   code snippets and gory details should be left to bug comments, web
   review or the mailing list.
 
-* If the patch fixes a bug in GitHub Issues, please include the PR# in the 
message.
-
 * Text formatting and spelling should follow the same rules as documentation
   and in-code comments, ex. capitalization, full stop, etc.
 
@@ -346,8 +354,13 @@
   related commit. This could be as simple as "Revert commit  because it
   caused PR#".
 
-* If the patch has been reviewed, add a link to its review page, as shown
-  `here `_.
+* It is acceptable to add metadata to the commit message to automate processes,
+  including for downstream consumers. If the patch fixes a bug in GitHub 
Issues,
+  we encourage adding a reference to the issue being closed, as described
+  `here `_.
+  Other kinds of metadata are also acceptable, including links to resources
+  that are not available to the entire community. However, such links should
+  not be used in place of making the commit message self-explanatory.
 
 For minor violations of these recommendations, the community normally favors
 reminding the contributor of this policy over reverting. Minor corrections and


Index: llvm/docs/DeveloperPolicy.rst
===
--- llvm/docs/DeveloperPolicy.rst
+++ llvm/docs/DeveloperPolicy.rst
@@ -201,6 +201,11 @@
   entire failing program into ``llvm/test`` as this creates a *time-to-test*
   burden on all developers. Please keep them short.
 
+* Avoid adding links to resources that are not available to the entire
+  community, such as links to private bug trackers, internal corporate
+  documentation, etc. Instead, add sufficient comments to the test to provide
+  the context behind such links.
+
 Note that llvm/test and clang/test are designed for regression and small feature
 tests only. More extensive test cases (e.g., entire applications, benchmarks,
 etc) should be added to the ``llvm-test`` test suite.  The llvm-test suite is
@@ -256,6 +261,11 @@
the change (more invasive changes require more testing). A reasonable subset
might be something like "``llvm-test/MultiSource/Benchmarks``".
 
+#. Ensure that links in source code and test files point to publicly available
+   resources and are used primarily to add additional information rather than
+   to supply critical context. The surrounding comments should be sufficient
+   to provide the context behind such links.
+
 Additionally, the committer is responsible for addressing any problems found in
 the future that the change is responsible for.  For example:
 
@@ -336,8 +346,6 @@
   code snippets and gory details should be left to bug comments, web
   review or the mailing list.
 
-* If the patch fixes a bug in GitHub Issues, please include the PR# in the message.
-
 * Text formatting and spelling should follow the same rules as documentation
   and in-code comments, ex. capitalization, full stop, etc.
 
@@ -346,8 +354,13 @@
   related commit. This could be as simple as "Revert commit NN

[PATCH] D144006: [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)

2023-08-15 Thread Vladislav Dzhidzhoev via Phabricator via cfe-commits
dzhidzhoev updated this revision to Diff 550270.
dzhidzhoev added a comment.

Rebased (on top of https://reviews.llvm.org/D155818).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144006

Files:
  clang/test/CodeGen/debug-info-codeview-unnamed.c
  clang/test/CodeGen/debug-info-unused-types.c
  clang/test/CodeGen/debug-info-unused-types.cpp
  clang/test/CodeGenCXX/debug-info-access.cpp
  clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp
  clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
  clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
  clang/test/CodeGenCXX/debug-lambda-this.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/Bitcode/Reader/MetadataLoader.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/test/Bitcode/upgrade-cu-locals.ll
  llvm/test/Bitcode/upgrade-cu-locals.ll.bc
  llvm/test/DebugInfo/Generic/inlined-local-type.ll
  llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
  llvm/test/DebugInfo/Generic/lexical-block-types.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
  llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll
  llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
  llvm/test/DebugInfo/X86/local-type-as-template-parameter.ll
  llvm/test/DebugInfo/X86/set.ll
  llvm/test/DebugInfo/X86/split-dwarf-local-import.ll
  llvm/test/DebugInfo/X86/split-dwarf-local-import2.ll
  llvm/test/DebugInfo/X86/split-dwarf-local-import3.ll

Index: llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll
@@ -1,70 +0,0 @@
-; REQUIRES: x86_64-linux
-; RUN: %llc_dwarf -O1 -filetype=obj -split-dwarf-file=%t.dwo < %s \
-; RUN:   | llvm-dwarfdump -debug-info -   \
-; RUN:   | FileCheck %s --implicit-check-not "{{DW_TAG|NULL}}"
-
-target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-unknown-linux-gnu"
-
-; Ensure that the imported entity 'nn::A' gets emitted in 'foo()'s abstract tree
-; in the destination (where 'foo()' was inlined) compile unit.
-
-; CHECK-LABEL: .debug_info contents
-; CHECK: DW_TAG_skeleton_unit
-; CHECK:   DW_AT_dwo_name
-
-; CHECK-LABEL: .debug_info.dwo contents:
-; CHECK: DW_TAG_compile_unit
-; CHECK:   DW_AT_name ("test.cpp")
-; CHECK:   DW_AT_dwo_name
-
-; CHECK:   [[ABSTRACT_FOO:0x[0-9a-f]+]]: DW_TAG_subprogram
-; CHECK: DW_AT_name	("foo")
-; CHECK: DW_TAG_imported_declaration
-; CHECK:   DW_AT_import  ([[A:0x[0-9a-f]+]])
-; CHECK: NULL
-
-; CHECK:   DW_TAG_base_type
-; CHECK: DW_AT_name	("int")
-
-; CHECK:   DW_TAG_subprogram
-; CHECK: DW_AT_name	("main")
-; CHECK: DW_TAG_inlined_subroutine
-; CHECK:   DW_AT_abstract_origin ([[ABSTRACT_FOO]] "_Z3foov")
-; CHECK: NULL
-
-; CHECK:   DW_TAG_namespace
-; CHECK: DW_AT_name	("nn")
-; CHECK: [[A]]: DW_TAG_variable
-; CHECK:   DW_AT_name	("A")
-; CHECK: NULL
-; CHECK:   NULL
-
-define dso_local noundef i32 @main() local_unnamed_addr !dbg !20 {
-entry:
-  ret i32 42, !dbg !21
-}
-
-!llvm.dbg.cu = !{!0, !2}
-!llvm.module.flags = !{!13, !14}
-!llvm.ident = !{!19, !19}
-
-!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 15.0.0", isOptimized: true, runtimeVersion: 0, splitDebugFilename: "test.dwo", emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: GNU)
-!1 = !DIFile(filename: "test.cpp", directory: "/", checksumkind: CSK_MD5, checksum: "e7c2808ee27614e496499d55e4b37962")
-!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 15.0.0", isOptimized: true, runtimeVersion: 0, splitDebugFilename: "cu1.dwo", emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: GNU)
-!3 = !DIFile(filename: "cu1.cpp", directory: "/", checksumkind: CSK_MD5, checksum: "c0b84240ef5682b87083b33cf9038171")
-!4 = !{!5}
-!5 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !6, entity: !11, file: !3, line: 5)
-!6 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !3, file: !3, line: 5, type: !7, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !4)
-!7 = !DISubroutineType(types: !8)
-!8 = !{!9}
-!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-!10 = !{}
-!11 = distinct !DIGlobalVariable(name: "A", linkageName: "_ZN2nn1AE", scope: !12, file: !3, line: 2, type: !9, isLocal: false, isDefinition: true)
-!12 = !DINamespace(name: "nn", scope: null)
-!13 = !{i32 7, !"Dwarf Version", i32 5}
-!14 = !{i32 2, !"Debug Info Version", i32

[PATCH] D152770: [clang][ExtractAPI] Add support for Objective-C categories

2023-08-15 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/test/ExtractAPI/objc_various_categories.m:8
+// RUN: %t/myclass_1.h \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+

I don't think you need to have MyClass2 and the associated myclass2.h. It's 
fine to check that everything looks right just for the NSString categories.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152770

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


[PATCH] D157777: [ASTMatcher] Add matcher for 'MacroQualifiedType'

2023-08-15 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!




Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:7261
 
+/// Matches macro qualified types.
+///

danix800 wrote:
> aaron.ballman wrote:
> > How about: Matches qualified types when the qualifier is applied via a 
> > macro.
> > 
> > and then a second example like:
> > ```
> > int * const qual_ptr;
> > 
> > #define nonnull _Nonnull
> > int * const nonnull macro_qual_ptr;
> > ```
> > where we match `macro_qual_ptr` but not `qual_ptr`.
> > How about: Matches qualified types when the qualifier is applied via a 
> > macro.
> 
> Forgive my broken English!  :-)
> 
> > and then a second example like:
> > ```
> > int * const qual_ptr;
> > 
> > #define nonnull _Nonnull
> > int * const nonnull macro_qual_ptr;
> > ```
> > where we match `macro_qual_ptr` but not `qual_ptr`.
> 
> Thanks for reminding me of the counter-example, it's critical for better test 
> coverage.
> 
> I'll pertain to the original one but with counter-example appended, because 
> the macro
> `nonnull` in this case will not generate a `MacroQualifiedType` for 
> `macro_qual_ptr`.
> Forgive my broken English! :-)

There's nothing to forgive! :-)

> I'll pertain to the original one but with counter-example appended, because 
> the macro nonnull in this case will not generate a MacroQualifiedType for 
> macro_qual_ptr.

Oh, interesting! (I didn't test my example, so that's neat to learn.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D15

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


[clang] 98322d3 - Complete the implementation of P2361 Unevaluated string literals

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

Author: Corentin Jabot
Date: 2023-08-15T14:13:13+02:00
New Revision: 98322d3eb43168a6a64c1a15a1e754e15c04aa2f

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

LOG: Complete the implementation of P2361 Unevaluated string literals

The attributes changes were left out of Clang 17.
Attributes that used to take a string literal now accept an unevaluated
string literal instead, which means they reject numeric escape sequences
and strings literal with an encoding prefix - but the later was already
ill-formed in most cases.

We need to know that we are going to parse an unevaluated string literal
before we do - so we can reject numeric escape sequence,
so we derive from Attrs.td which attributes parameters are expected
to be string literals.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/ParsedAttr.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Parser/MicrosoftExtensions.cpp
clang/test/Parser/c2x-attributes.c
clang/test/Parser/cxx-attributes.cpp
clang/test/Parser/cxx0x-attributes.cpp
clang/test/Sema/MicrosoftExtensions.c
clang/test/Sema/annotate-type.c
clang/test/Sema/annotate.c
clang/test/Sema/attr-assume.c
clang/test/Sema/attr-btf_tag.c
clang/test/Sema/attr-btf_type_tag.c
clang/test/Sema/attr-capabilities.c
clang/test/Sema/attr-enforce-tcb-errors.cpp
clang/test/Sema/attr-enforce-tcb-errors.m
clang/test/Sema/attr-error.c
clang/test/Sema/attr-handles.cpp
clang/test/Sema/attr-section.c
clang/test/Sema/attr-tls_model.c
clang/test/Sema/attr-unavailable-message.c
clang/test/Sema/attr-warning.c
clang/test/Sema/diagnose_if.c
clang/test/Sema/enable_if.c
clang/test/SemaCXX/attr-deprecated-replacement-error.cpp
clang/test/SemaCXX/attr-no-sanitize.cpp
clang/test/SemaCXX/attr-section.cpp
clang/test/SemaCXX/attr-weakref.cpp
clang/test/SemaCXX/suppress.cpp
clang/test/SemaObjC/attr-swift_bridge.m
clang/test/SemaObjC/objc-asm-attribute-neg-test.m
clang/test/SemaObjC/validate-attr-swift_attr.m
clang/test/SemaTemplate/attributes.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cd7beff546c932..56eef72c8a2835 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -85,6 +85,9 @@ C++2c Feature Support
   int _; // Previously diagnosed under -Wunused, no longer diagnosed
 }
 
+- Attributes now expect unevaluated strings in attributes parameters that are 
string literals.
+  This is applied to both C++ standard attributes, and other attributes 
supported by Clang.
+  This completes the implementation of `P2361R6 Unevaluated Strings 
_`
 
 
 Resolutions to C++ Defect Reports

diff  --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 46a21d5da54026..195a61127c2a67 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -56,7 +56,9 @@ def err_expected_string_literal : Error<"expected string 
literal "
   "%select{in %1|for diagnostic message in static_assert|"
   "for optional message in 'availability' attribute|"
   "for %select{language name|source container name|USR}1 in "
-  "'external_source_symbol' attribute}0">;
+  "'external_source_symbol' attribute|"
+  "as argument of '%1' attribute}0">;
+
 def err_invalid_string_udl : Error<
   "string literal with user-defined suffix cannot be used here">;
 def err_invalid_character_udl : Error<

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 6312318d0ba983..c4dff165a13041 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2790,6 +2790,13 @@ class Parser : public CodeCompletionHandler {
   /// clang accepts as an extension.
   void DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs);
 
+  ExprResult ParseUnevaluatedStringInAttribute(const IdentifierInfo &AttrName);
+
+  bool
+  ParseAttributeArgumentList(const clang::IdentifierInfo &AttrName,
+ SmallVectorImpl &Exprs,
+ ParsedAttributeArgumentsProperties 
ArgsProperties);
+
   /// Parses syntax-generic attribute arguments for attributes which are
   /// known to the implementation, and adds them to the given ParsedAttributes

[PATCH] D156237: Complete the implementation of P2361 Unevaluated string literals

2023-08-15 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG98322d3eb431: Complete the implementation of P2361 
Unevaluated string literals (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156237

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Parser/MicrosoftExtensions.cpp
  clang/test/Parser/c2x-attributes.c
  clang/test/Parser/cxx-attributes.cpp
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/Sema/MicrosoftExtensions.c
  clang/test/Sema/annotate-type.c
  clang/test/Sema/annotate.c
  clang/test/Sema/attr-assume.c
  clang/test/Sema/attr-btf_tag.c
  clang/test/Sema/attr-btf_type_tag.c
  clang/test/Sema/attr-capabilities.c
  clang/test/Sema/attr-enforce-tcb-errors.cpp
  clang/test/Sema/attr-enforce-tcb-errors.m
  clang/test/Sema/attr-error.c
  clang/test/Sema/attr-handles.cpp
  clang/test/Sema/attr-section.c
  clang/test/Sema/attr-tls_model.c
  clang/test/Sema/attr-unavailable-message.c
  clang/test/Sema/attr-warning.c
  clang/test/Sema/diagnose_if.c
  clang/test/Sema/enable_if.c
  clang/test/SemaCXX/attr-deprecated-replacement-error.cpp
  clang/test/SemaCXX/attr-no-sanitize.cpp
  clang/test/SemaCXX/attr-section.cpp
  clang/test/SemaCXX/attr-weakref.cpp
  clang/test/SemaCXX/suppress.cpp
  clang/test/SemaObjC/attr-swift_bridge.m
  clang/test/SemaObjC/objc-asm-attribute-neg-test.m
  clang/test/SemaObjC/validate-attr-swift_attr.m
  clang/test/SemaTemplate/attributes.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -115,12 +115,7 @@
  
   Unevaluated strings
   https://wg21.link/P2361R6";>P2361R6
-  
-
-  Clang 17 (Partial)
-  Attributes arguments don't yet parse as unevaluated string literals.
-
-  
+  Clang 18
  
  
   Add @, $, and ` to the basic character set
Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2297,6 +2297,22 @@
  .Default(false);
 }
 
+static bool isStringLiteralArgument(const Record *Arg) {
+  return !Arg->getSuperClasses().empty() &&
+ llvm::StringSwitch(
+ Arg->getSuperClasses().back().first->getName())
+ .Case("StringArgument", true)
+ .Default(false);
+}
+
+static bool isVariadicStringLiteralArgument(const Record *Arg) {
+  return !Arg->getSuperClasses().empty() &&
+ llvm::StringSwitch(
+ Arg->getSuperClasses().back().first->getName())
+ .Case("VariadicStringArgument", true)
+ .Default(false);
+}
+
 static void emitClangAttrVariadicIdentifierArgList(RecordKeeper &Records,
raw_ostream &OS) {
   OS << "#if defined(CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST)\n";
@@ -2317,6 +2333,34 @@
   OS << "#endif // CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST\n\n";
 }
 
+// Emits the list of arguments that should be parsed as unevaluated string
+// literals for each attribute.
+static void emitClangAttrUnevaluatedStringLiteralList(RecordKeeper &Records,
+  raw_ostream &OS) {
+  OS << "#if defined(CLANG_ATTR_STRING_LITERAL_ARG_LIST)\n";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *Attr : Attrs) {
+std::vector Args = Attr->getValueAsListOfDefs("Args");
+uint32_t Bits = 0;
+assert(Args.size() <= 32 && "unsupported number of arguments in attribute");
+for (uint32_t N = 0; N < Args.size(); ++N) {
+  Bits |= (isStringLiteralArgument(Args[N]) << N);
+  // If we have a variadic string argument, set all the remaining bits to 1
+  if (isVariadicStringLiteralArgument(Args[N])) {
+Bits |= maskTrailingZeros(N);
+break;
+  }
+}
+if (!Bits)
+  continue;
+// All these spellings have at least one string literal has argument.
+forEachUniqueSpelling(*Attr, [&](const FlattenedSpelling &S) {
+  OS << ".Case(\"" << S.name() << "\", " << Bits << ")\n";
+});
+  }
+  OS << "#endif // CLANG_ATTR_STRING_LITERAL_ARG_LIST\n\n";
+}
+
 // Emits the first-argument-is-identifier property for attributes.
 static void emitClangAttrIdentifierArgList(RecordKeeper &Records, raw_ostream &OS) {
   OS << "#if defined(CLANG_ATTR_IDENTIFIER_ARG_LIST)\n";
@@ -4611,6 +4655,7 @@
   emitSourceFileHeader("Parser-related llvm::StringSwitch cases", OS);
   emitClangAttrArgContextList(Records, OS);
   emitClan

[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a reviewer: libc++.
aaron.ballman added a comment.
This revision now requires review to proceed.

LGTM but I'm adding libc++ as a blocking reviewer because there are questions 
about how well this interacts with their `stddef.h` (especially the `nullptr_t` 
bits): https://github.com/llvm/llvm-project/blob/main/libcxx/include/stddef.h




Comment at: clang/lib/Headers/stddef.h:16
+defined(__need_wint_t) ||  
\
+(defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1)
 

iana wrote:
> aaron.ballman wrote:
> > C23 K.3.1.1p2: The functions, macros, and types declared or defined in K.3 
> > and its subclauses are declared and defined by their respective headers if 
> > __STDC_WANT_LIB_EXT1__ is defined as a macro which expands to the integer 
> > constant 1 at the point in the source file where the appropriate header is 
> > first included.
> > 
> > So I don't think this should be `>= 1`. Same below. (Though I notice we 
> > seem to do this in other places, so perhaps that's more of a general 
> > cleanup we should make?)
> `>=1` is what stddef.h was already doing, so I'd vote do this later as 
> general cleanup.
That sounds reasonable to me!



Comment at: clang/test/Headers/stddef.c:7
+
+ptrdiff_t p0; // c99-error{{unknown}} c11-error{{unknown}} c23-error{{unknown}}
+size_t s0; // c99-error{{unknown}} c11-error{{unknown}} c23-error{{unknown}}

iana wrote:
> aaron.ballman wrote:
> > At least one of these `unknown` errors should be fully spelled out (the 
> > rest can then be assumed to be the same wording as the long-form).
> Let me know how this looks, I can just fully expand all of them if you 
> prefer. I was going by stddefneeds.cpp as an example.
This works fine -- I would have also been happy if only `ptrdiff_t` was fully 
spelled out and the rest used `unknown` (we can infer they're all the same 
diagnostic from that).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157757

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


[PATCH] D156320: [Flang][Driver] Add support for Rpass and related options

2023-08-15 Thread victorkingi via Phabricator via cfe-commits
victorkingi updated this revision to Diff 550280.
victorkingi marked 4 inline comments as done.
victorkingi added a comment.

code refactoring


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156320

Files:
  flang/include/flang/Frontend/CodeGenOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/Frontend/TextDiagnosticPrinter.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/optimization-remark.f90

Index: flang/test/Driver/optimization-remark.f90
===
--- /dev/null
+++ flang/test/Driver/optimization-remark.f90
@@ -0,0 +1,52 @@
+! This file tests the -Rpass family of flags (-Rpass, -Rpass-missed
+! and -Rpass-analysis)
+! loop-delete isn't enabled at O0 so we use at least O1
+
+! Check that we can override -Rpass= with -Rno-pass.
+! RUN: %flang_fc1 %s -O1 -Rpass -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
+! RUN: %flang_fc1 %s -O1 -Rpass -Rno-pass -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-REMARKS
+
+! Check "unknown remark option" warning
+! RUN: %flang %s -O1 -R 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-WARN
+
+! Check "unknown remark option" warning with suggestion
+! RUN: %flang %s -O1 -Rpas 2>&1 | FileCheck %s --check-prefix=CHECK-WARN-SUGGEST
+
+! Check -Rno-pass, -Rno-pass-analysis, -Rno-pass-missed nothing emitted
+! RUN: %flang %s -O1 -Rno-pass 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+! RUN: %flang %s -O1 -Rno-pass-missed 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+! RUN: %flang %s -O1 -Rno-pass-analysis 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+
+! Check full -Rpass message is emitted
+! RUN: %flang %s -O1 -Rpass 2>&1 | FileCheck %s
+
+! Check full -Rpass-missed message is emitted
+! RUN: %flang %s -O1 -Rpass-missed 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-MISSED
+
+! Check full -Rpass-analysis message is emitted
+! RUN: %flang %s -O1 -Rpass-analysis 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-ANALYSIS
+
+! CHECK: optimization-remark.f90:48:5: remark: Loop deleted because it is invariant [-Rpass=loop-delete]
+! CHECK-REMARKS-MISSED: optimization-remark.f90:43:5: remark: loop not vectorized [-Rpass-missed=loop-vectorize]
+! CHECK-REMARKS-ANALYSIS: optimization-remark.f90:43:5: remark: loop not vectorized: instruction cannot be vectorized [-Rpass-analysis=loop-vectorize]
+! CHECK-REMARKS: remark:
+! CHECK-NO-REMARKS-NOT: remark:
+
+! CHECK-REMARKS-WARN: warning: unknown remark option '-R' [-Wunknown-warning-option]
+! CHECK-WARN-SUGGEST: warning: unknown remark option '-Rpas'; did you mean '-Rpass'? [-Wunknown-warning-option]
+
+program forttest
+implicit none
+real, dimension(1:50) :: aR1
+integer :: n
+
+do n = 1,50
+aR1(n) = n * 1.34
+print *, "hello"
+end do
+
+do n = 1,50
+aR1(n) = n * 1.34
+end do
+
+end program forttest
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -22,6 +22,7 @@
 #include "mlir/IR/AsmState.h"
 #include "mlir/IR/MLIRContext.h"
 #include "mlir/Pass/PassManager.h"
+#include "clang/Basic/DiagnosticFrontend.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
@@ -100,6 +101,50 @@
   llvm_unreachable("Invalid program action!");
 }
 
+// Emit a warning and typo hint for unknown warning opts
+static void emitUnknownDiagWarning(clang::DiagnosticsEngine &diags,
+   clang::diag::Flavor flavor,
+   llvm::StringRef prefix,
+   llvm::StringRef opt) {
+  llvm::StringRef suggestion =
+  clang::DiagnosticIDs::getNearestOption(flavor, opt);
+  diags.Report(clang::diag::warn_unknown_diag_option)
+  << (flavor == clang::diag::Flavor::WarningOrError ? 0 : 1)
+  << (prefix.str() += std::string(opt)) << !suggestion.empty()
+  << (prefix.str() += std::string(suggestion));
+}
+
+// Remarks are ignored by default in Diagnostic.td, hence, we have to
+// enable them here before execution. Clang follows same idea using
+// ProcessWarningOptions in Warnings.cpp
+// This function is also responsible for emitting early warnings for
+// invalid -R options.
+static void processRemarkOptions(clang::DiagnosticsEngine &diags,
+ const clang::DiagnosticOptions &opts,
+ bool reportDiags = true) {
+  llvm::SmallVector _diags;
+  const llvm::IntrusiveRefCntPtr diagIDs =
+  diags.getDiagnosticIDs();
+
+  for (unsigned i = 0, e = opts.Remarks.size(); i != e; ++i) {
+llvm::StringRef

[PATCH] D157681: [clang][AST] TextNodeDumper learned to dump qualifiers (NestedNameSpecifier)

2023-08-15 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 aside from a small nit (feel free to fix when landing).




Comment at: clang/include/clang/AST/TextNodeDumper.h:205
   void dumpCleanupObject(const ExprWithCleanups::CleanupObject &C);
+  void dumpNestedNameSpecifier(NestedNameSpecifier *NNS);
 





Comment at: clang/lib/AST/TextNodeDumper.cpp:737
 
+void clang::TextNodeDumper::dumpNestedNameSpecifier(NestedNameSpecifier *NNS) {
+  if (!NNS)




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157681

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


[PATCH] D157705: [clang][AST] TextNodeDumper learned to output template specialization kind

2023-08-15 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 with a small nit (feel free to fix when landing).




Comment at: clang/lib/AST/TextNodeDumper.cpp:2053
   VisitRecordDecl(D);
+  if (auto *CTSD = dyn_cast(D))
+dumpTemplateSpecializationKind(CTSD->getSpecializationKind());




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157705

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


[PATCH] D157687: [clang][AST] TextNodeDumper learned to dump NRVO candidates of return stmts

2023-08-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Can you add test coverage for the changes?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157687

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


[PATCH] D156320: [Flang][Driver] Add support for Rpass and related options

2023-08-15 Thread victorkingi via Phabricator via cfe-commits
victorkingi updated this revision to Diff 550288.
victorkingi added a comment.

code refactoring


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156320

Files:
  flang/include/flang/Frontend/CodeGenOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/Frontend/TextDiagnosticPrinter.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/optimization-remark.f90

Index: flang/test/Driver/optimization-remark.f90
===
--- /dev/null
+++ flang/test/Driver/optimization-remark.f90
@@ -0,0 +1,52 @@
+! This file tests the -Rpass family of flags (-Rpass, -Rpass-missed
+! and -Rpass-analysis)
+! loop-delete isn't enabled at O0 so we use at least O1
+
+! Check that we can override -Rpass= with -Rno-pass.
+! RUN: %flang_fc1 %s -O1 -Rpass -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
+! RUN: %flang_fc1 %s -O1 -Rpass -Rno-pass -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-REMARKS
+
+! Check "unknown remark option" warning
+! RUN: %flang %s -O1 -R 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-WARN
+
+! Check "unknown remark option" warning with suggestion
+! RUN: %flang %s -O1 -Rpas 2>&1 | FileCheck %s --check-prefix=CHECK-WARN-SUGGEST
+
+! Check -Rno-pass, -Rno-pass-analysis, -Rno-pass-missed nothing emitted
+! RUN: %flang %s -O1 -Rno-pass 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+! RUN: %flang %s -O1 -Rno-pass-missed 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+! RUN: %flang %s -O1 -Rno-pass-analysis 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+
+! Check full -Rpass message is emitted
+! RUN: %flang %s -O1 -Rpass 2>&1 | FileCheck %s
+
+! Check full -Rpass-missed message is emitted
+! RUN: %flang %s -O1 -Rpass-missed 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-MISSED
+
+! Check full -Rpass-analysis message is emitted
+! RUN: %flang %s -O1 -Rpass-analysis 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-ANALYSIS
+
+! CHECK: optimization-remark.f90:48:5: remark: Loop deleted because it is invariant [-Rpass=loop-delete]
+! CHECK-REMARKS-MISSED: optimization-remark.f90:43:5: remark: loop not vectorized [-Rpass-missed=loop-vectorize]
+! CHECK-REMARKS-ANALYSIS: optimization-remark.f90:43:5: remark: loop not vectorized: instruction cannot be vectorized [-Rpass-analysis=loop-vectorize]
+! CHECK-REMARKS: remark:
+! CHECK-NO-REMARKS-NOT: remark:
+
+! CHECK-REMARKS-WARN: warning: unknown remark option '-R' [-Wunknown-warning-option]
+! CHECK-WARN-SUGGEST: warning: unknown remark option '-Rpas'; did you mean '-Rpass'? [-Wunknown-warning-option]
+
+program forttest
+implicit none
+real, dimension(1:50) :: aR1
+integer :: n
+
+do n = 1,50
+aR1(n) = n * 1.34
+print *, "hello"
+end do
+
+do n = 1,50
+aR1(n) = n * 1.34
+end do
+
+end program forttest
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -22,6 +22,7 @@
 #include "mlir/IR/AsmState.h"
 #include "mlir/IR/MLIRContext.h"
 #include "mlir/Pass/PassManager.h"
+#include "clang/Basic/DiagnosticFrontend.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
@@ -100,6 +101,50 @@
   llvm_unreachable("Invalid program action!");
 }
 
+// Emit a warning and typo hint for unknown warning opts
+static void emitUnknownDiagWarning(clang::DiagnosticsEngine &diags,
+   clang::diag::Flavor flavor,
+   llvm::StringRef prefix,
+   llvm::StringRef opt) {
+  llvm::StringRef suggestion =
+  clang::DiagnosticIDs::getNearestOption(flavor, opt);
+  diags.Report(clang::diag::warn_unknown_diag_option)
+  << (flavor == clang::diag::Flavor::WarningOrError ? 0 : 1)
+  << (prefix.str() += std::string(opt)) << !suggestion.empty()
+  << (prefix.str() += std::string(suggestion));
+}
+
+// Remarks are ignored by default in Diagnostic.td, hence, we have to
+// enable them here before execution. Clang follows same idea using
+// ProcessWarningOptions in Warnings.cpp
+// This function is also responsible for emitting early warnings for
+// invalid -R options.
+static void processRemarkOptions(clang::DiagnosticsEngine &diags,
+ const clang::DiagnosticOptions &opts,
+ bool reportDiags = true) {
+  llvm::SmallVector _diags;
+  const llvm::IntrusiveRefCntPtr diagIDs =
+  diags.getDiagnosticIDs();
+
+  for (unsigned i = 0; i < opts.Remarks.size(); i++) {
+llvm::StringRef opt = opts.Remarks[i];
+const auto flavor = clang

[PATCH] D156320: [Flang][Driver] Add support for Rpass and related options

2023-08-15 Thread victorkingi via Phabricator via cfe-commits
victorkingi added inline comments.



Comment at: flang/lib/Frontend/FrontendActions.cpp:976-1011
+  void
+  optimizationRemarkHandler(const llvm::DiagnosticInfoOptimizationBase &d) {
+if (d.isPassed()) {
+  // Optimization remarks are active only if the -Rpass flag has a regular
+  // expression that matches the name of the pass name in \p d.
+  if (codeGenOpts.OptimizationRemark.patternMatches(d.getPassName()))
+emitOptimizationMessage(

awarzynski wrote:
> 
The if statement still needs to return if the pattern doesn't match, should I 
leave it the way it is?



Comment at: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:30
 #include "llvm/Support/CommandLine.h"
+#include 
 

awarzynski wrote:
> No longer needed, right? Also, please use the the format consistent with the 
> other `#include`s.
It's needed in the case of `clang::diag::warn_unknown_diag_option` in 
`emitUnknownDiagWarning` function.



Comment at: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:117
+
+void processWarningOptions(clang::DiagnosticsEngine &diags,
+   const clang::DiagnosticOptions &opts,

awarzynski wrote:
> awarzynski wrote:
> > ?
> I find this method quite confusing.
> 
> 1. It doesn't process warning options - it processes remarks options (so the 
> name is inaccurate).
> 2. It deals with `-Rpass -Rno-pass` cases (i.e. postive + negative flag), but 
> that's normally done in CompilerInvocation when parsing other options. See 
> e.g. 
> https://github.com/llvm/llvm-project/blob/c52d9509d40d3048914b144618232213e6076e05/flang/lib/Frontend/CompilerInvocation.cpp#L161-L163.
>  Why not use that logic instead?
> 3. It's been extracted from Clang - it would be very helpful to note that and 
> highlight the difference between this method and similar method in Clang.
> 4. You can safely trim it to only deal with Remarks (so e.g. update `const 
> clang::DiagnosticOptions &opts,` in the signature)
> 
> Now, I am not requesting any major refactor here - I appreciate that e.g. 
> these remark flags are defined a bit differently to other flags. But this 
> method can be simplified and should be documented.
I found it difficult including it in `CompilerInvocation.cpp` 
`parseCodeGenArgs` function since we are updating the DiagnosticsEngine object 
belonging to CompilerInstance not the other. We would have to expose the 
`DiagnosticsEngine` in `CompilerInvocation` class to do this. Would there be 
another way?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156320

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


[PATCH] D156032: Implement CWG2137 (list-initialization from objects of the same type)

2023-08-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a subscriber: Endill.
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:4263-4264
+  // CWG2311: T{ prvalue_of_type_T } is not eligible for copy elision
+  // Make this an elision if this won't call an initializer-list 
constructor
+  // (Always on an aggregate type or check constructors first)
+  CopyElisionPossible = true;





Comment at: clang/lib/Sema/SemaInit.cpp:4334
+  case OR_No_Viable_Function: // Possible if you try to initialize from a
+  // volatile prvalue
+  case OR_Ambiguous:





Comment at: clang/lib/Sema/SemaInit.cpp:4337
+// This was never going to be an initializer-list constructor
+// so it should be elided
+ElideConstructor();





Comment at: clang/lib/Sema/SemaInit.cpp:4342
+// If this deleted constructor was not an initializer-list constructor
+// we should elide it
+if (!S.isInitListConstructor(Best->Function)) {





Comment at: clang/lib/Sema/SemaInit.cpp:4249-4250
   InitializedEntity::EK_LambdaToBlockConversionBlockElement &&
-  UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isPRValue() &&
-  S.Context.hasSameUnqualifiedType(UnwrappedArgs[0]->getType(), DestType)) 
{
+  Args.size() == 1 && Args[0]->isPRValue() &&
+  S.Context.hasSameUnqualifiedType(Args[0]->getType(), DestType)) {
 // Convert qualifications if necessary.

MitalAshok wrote:
> MitalAshok wrote:
> > This change unfortunately exposes the still-open [[ 
> > https://wg21.link/CWG2311 | CWG2311 ]] but allows `T{ object_of_type_T }` 
> > to consider user declared constructors.
> > 
> > I am working on a separate fix for CWG2311 (Consider constructors as below, 
> > but then if the chosen constructor is not an initializer-list constructor, 
> > elide it).
> > 
> Fix will be here: https://reviews.llvm.org/D156062
> 
> `auto{ prvalue }` will elide a copy for aggregate types again. It will do so 
> after checking constructors for non-aggregate classes now.
As this was abandoned in favor of doing the fix here, the patch title, summary, 
and release notes should all be updated to talk about CWG2311.



Comment at: clang/test/CXX/drs/dr23xx.cpp:54
+void test() {
+  // Ensure none of these expressions try to call a move constructor
+  T a = T{T(0)};





Comment at: clang/test/CXX/drs/dr23xx.cpp:9
+namespace std {
+  __extension__ typedef __SIZE_TYPE__ size_t;
+

MitalAshok wrote:
> cor3ntin wrote:
> > 
> Wouldn't work in c++98 mode this file is being run in. I've copied this from 
> other tests in this directory. I guess I can put a `#if __cplusplus >= 
> 201103L` instead?
The current form seems fine to me.



Comment at: clang/test/CXX/drs/dr23xx.cpp:50
 
+namespace dr2311 {
+#if __cplusplus >= 201707L

MitalAshok wrote:
> cor3ntin wrote:
> > the dr status html page is generated automatically by leaving a magic 
> > comment here - and then running `clang/www/make_cxx_dr_status`
> CWG2311 is still open, but clang did support list-initialization elision 
> before this patch. The committee still needs to decide how exactly this 
> elision is going to work, which might be different from how this patch 
> implements it, so hesitant to mark this as done.
CC @Endill -- do we have a special marking for "issue still open in WG21, but 
we implement the current suggested resolution?"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156032

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


[PATCH] D157793: [Headers] Add missing __need_ macros to stdarg.h

2023-08-15 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!




Comment at: clang/test/Headers/stdarg.c:34
+__va_copy(g, v);
+va_copy(g, v); // c89-error{{implicit}} c89-note{{va_copy}} 
c99-no-diagnostics
+}

iana wrote:
> aaron.ballman wrote:
> > You should spell out these diagnostics, and I think `c99-no-diagnostics` 
> > should be placed up by the RUN lines so it's more obvious that we expect no 
> > diagnostics in C99 mode.
> > 
> > Actually, this file should perhaps be split into two files as they're 
> > testing different things. (I was tripped up seeing no-diagnostics but we 
> > have `c99-error` entries above, that's when I realized the split file was 
> > being used differently in the RUN lines which is a bit novel.) But I'm not 
> > certain I fully understand what your comment means about why we're using 
> > split file in the first place, so I might be missing something.
> It's only trying to test what including  gets you by default. The 
> first chunk is to prove that nothing is provided via built-ins or anything 
> like if you don't include anything. The second chunk shows that you get the 
> expected declarations in each standard mode if you include  with no 
> `__need_` macros.
> 
> The problem is this.
> ```
> va_copy(g, v); // The first time you get: implicitly declaring library 
> function 'va_copy'
> 
> va_copy(g, v); // But now the compiler has decided that va_copy has a 
> declaration, so you don't get any diagnostics even though va_copy doesn't 
> have its real declaration, I think the compiler assumes 'int va_copy(int, 
> int)' or something like that.
> ```
> 
> Maybe we don't need to test the include-nothing case both here and 
> stdargneeds.c?
> 
> D157757 has the same problem for `offsetof` but since it uses C23 also, the 
> diagnostics get repeated.
Ah, I see now, thank you for the explanation.

The compiler adds an implicit function declaration for `va_copy` in C (so the 
signature is `int func()` as a K&R C function without a prototype), hence the 
need to split the file.

This seems reasonable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157793

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


[PATCH] D156032: Implement CWG2137 (list-initialization from objects of the same type)

2023-08-15 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/test/CXX/drs/dr23xx.cpp:50
 
+namespace dr2311 {
+#if __cplusplus >= 201707L

aaron.ballman wrote:
> MitalAshok wrote:
> > cor3ntin wrote:
> > > the dr status html page is generated automatically by leaving a magic 
> > > comment here - and then running `clang/www/make_cxx_dr_status`
> > CWG2311 is still open, but clang did support list-initialization elision 
> > before this patch. The committee still needs to decide how exactly this 
> > elision is going to work, which might be different from how this patch 
> > implements it, so hesitant to mark this as done.
> CC @Endill -- do we have a special marking for "issue still open in WG21, but 
> we implement the current suggested resolution?"
`18 open` sould work


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156032

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


[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2023-08-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D126864#4586307 , @efriedma wrote:

> RecordDecl::hasFlexibleArrayMember() is supposed to reflect the standard's 
> definition of a flexible array member, which only includes incomplete arrays. 
>  The places that care about other array members use separate checks.  We 
> wouldn't want to accidentally extend the non-standard treatment of arrays 
> with fixed bound to other places.
>
> I think there was an effort to try to refactor uses of StrictFlexArrays to a 
> centralized helper, but I don't remember what happened to it.

Are you thinking of https://reviews.llvm.org/D134791 perchance?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126864

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


[PATCH] D157962: [GNU ObjC] Unconditionally emit section markers.

2023-08-15 Thread David Chisnall via Phabricator via cfe-commits
theraven updated this revision to Diff 550295.
theraven added a comment.

Update test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157962

Files:
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/test/CodeGenObjC/gnu-init.m


Index: clang/test/CodeGenObjC/gnu-init.m
===
--- clang/test/CodeGenObjC/gnu-init.m
+++ clang/test/CodeGenObjC/gnu-init.m
@@ -52,7 +52,8 @@
 // CHECK-NEW: @.objc_null_class_alias = linkonce_odr hidden global { ptr, ptr 
} zeroinitializer, section "__objc_class_aliases", comdat, align 8
 // CHECK-NEW: @.objc_null_constant_string = linkonce_odr hidden global { ptr, 
i32, i32, i32, i32, ptr } zeroinitializer, section "__objc_constant_string", 
comdat, align 8
 // Make sure that the null symbols are not going to be removed, even by 
linking.
-// CHECK-NEW: @llvm.used = appending global [8 x ptr] [ptr 
@._OBJC_INIT_CLASS_X, ptr @.objc_ctor, ptr @.objc_null_selector, ptr 
@.objc_null_category, ptr @.objc_null_protocol, ptr @.objc_null_protocol_ref, 
ptr @.objc_null_class_alias, ptr @.objc_null_constant_string], section 
"llvm.metadata"
+// CHECK-NEW: @llvm.used = appending global [10 x ptr] [ptr 
@._OBJC_INIT_CLASS_X, ptr @.objc_ctor, ptr @.objc_null_selector, ptr 
@.objc_null_category, ptr @.objc_null_cls_init_ref, ptr @.objc_null_class_ref, 
ptr @.objc_null_protocol, ptr @.objc_null_protocol_ref, ptr 
@.objc_null_class_alias, ptr @.objc_null_constant_string], section 
"llvm.metadata"
+
 // Make sure that the load function and the reference to it are marked as used.
 // CHECK-NEW: @llvm.compiler.used = appending global [1 x ptr] [ptr 
@.objcv2_load_function], section "llvm.metadata"
 
Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1614,32 +1614,24 @@
 if (!CGM.getTriple().isOSBinFormatCOFF()) {
   createNullGlobal(".objc_null_selector", {NULLPtr, NULLPtr},
   sectionName());
-  if (Categories.empty())
-createNullGlobal(".objc_null_category", {NULLPtr, NULLPtr,
-  NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr},
-sectionName());
-  if (!EmittedClass) {
-createNullGlobal(".objc_null_cls_init_ref", NULLPtr,
-sectionName());
-createNullGlobal(".objc_null_class_ref", { NULLPtr, NULLPtr },
-sectionName());
-  }
-  if (!EmittedProtocol)
-createNullGlobal(".objc_null_protocol", {NULLPtr, NULLPtr, NULLPtr,
-NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr,
-NULLPtr}, sectionName());
-  if (!EmittedProtocolRef)
-createNullGlobal(".objc_null_protocol_ref", {NULLPtr},
-sectionName());
-  if (ClassAliases.empty())
-createNullGlobal(".objc_null_class_alias", { NULLPtr, NULLPtr },
-sectionName());
-  if (ConstantStrings.empty()) {
-auto i32Zero = llvm::ConstantInt::get(Int32Ty, 0);
-createNullGlobal(".objc_null_constant_string", { NULLPtr, i32Zero,
-i32Zero, i32Zero, i32Zero, NULLPtr },
-sectionName());
-  }
+  createNullGlobal(".objc_null_category", {NULLPtr, NULLPtr,
+NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr},
+  sectionName());
+  createNullGlobal(".objc_null_cls_init_ref", NULLPtr,
+  sectionName());
+  createNullGlobal(".objc_null_class_ref", { NULLPtr, NULLPtr },
+  sectionName());
+  createNullGlobal(".objc_null_protocol", {NULLPtr, NULLPtr, NULLPtr,
+  NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr,
+  NULLPtr}, sectionName());
+  createNullGlobal(".objc_null_protocol_ref", {NULLPtr},
+  sectionName());
+  createNullGlobal(".objc_null_class_alias", { NULLPtr, NULLPtr },
+  sectionName());
+  auto i32Zero = llvm::ConstantInt::get(Int32Ty, 0);
+  createNullGlobal(".objc_null_constant_string", { NULLPtr, i32Zero,
+  i32Zero, i32Zero, i32Zero, NULLPtr },
+  sectionName());
 }
 ConstantStrings.clear();
 Categories.clear();


Index: clang/test/CodeGenObjC/gnu-init.m
===
--- clang/test/CodeGenObjC/gnu-init.m
+++ clang/test/CodeGenObjC/gnu-init.m
@@ -52,7 +52,8 @@
 // CHECK-NEW: @.objc_null_class_alias = linkonce_odr hidden global { ptr, ptr } zeroinitializer, section "__objc_class_aliases", comdat, align 8
 // CHECK-NEW: @.objc_null_constant_string = linkonce_odr hidden global { ptr, i32, i32, i32, i32, ptr } zeroinitializer, section "__objc_constant_string", comdat, align 8
 // Make sure that the null symbols are not going to be removed, even by linking.
-// CHECK-NEW: @llvm.used = appending global [8 x ptr] [ptr @._OBJC_INIT_CLASS_X, ptr @.objc_ctor, ptr @.objc_null_

[PATCH] D157479: [Clang][DebugInfo] Emit narrower base types for structured binding declarations that bind to struct bitfields

2023-08-15 Thread Victor Campos via Phabricator via cfe-commits
vhscampos updated this revision to Diff 550298.
vhscampos added a comment.

- Redone test to cover only what's needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157479

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGenCXX/debug-info-structured-binding-bitfield.cpp

Index: clang/test/CodeGenCXX/debug-info-structured-binding-bitfield.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-structured-binding-bitfield.cpp
@@ -0,0 +1,285 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -triple aarch64-arm-none-eabi %s -o - | FileCheck %s
+
+struct S0 {
+  unsigned int x : 16;
+  unsigned int y : 16;
+};
+
+// CHECK-LABEL: define dso_local void @_Z3fS0v
+// CHECK:alloca %struct.S0, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = alloca %struct.S0, align 4
+// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S0_A:![0-9]+]], metadata !DIExpression())
+// CHECK-NEXT:call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S0_B:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 2))
+//
+void fS0() {
+  S0 s0;
+  auto [a, b] = s0;
+}
+
+struct S1 {
+  volatile unsigned int x : 16;
+  volatile unsigned int y : 16;
+};
+
+// CHECK-LABEL: define dso_local void @_Z3fS1v
+// CHECK:alloca %struct.S1, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = alloca %struct.S1, align 4
+// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S1_A:![0-9]+]], metadata !DIExpression())
+// CHECK-NEXT:call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S1_B:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 2))
+//
+void fS1() {
+  S1 s1;
+  auto [a, b] = s1;
+}
+
+struct S2 {
+  unsigned int x : 8;
+  unsigned int y : 8;
+};
+
+// CHECK-LABEL: define dso_local void @_Z3fS2v
+// CHECK:alloca %struct.S2, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = alloca %struct.S2, align 4
+// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S2_A:![0-9]+]], metadata !DIExpression())
+// CHECK-NEXT:call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S2_B:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 1))
+//
+void fS2() {
+  S2 s2;
+  auto [a, b] = s2;
+}
+
+struct S3 {
+  volatile unsigned int x : 8;
+  volatile unsigned int y : 8;
+};
+
+// CHECK-LABEL: define dso_local void @_Z3fS3v
+// CHECK:alloca %struct.S3, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = alloca %struct.S3, align 4
+// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S3_A:![0-9]+]], metadata !DIExpression())
+// CHECK-NEXT:call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S3_B:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 1))
+//
+void fS3() {
+  S3 s3;
+  auto [a, b] = s3;
+}
+
+struct S4 {
+  unsigned int x : 8;
+  unsigned int y : 16;
+};
+
+// CHECK-LABEL: define dso_local void @_Z3fS4v
+// CHECK:alloca %struct.S4, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = alloca %struct.S4, align 4
+// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S4_A:![0-9]+]], metadata !DIExpression())
+// CHECK-NEXT:call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S4_B:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 1))
+//
+void fS4() {
+  S4 s4;
+  auto [a, b] = s4;
+}
+
+struct S5 {
+  volatile unsigned int x : 8;
+  volatile unsigned int y : 16;
+};
+
+// CHECK-LABEL: define dso_local void @_Z3fS5v
+// CHECK:alloca %struct.S5, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = alloca %struct.S5, align 4
+// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S5_A:![0-9]+]], metadata !DIExpression())
+// CHECK-NEXT:call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S5_B:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 1))
+//
+void fS5() {
+  S5 s5;
+  auto [a, b] = s5;
+}
+
+struct S6 {
+  unsigned int x : 16;
+  unsigned int y : 8;
+};
+
+// CHECK-LABEL: define dso_local void @_Z3fS6v
+// CHECK:alloca %struct.S6, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = alloca %struct.S6, align 4
+// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S6_A:![0-9]+]], metadata !DIExpression())
+// CHECK-NEXT:call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S6_B:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 2))
+//
+void fS6() {
+  S6 s6;
+  auto [a, b] = s6;
+}
+
+struct S7 {
+  volatile unsigned int x : 16;
+  volatile unsigned int y : 8;
+};
+
+// CHECK-LABEL: define dso_local void @_Z3fS7v
+// CHECK:alloca %struct.S7, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = alloca %struct.S7, align 4
+// CHECK: call void @llvm.dbg

[PATCH] D157479: [Clang][DebugInfo] Emit narrower base types for structured binding declarations that bind to struct bitfields

2023-08-15 Thread Victor Campos via Phabricator via cfe-commits
vhscampos marked an inline comment as done.
vhscampos added a comment.

@aprantl We have discussed internally a few options to implement correct debug 
information in this case. But this will be future work.

For the time being, we believe it is better to have no debug information rather 
than wrong debug info, as can be also concluded from the first line of 
https://llvm.org/docs/HowToUpdateDebugInfo.html




Comment at: clang/test/CodeGenCXX/debug-info-structured-binding-bitfield.cpp:525
+// CHECK: !202 = !DILocation(line: 279, column: 8, scope: !194)
+// CHECK: !203 = !DILocation(line: 279, column: 17, scope: !194)
+// CHECK: !204 = !DILocation(line: 280, column: 1, scope: !194)

aprantl wrote:
> This test is going to to be a nightmare to maintain since it's hardcoding all 
> the metadata numbering. Please use FileCheck variables `![[VAR:[0-9]+]]` to 
> refer to other fields. Also, this test is probably checking too much.
> The primary thing this patch changes is the data types of the fields, so the 
> CHECK lines should focus on that.
Ok. Redone the checks to cover only what's needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157479

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


[PATCH] D152770: [clang][ExtractAPI] Add support for Objective-C categories

2023-08-15 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 updated this revision to Diff 550303.
Ruturaj4 marked an inline comment as done.
Ruturaj4 added a comment.

- [clang][ExtractAPI] Add support for Objective-C categories

1. Updating D152770 : [clang][ExtractAPI] Add 
support for Objective-C categories #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Update test to remove MyClass2.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152770

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/objc_module_category.m
  clang/test/ExtractAPI/objc_various_categories.m

Index: clang/test/ExtractAPI/objc_various_categories.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_various_categories.m
@@ -0,0 +1,507 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang -extract-api -x objective-c-header \
+// RUN: -target arm64-apple-macosx \
+// RUN: %t/myclass_1.h \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+#import "myclass_1.h"
+#import "Foundation.h"
+
+@interface MyClass1 (MyCategory1)
+- (int) SomeMethod;
+@end
+
+@interface NSString (Category1)
+-(void) StringMethod;
+@end
+
+@interface NSString (Category2)
+-(void) StringMethod2;
+@end
+
+//--- myclass_1.h
+@interface MyClass1
+@end
+
+//--- Foundation.h
+@interface NSString
+@end
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)MyClass1(im)SomeMethod",
+  "target": "c:objc(cs)MyClass1",
+  "targetFallback": "MyClass1"
+},
+{
+  "kind": "extensionTo",
+  "source": "c:objc(cy)NSString@Category1",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod",
+  "target": "c:objc(cy)NSString@Category1",
+  "targetFallback": "Category1"
+},
+{
+  "kind": "extensionTo",
+  "source": "c:objc(cy)NSString@Category2",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod2",
+  "target": "c:objc(cy)NSString@Category2",
+  "targetFallback": "Category2"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyClass1"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyClass1"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"position": {
+  "character": 12,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/myclass_1.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "MyClass1"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "MyClass1"
+  }
+],
+"title": "MyClass1"
+  },
+  "pathComponents": [
+"MyClass1"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "text",
+  "spelling": "- ("
+},
+{
+  "kind": "typ

[PATCH] D152770: [clang][ExtractAPI] Add support for Objective-C categories

2023-08-15 Thread Daniel Grumberg via Phabricator via cfe-commits
dang accepted this revision.
dang added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152770

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


[PATCH] D157383: [clang][Diagnostics] Provide source range to integer-overflow warnings

2023-08-15 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157383

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


[PATCH] D154130: [lit][clang] Avoid realpath on Windows due to MAX_PATH limitations

2023-08-15 Thread Tristan Labelle via Phabricator via cfe-commits
MrTrillian added inline comments.



Comment at: clang/test/Lexer/case-insensitive-include-win.c:5-9
+// Note: We must use the real path here, because the logic to detect case
+// mismatch relies on resolving the real path and checking that casing differs.
+// If we use %t and we are on a substitute drive S: mapping to C:\subst,
+// then we will compare "S:\test.dir\FOO.h" to "C:\subst\test.dir\foo.h"
+// and avoid emitting the diagnostic because the structure is different.

tahonermann wrote:
> MrTrillian wrote:
> > tahonermann wrote:
> > > MrTrillian wrote:
> > > > tahonermann wrote:
> > > > > Hmm, is it really desirable or necessary that the case mismatch logic 
> > > > > resolve substituted drives? I wouldn't think so. This seems like 
> > > > > another case where our common canonicalization would be desired.
> > > > I think it is necessary as I don't see how else we can retrieve the 
> > > > original casing of the file path. Merely making the path absolute would 
> > > > not do that. Searching for solutions on the internet finds ideas that 
> > > > are worse like converting to a short path then back to a long path or 
> > > > rebuilding the path one component at a time with a series directory 
> > > > listing requests.
> > > The warning this test checks for is diagnosed in 
> > > `Preprocessor::HandleHeaderIncludeOrImport()`; search for 
> > > `pp_nonportable_path` and/or `pp_nonportable_system_path`. I believe this 
> > > warning will be issued if any component of the path does not match the 
> > > case of the include directive. Since the file name differs in case, 
> > > unless there is a bug in handling of the file name, this test isn't 
> > > sensitive to case mismatches in `%t`.
> > > 
> > > From a user point of view, resolving a substitute drive doesn't seem 
> > > desirableto me with respect to determining whether a non-portable path is 
> > > being used; I don't think the behavior should be dependent on whether a 
> > > substitute drive is being used or what its target is.
> > @tahonermann I think the code is working by design and it would be an 
> > unrelated change to modify its logic. See `trySimplifyPath` in 
> > `PPDirectives.cpp`:
> > 
> > ```
> >   // Below is a best-effort to handle ".." in paths. It is admittedly
> >   // not 100% correct in the presence of symlinks.
> > 
> > // If these path components differ by more than just case, then we
> > // may be looking at symlinked paths. Bail on this diagnostic to 
> > avoid
> > // noisy false positives.
> > ```
> > 
> > The test was previously implicitly requiring getting the realpath, and it 
> > worked because `lit.py`'s logic of doing that. Now that requirement is 
> > explicit in the test.
> I'm still not following here. Are you saying that `trySimplifyPath()` will 
> replace substitute drives? If so, that doesn't sound desirable and I would 
> expect it to be problematic for your use case. I think we should follow this 
> up ... somewhere (now that this review is closed).
@tahonermann . `trySimplifyPath()` does not replace substitute drives. It's a 
best-effort attempt to see if the included path mismatches the real file path 
only by case. It explicitly bails out without diagnostics if it finds that the 
included path has a different shape from the real file path, which will happen 
if the included path is on a substitute drive. It has to compare with the real 
file path because this is the only reasonable way to get the original path 
casing.

It was already the case that this diagnostic bailed out in the presence of 
symbolic links, so there are no behavioral differences. I needed to update the 
test because previously `lit.py` would enforce that `%t` was a real path, and 
now it doesn't, which means that we would hit the "bail out" code path and not 
produce the diagnostic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154130

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


[PATCH] D153156: [Clang] CWG1473: do not err on the lack of space after operator""

2023-08-15 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 aside from some minor concerns.

In D153156#4507440 , @rZhBoYao wrote:

> There seems to be no clear objection to this and 
> https://reviews.llvm.org/D152632 and the CI are passing for both.  Any chance 
> that I merge these two before llvm 17 branch out (IIRC the next Monday)?

As this isn't fixing a regression, I think it'd be better to let it bake a 
while longer in Clang 18 (unless there's some extenuating circumstances where 
we need to land this sooner).




Comment at: clang/test/SemaCXX/reserved-identifier.cpp:91-92
 long double sangbleu = operator""_SacreBleu(1.2);   // no-warning
 
-void operator"" _lowercase(unsigned long long); // no-warning
+void operator""_lowercase(unsigned long long); // no-warning
 void operator""_lowercase(unsigned long long); // no-warning

No need to have a duplicate test.



Comment at: clang/www/cxx_dr_status.html:8648
 Syntax of literal-operator-id
-Unknown
+Clang 17
   




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

https://reviews.llvm.org/D153156

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


[PATCH] D157452: [RFC][Clang][Codegen] `std::type_info` needs special care with explicit address spaces

2023-08-15 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx updated this revision to Diff 550311.
AlexVlx added a comment.

Rework the patch as the proposed approach was unsound; keep `typeid` generic.


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

https://reviews.llvm.org/D157452

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/typeid-cxx11-with-address-space.cpp
  clang/test/CodeGenCXX/typeid-with-address-space.cpp
  clang/test/CodeGenCXX/typeinfo
  clang/test/CodeGenCXX/typeinfo-with-address-space.cpp

Index: clang/test/CodeGenCXX/typeinfo-with-address-space.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/typeinfo-with-address-space.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -I%S %s -triple amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s -check-prefix=AS
+// RUN: %clang_cc1 -I%S %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s -check-prefix=NO-AS
+#include 
+
+class A {
+virtual void f() = 0;
+};
+
+class B : A {
+void f() override;
+};
+
+// AS: @_ZTISt9type_info = external addrspace(1) constant ptr addrspace(1)
+// NO-AS: @_ZTISt9type_info = external constant ptr
+// AS: @_ZTIi = external addrspace(1) constant ptr addrspace(1)
+// NO-AS: @_ZTIi = external constant ptr
+// AS: @_ZTVN10__cxxabiv117__class_type_infoE = external addrspace(1) global ptr addrspace(1)
+// NO-AS: @_ZTVN10__cxxabiv117__class_type_infoE = external global ptr
+// AS: @_ZTS1A = linkonce_odr addrspace(1) constant [3 x i8] c"1A\00", comdat, align 1
+// NO-AS: @_ZTS1A = linkonce_odr constant [3 x i8] c"1A\00", comdat, align 1
+// AS: @_ZTI1A = linkonce_odr addrspace(1) constant { ptr addrspace(1), ptr addrspace(1) } { ptr addrspace(1) getelementptr inbounds (ptr addrspace(1), ptr addrspace(1) @_ZTVN10__cxxabiv117__class_type_infoE, i64 2), ptr addrspace(1) @_ZTS1A }, comdat, align 8
+// NO-AS: @_ZTI1A = linkonce_odr constant { ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i64 2), ptr @_ZTS1A }, comdat, align 8
+// AS: @_ZTIf = external addrspace(1) constant ptr addrspace(1)
+// NO-AS: @_ZTIf = external constant ptr
+
+unsigned long Fn(B& b) {
+// AS: %call = call noundef zeroext i1 @_ZNKSt9type_infoeqERKS_(ptr {{.*}} addrspacecast (ptr addrspace(1) @_ZTISt9type_info to ptr), ptr {{.*}} %2)
+// NO-AS: %call = call noundef zeroext i1 @_ZNKSt9type_infoeqERKS_(ptr {{.*}} @_ZTISt9type_info, ptr {{.*}} %2)
+if (typeid(std::type_info) == typeid(b))
+return 42;
+// AS: %call2 = call noundef zeroext i1 @_ZNKSt9type_infoneERKS_(ptr {{.*}} addrspacecast (ptr addrspace(1) @_ZTIi to ptr), ptr {{.*}} %5)
+// NO-AS: %call2 = call noundef zeroext i1 @_ZNKSt9type_infoneERKS_(ptr {{.*}} @_ZTIi, ptr {{.*}} %5)
+if (typeid(int) != typeid(b))
+return 1712;
+// AS: %call5 = call noundef ptr @_ZNKSt9type_info4nameEv(ptr {{.*}} addrspacecast (ptr addrspace(1) @_ZTI1A to ptr))
+// NO-AS: %call5 = call noundef ptr @_ZNKSt9type_info4nameEv(ptr {{.*}} @_ZTI1A)
+// AS: %call7 = call noundef ptr @_ZNKSt9type_info4nameEv(ptr {{.*}} %8)
+// NO-AS: %call7 = call noundef ptr @_ZNKSt9type_info4nameEv(ptr {{.*}} %8)
+if (typeid(A).name() == typeid(b).name())
+return 0;
+// AS: %call11 = call noundef zeroext i1 @_ZNKSt9type_info6beforeERKS_(ptr {{.*}} %11, ptr {{.*}} addrspacecast (ptr addrspace(1) @_ZTIf to ptr))
+// NO-AS:   %call11 = call noundef zeroext i1 @_ZNKSt9type_info6beforeERKS_(ptr {{.*}} %11, ptr {{.*}} @_ZTIf)
+if (typeid(b).before(typeid(float)))
+return 1;
+// AS: %call15 = call noundef i64 @_ZNKSt9type_info9hash_codeEv(ptr {{.*}} %14)
+// NO-AS: %call15 = call noundef i64 @_ZNKSt9type_info9hash_codeEv(ptr {{.*}} %14)
+return typeid(b).hash_code();
+}
Index: clang/test/CodeGenCXX/typeinfo
===
--- clang/test/CodeGenCXX/typeinfo
+++ clang/test/CodeGenCXX/typeinfo
@@ -10,6 +10,14 @@
 bool operator!=(const type_info& __arg) const {
   return !operator==(__arg);
 }
+
+bool before(const type_info& __arg) const {
+  return __name < __arg.__name;
+}
+
+unsigned long hash_code() const {
+  return reinterpret_cast(__name);
+}
   protected:
 const char *__name;
   };
Index: clang/test/CodeGenCXX/typeid-with-address-space.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/typeid-with-address-space.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -I%S %s -triple amdgcn-amd-amdhsa -emit-llvm -fcxx-exceptions -fexceptions -o - | FileCheck %s
+#include 
+
+namespace Test1 {
+
+// PR7400
+struct A { virtual void f(); };
+
+// CHECK: @_ZN5Test16int_tiE ={{.*}} constant ptr addrspacecast (ptr addrspace(1) @_ZTIi to ptr), align 8
+const std::type_info &int_ti = typeid(int);
+
+// CHECK: @_ZN5Test14A_tiE ={{.*}} constant ptr addrspacecast (ptr addrspace(1) @_ZTIN5Test11AE to ptr), align 8
+const std::type_info &A_ti = typ

[PATCH] D157808: [clang] Add missing field to VisibilityAttr json AST dump

2023-08-15 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

In D157808#4587014 , @thakis wrote:

> Hello, one of the many dump commits broke tests on macOS: 
> http://45.33.8.238/macm1/67030/step_7.txt
>
> Please take a look and revert for now if it takes a while to fix.
>
> Also, consider spreading out commits a bit so that if one breaks something, 
> it's easily to see which one it was.

Turns out the failure is from D157775 . Tests 
have been broken on mac for over 13 hours now. Could you please take a look?

I'll revert D157775  and follow-ups causing 
conflicts if it's still broken in another 2h.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157808

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


[PATCH] D157452: [RFC][Clang][Codegen] `std::type_info` needs special care with explicit address spaces

2023-08-15 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx added a comment.

In D157452#4586554 , @rjmccall wrote:

> The path of least resistance here is that IRGen should just insert 
> conversions from the global AS to the default AS as part of evaluating 
> `typeid`.  I haven't looked at it closely, but that seems to be what this 
> patch is doing.
>
> However, `std::type_info` is an interesting special case in that we actually 
> know statically that all objects of that type will be allocated in the global 
> AS, so there's really no reason to pass around pointers in the default AS; 
> `std::type_info *` should just default to being in the global AS.  It'd be a 
> non-trivial feature in support of a somewhat uncommonly-used C++ feature, and 
> I can't tell how best to spend your time, *but*... if you're so inclined, I 
> think it would make a somewhat compelling feature to be able to declare a 
> default AS for a class type, which your target could then adopt in the 
> headers for `std::type_info`.

I've reworked things along these lines, as both you and @yaxunl, thank you; 
turns out that what I was doing was unsound / would not catch all cases, 
whereas this does. As for the feature suggestion, that actually seems as if it 
would be very useful, beyond this application; I will add it to my TODO list, 
although I cannot promise to get to investigating it right away.


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

https://reviews.llvm.org/D157452

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


[PATCH] D157687: [clang][AST] TextNodeDumper learned to dump NRVO candidates of return stmts

2023-08-15 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 updated this revision to Diff 550319.
strimo378 added a comment.

Added test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157687

Files:
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-decl.cpp


Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -25,12 +25,17 @@
 
 namespace testVarDeclNRVO {
   class A { };
-  A foo() {
+  A TestFuncNRVO() {
 A TestVarDeclNRVO;
 return TestVarDeclNRVO;
   }
 }
-// CHECK: VarDecl{{.*}} TestVarDeclNRVO 'A':'testVarDeclNRVO::A' nrvo
+// CHECK:  FunctionDecl{{.*}} TestFuncNRVO 'A ()'
+// CHECK-NEXT: `-CompoundStmt
+// CHECK-NEXT: |-DeclStmt
+// CHECK-NEXT: | `-VarDecl{{.*}} TestVarDeclNRVO 'A':'testVarDeclNRVO::A' nrvo 
callinit
+// CHECK-NEXT: |   `-CXXConstructExpr
+// CHECK-NEXT: `-ReturnStmt{{.*}} nrvo_candidate(Var {{.*}} 'TestVarDeclNRVO' 
'A':'testVarDeclNRVO::A')
 
 void testParmVarDeclInit(int TestParmVarDeclInit = 0);
 // CHECK:  ParmVarDecl{{.*}} TestParmVarDeclInit 'int'
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -995,6 +995,14 @@
 OS << " gnu_range";
 }
 
+void clang::TextNodeDumper::VisitReturnStmt(const ReturnStmt *Node) {
+  if (const VarDecl *Cand = Node->getNRVOCandidate()) {
+OS << " nrvo_candidate(";
+dumpBareDeclRef(Cand);
+OS << ")";
+  }
+}
+
 void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
   if (Node->hasAPValueResult())
 AddChild("value",
Index: clang/include/clang/AST/TextNodeDumper.h
===
--- clang/include/clang/AST/TextNodeDumper.h
+++ clang/include/clang/AST/TextNodeDumper.h
@@ -246,6 +246,7 @@
   void VisitLabelStmt(const LabelStmt *Node);
   void VisitGotoStmt(const GotoStmt *Node);
   void VisitCaseStmt(const CaseStmt *Node);
+  void VisitReturnStmt(const ReturnStmt *Node);
   void VisitCompoundStmt(const CompoundStmt *Node);
   void VisitConstantExpr(const ConstantExpr *Node);
   void VisitCallExpr(const CallExpr *Node);


Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -25,12 +25,17 @@
 
 namespace testVarDeclNRVO {
   class A { };
-  A foo() {
+  A TestFuncNRVO() {
 A TestVarDeclNRVO;
 return TestVarDeclNRVO;
   }
 }
-// CHECK: VarDecl{{.*}} TestVarDeclNRVO 'A':'testVarDeclNRVO::A' nrvo
+// CHECK:  FunctionDecl{{.*}} TestFuncNRVO 'A ()'
+// CHECK-NEXT: `-CompoundStmt
+// CHECK-NEXT: |-DeclStmt
+// CHECK-NEXT: | `-VarDecl{{.*}} TestVarDeclNRVO 'A':'testVarDeclNRVO::A' nrvo callinit
+// CHECK-NEXT: |   `-CXXConstructExpr
+// CHECK-NEXT: `-ReturnStmt{{.*}} nrvo_candidate(Var {{.*}} 'TestVarDeclNRVO' 'A':'testVarDeclNRVO::A')
 
 void testParmVarDeclInit(int TestParmVarDeclInit = 0);
 // CHECK:  ParmVarDecl{{.*}} TestParmVarDeclInit 'int'
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -995,6 +995,14 @@
 OS << " gnu_range";
 }
 
+void clang::TextNodeDumper::VisitReturnStmt(const ReturnStmt *Node) {
+  if (const VarDecl *Cand = Node->getNRVOCandidate()) {
+OS << " nrvo_candidate(";
+dumpBareDeclRef(Cand);
+OS << ")";
+  }
+}
+
 void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
   if (Node->hasAPValueResult())
 AddChild("value",
Index: clang/include/clang/AST/TextNodeDumper.h
===
--- clang/include/clang/AST/TextNodeDumper.h
+++ clang/include/clang/AST/TextNodeDumper.h
@@ -246,6 +246,7 @@
   void VisitLabelStmt(const LabelStmt *Node);
   void VisitGotoStmt(const GotoStmt *Node);
   void VisitCaseStmt(const CaseStmt *Node);
+  void VisitReturnStmt(const ReturnStmt *Node);
   void VisitCompoundStmt(const CompoundStmt *Node);
   void VisitConstantExpr(const ConstantExpr *Node);
   void VisitCallExpr(const CallExpr *Node);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156320: [Flang][Driver] Add support for Rpass and related options

2023-08-15 Thread victorkingi via Phabricator via cfe-commits
victorkingi updated this revision to Diff 550320.
victorkingi added a comment.

rebasing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156320

Files:
  flang/include/flang/Frontend/CodeGenOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/Frontend/TextDiagnosticPrinter.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/optimization-remark.f90

Index: flang/test/Driver/optimization-remark.f90
===
--- /dev/null
+++ flang/test/Driver/optimization-remark.f90
@@ -0,0 +1,52 @@
+! This file tests the -Rpass family of flags (-Rpass, -Rpass-missed
+! and -Rpass-analysis)
+! loop-delete isn't enabled at O0 so we use at least O1
+
+! Check that we can override -Rpass= with -Rno-pass.
+! RUN: %flang_fc1 %s -O1 -Rpass -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
+! RUN: %flang_fc1 %s -O1 -Rpass -Rno-pass -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-REMARKS
+
+! Check "unknown remark option" warning
+! RUN: %flang %s -O1 -R 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-WARN
+
+! Check "unknown remark option" warning with suggestion
+! RUN: %flang %s -O1 -Rpas 2>&1 | FileCheck %s --check-prefix=CHECK-WARN-SUGGEST
+
+! Check -Rno-pass, -Rno-pass-analysis, -Rno-pass-missed nothing emitted
+! RUN: %flang %s -O1 -Rno-pass 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+! RUN: %flang %s -O1 -Rno-pass-missed 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+! RUN: %flang %s -O1 -Rno-pass-analysis 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+
+! Check full -Rpass message is emitted
+! RUN: %flang %s -O1 -Rpass 2>&1 | FileCheck %s
+
+! Check full -Rpass-missed message is emitted
+! RUN: %flang %s -O1 -Rpass-missed 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-MISSED
+
+! Check full -Rpass-analysis message is emitted
+! RUN: %flang %s -O1 -Rpass-analysis 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-ANALYSIS
+
+! CHECK: optimization-remark.f90:48:5: remark: Loop deleted because it is invariant [-Rpass=loop-delete]
+! CHECK-REMARKS-MISSED: optimization-remark.f90:43:5: remark: loop not vectorized [-Rpass-missed=loop-vectorize]
+! CHECK-REMARKS-ANALYSIS: optimization-remark.f90:43:5: remark: loop not vectorized: instruction cannot be vectorized [-Rpass-analysis=loop-vectorize]
+! CHECK-REMARKS: remark:
+! CHECK-NO-REMARKS-NOT: remark:
+
+! CHECK-REMARKS-WARN: warning: unknown remark option '-R' [-Wunknown-warning-option]
+! CHECK-WARN-SUGGEST: warning: unknown remark option '-Rpas'; did you mean '-Rpass'? [-Wunknown-warning-option]
+
+program forttest
+implicit none
+real, dimension(1:50) :: aR1
+integer :: n
+
+do n = 1,50
+aR1(n) = n * 1.34
+print *, "hello"
+end do
+
+do n = 1,50
+aR1(n) = n * 1.34
+end do
+
+end program forttest
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -22,6 +22,7 @@
 #include "mlir/IR/AsmState.h"
 #include "mlir/IR/MLIRContext.h"
 #include "mlir/Pass/PassManager.h"
+#include "clang/Basic/DiagnosticFrontend.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
@@ -100,6 +101,50 @@
   llvm_unreachable("Invalid program action!");
 }
 
+// Emit a warning and typo hint for unknown warning opts
+static void emitUnknownDiagWarning(clang::DiagnosticsEngine &diags,
+   clang::diag::Flavor flavor,
+   llvm::StringRef prefix,
+   llvm::StringRef opt) {
+  llvm::StringRef suggestion =
+  clang::DiagnosticIDs::getNearestOption(flavor, opt);
+  diags.Report(clang::diag::warn_unknown_diag_option)
+  << (flavor == clang::diag::Flavor::WarningOrError ? 0 : 1)
+  << (prefix.str() += std::string(opt)) << !suggestion.empty()
+  << (prefix.str() += std::string(suggestion));
+}
+
+// Remarks are ignored by default in Diagnostic.td, hence, we have to
+// enable them here before execution. Clang follows same idea using
+// ProcessWarningOptions in Warnings.cpp
+// This function is also responsible for emitting early warnings for
+// invalid -R options.
+static void processRemarkOptions(clang::DiagnosticsEngine &diags,
+ const clang::DiagnosticOptions &opts,
+ bool reportDiags = true) {
+  llvm::SmallVector _diags;
+  const llvm::IntrusiveRefCntPtr diagIDs =
+  diags.getDiagnosticIDs();
+
+  for (unsigned i = 0; i < opts.Remarks.size(); i++) {
+llvm::StringRef opt = opts.Remarks[i];
+const auto flavor = clang::diag::

[PATCH] D157687: [clang][AST] TextNodeDumper learned to dump NRVO candidates of return stmts

2023-08-15 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

@aaron.ballman Alright ... I managed to extend an existing test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157687

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


[PATCH] D157452: [RFC][Clang][Codegen] `std::type_info` needs special care with explicit address spaces

2023-08-15 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:5237-5238
+
+  if (VTy->isPointerTy() &&
+  VTy->getPointerAddressSpace() != IRTy->getPointerAddressSpace()) 
{
+// In the case of targets that use a non-default address space for

arsenm wrote:
> you can also just unconditionally call CreateAddrSpaceCast and let it no-op 
> if the types match
I would've if I could've:) Sadly, CastIsValid returns false for address space 
casts between the same AS: 
https://github.com/llvm/llvm-project/blob/ca68a7f956f24aa3882134c5d8e72659355292dc/llvm/lib/IR/Instructions.cpp#L3895,
 and this makes `assert`s flare. I'm not sure if that is vestigial or just 
overly cautious behaviour.


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

https://reviews.llvm.org/D157452

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


[PATCH] D156312: [analyzer] Upstream BitwiseShiftChecker

2023-08-15 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy updated this revision to Diff 550318.
donat.nagy edited the summary of this revision.
donat.nagy added a comment.

I verified that the checker handles the examples in the documentation correctly 
(and added them to the test suite). However, as I was tweaking the examples in 
the documentation, I accidentally found a situation where the checker produces 
a very surprising and arguably incorrect error message.

After investigating this issue, I added the testcases 
`signed_aritmetic_{good,bad}` which document the current sub-optimal state. The 
root cause of this problem is a high-level property of the engine (that it 
assumes that signed overflows are always possible and acceptable) and I don't 
see a local workaround that would silence or fix these incorrect error messages.

@steakhal @NoQ What do you know about these signed overflow issues (I presume 
that analogous issues also appear in other checkers)? How should we handle this 
limitation of this checker?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156312

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/bitwise-ops-nocrash.c
  clang/test/Analysis/bitwise-ops.c
  clang/test/Analysis/bitwise-shift-common.c
  clang/test/Analysis/bitwise-shift-pedantic.c
  clang/test/Analysis/bitwise-shift-sanity-checks.c
  clang/test/Analysis/bitwise-shift-state-update.c
  clang/test/Analysis/casts.c
  clang/test/Analysis/diagnostics/track_subexpressions.cpp
  clang/test/Analysis/left-shift-cxx2a.cpp
  clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
  clang/test/Analysis/symbol-simplification-nonloc-loc.cpp

Index: clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
===
--- clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
+++ clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
@@ -14,7 +14,7 @@
   if (p) {
 // no-crash
   }
-  if (p == (int *)0x404) {
+  if (p == (int *)0x1b) {
 // no-crash
   }
 }
@@ -29,7 +29,7 @@
   if (p) {
 // no-crash
   }
-  if (p == (int *)0x404) {
+  if (p == (int *)0x1b) {
 // no-crash
   }
 }
@@ -43,8 +43,6 @@
   nonloc_OP_loc(p, BINOP(-)); // no-crash
 
   // Bitwise operators:
-  // expected-warning@+2 {{The result of the left shift is undefined due to shifting by '1028', which is greater or equal to the width of type 'int' [core.UndefinedBinaryOperatorResult]}}
-  // expected-warning@+2 {{The result of the right shift is undefined due to shifting by '1028', which is greater or equal to the width of type 'int' [core.UndefinedBinaryOperatorResult]}}
   nonloc_OP_loc(p, BINOP(<<)); // no-crash
   nonloc_OP_loc(p, BINOP(>>)); // no-crash
   nonloc_OP_loc(p, BINOP(&));
Index: clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
===
--- clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
+++ clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
@@ -24,6 +24,7 @@
 // CHECK-NEXT: apiModeling.TrustReturnsNonnull
 // CHECK-NEXT: apiModeling.llvm.CastValue
 // CHECK-NEXT: apiModeling.llvm.ReturnValue
+// CHECK-NEXT: core.BitwiseShift
 // CHECK-NEXT: core.DivideZero
 // CHECK-NEXT: core.DynamicTypePropagation
 // CHECK-NEXT: core.NonnilStringConstants
Index: clang/test/Analysis/left-shift-cxx2a.cpp
===
--- clang/test/Analysis/left-shift-cxx2a.cpp
+++ clang/test/Analysis/left-shift-cxx2a.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple x86_64-apple-darwin13 -Wno-shift-count-overflow -verify=expected,cxx17 -std=c++17 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple x86_64-apple-darwin13 -Wno-shift-count-overflow -verify=expected,cxx2a -std=c++2a %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-disable-checker core.BitwiseShift -triple x86_64-apple-darwin13 -Wno-shift-count-overflow -verify=expected,cxx17 -std=c++17 %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-disable-checker core.BitwiseShift -triple x86_64-apple-darwin13 -Wno-shift-count-overflow -verify=expected,cxx2a -std=c++2a %s
 
 int testNegativeShift(int a) {
   if (a == -5) {
Index: clang/test/Analysis/diagnostics/track_subexpressions.cpp
===
--- clang/test/Analysis/diagnostics/track_subexpressions.cpp
+++ clang/test/Analysis/diagnostics/track_subexpressions.cpp
@@ -12,10 +12,10 @@
 
 void shift_by_undefined_value() {
   uint

[PATCH] D157334: [clang] Define _MSC_EXTENSIONS on -gnu if -fms-extensions is set

2023-08-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I'm comfortable with the changes but we should add a release note so users know 
about the change in behavior. I also wonder if we should take this opportunity 
to add some user-facing documentation around how the target triple, 
`-fms-compatibility`, and `-fms-extensions` interact (what features do they 
enable, what macros do they define, how do they change ABI, etc)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157334

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


[PATCH] D156312: [analyzer] Upstream BitwiseShiftChecker

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

(The release notes entry is still missing, I'll try to add it tomorrow.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156312

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


[clang] 611ce24 - [PGO] Enable `-fprofile-update` for `-fprofile-generate`

2023-08-15 Thread Qiongsi Wu via cfe-commits

Author: Qiongsi Wu
Date: 2023-08-15T10:10:03-04:00
New Revision: 611ce24114aac1befac6e65d85b0daa721cf71fd

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

LOG: [PGO] Enable `-fprofile-update` for `-fprofile-generate`

Currently, the `-fprofile-udpate` is ignored when `-fprofile-generate` is in 
effect. This patch enables `-fprofile-update` for `-fprofile-generate`. This 
patch continues the work from https://reviews.llvm.org/D87737, which added 
`-fprofile-update` in the first place.

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/docs/UsersManual.rst
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/tsan-instrprof-atomic.c
llvm/include/llvm/Passes/PassBuilder.h
llvm/include/llvm/Support/PGOOptions.h
llvm/lib/Passes/PassBuilderPipelines.cpp
llvm/lib/Support/PGOOptions.cpp

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 558e205d69c2a3..d7854d3920f4a9 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2759,9 +2759,6 @@ programs using the same instrumentation method as 
``-fprofile-generate``.
   overhead. ``prefer-atomic`` will be transformed to ``atomic`` when supported
   by the target, or ``single`` otherwise.
 
-  This option currently works with ``-fprofile-arcs`` and 
``-fprofile-instr-generate``,
-  but not with ``-fprofile-generate``.
-
 Disabling Instrumentation
 ^
 

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index e902f7372f3ab5..3e8b2b78a3928b 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -768,7 +768,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 CodeGenOpts.InstrProfileOutput.empty() ? getDefaultProfileGenName()
: 
CodeGenOpts.InstrProfileOutput,
 "", "", CodeGenOpts.MemoryProfileUsePath, nullptr, PGOOptions::IRInstr,
-PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling);
+PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling,
+/*PseudoProbeForProfiling=*/false, CodeGenOpts.AtomicProfileUpdate);
   else if (CodeGenOpts.hasProfileIRUse()) {
 // -fprofile-use.
 auto CSAction = CodeGenOpts.hasProfileCSIRUse() ? PGOOptions::CSIRUse

diff  --git a/clang/test/CodeGen/tsan-instrprof-atomic.c 
b/clang/test/CodeGen/tsan-instrprof-atomic.c
index 23402cffa46d8a..04ca7c08410992 100644
--- a/clang/test/CodeGen/tsan-instrprof-atomic.c
+++ b/clang/test/CodeGen/tsan-instrprof-atomic.c
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 %s -emit-llvm -fprofile-instrument=clang 
-fprofile-update=atomic -o - | FileCheck %s
+// RUN: %clang %s -S -emit-llvm -fprofile-generate -fprofile-update=atomic -o 
- | FileCheck %s
+// RUN: %clang -O3 %s -S -emit-llvm -fprofile-generate -fprofile-update=atomic 
-o - | FileCheck %s
 
 // CHECK: define {{.*}}@foo
 // CHECK-NOT: load {{.*}}foo

diff  --git a/llvm/include/llvm/Passes/PassBuilder.h 
b/llvm/include/llvm/Passes/PassBuilder.h
index fdb407263787f6..08c5b112d903a4 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -560,7 +560,8 @@ class PassBuilder {
 
   /// Add PGOInstrumenation passes for O0 only.
   void addPGOInstrPassesForO0(ModulePassManager &MPM, bool RunProfileGen,
-  bool IsCS, std::string ProfileFile,
+  bool IsCS, bool AtomicCounterUpdate,
+  std::string ProfileFile,
   std::string ProfileRemappingFile,
   IntrusiveRefCntPtr FS);
 
@@ -628,7 +629,8 @@ class PassBuilder {
 ArrayRef Pipeline);
 
   void addPGOInstrPasses(ModulePassManager &MPM, OptimizationLevel Level,
- bool RunProfileGen, bool IsCS, std::string 
ProfileFile,
+ bool RunProfileGen, bool IsCS,
+ bool AtomicCounterUpdate, std::string ProfileFile,
  std::string ProfileRemappingFile,
  ThinOrFullLTOPhase LTOPhase,
  IntrusiveRefCntPtr FS);

diff  --git a/llvm/include/llvm/Support/PGOOptions.h 
b/llvm/include/llvm/Support/PGOOptions.h
index 35670c457745a5..87eb29a8de48a0 100644
--- a/llvm/include/llvm/Support/PGOOptions.h
+++ b/llvm/include/llvm/Support/PGOOptions.h
@@ -32,7 +32,8 @@ struct PGOOptions {
  IntrusiveRefCntPtr FS,
  PGOAction Action = NoAction, CSPGOAction CSAction = NoCSAction,
  bool DebugInfoForProfiling = false,
- bool PseudoProbeForProfiling = false);
+ bool PseudoProbeForProfi

[PATCH] D157280: [PGO] Enable `-fprofile-update` for `-fprofile-generate`

2023-08-15 Thread Qiongsi Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG611ce24114aa: [PGO] Enable `-fprofile-update` for 
`-fprofile-generate` (authored by qiongsiwu1).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157280

Files:
  clang/docs/UsersManual.rst
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/tsan-instrprof-atomic.c
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Support/PGOOptions.h
  llvm/lib/Passes/PassBuilderPipelines.cpp
  llvm/lib/Support/PGOOptions.cpp

Index: llvm/lib/Support/PGOOptions.cpp
===
--- llvm/lib/Support/PGOOptions.cpp
+++ llvm/lib/Support/PGOOptions.cpp
@@ -16,13 +16,14 @@
std::string MemoryProfile,
IntrusiveRefCntPtr FS, PGOAction Action,
CSPGOAction CSAction, bool DebugInfoForProfiling,
-   bool PseudoProbeForProfiling)
+   bool PseudoProbeForProfiling, bool AtomicCounterUpdate)
 : ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
   ProfileRemappingFile(ProfileRemappingFile), MemoryProfile(MemoryProfile),
   Action(Action), CSAction(CSAction),
   DebugInfoForProfiling(DebugInfoForProfiling ||
 (Action == SampleUse && !PseudoProbeForProfiling)),
-  PseudoProbeForProfiling(PseudoProbeForProfiling), FS(std::move(FS)) {
+  PseudoProbeForProfiling(PseudoProbeForProfiling),
+  AtomicCounterUpdate(AtomicCounterUpdate), FS(std::move(FS)) {
   // Note, we do allow ProfileFile.empty() for Action=IRUse LTO can
   // callback with IRUse action without ProfileFile.
 
Index: llvm/lib/Passes/PassBuilderPipelines.cpp
===
--- llvm/lib/Passes/PassBuilderPipelines.cpp
+++ llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -724,7 +724,8 @@
 
 void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
 OptimizationLevel Level, bool RunProfileGen,
-bool IsCS, std::string ProfileFile,
+bool IsCS, bool AtomicCounterUpdate,
+std::string ProfileFile,
 std::string ProfileRemappingFile,
 ThinOrFullLTOPhase LTOPhase,
 IntrusiveRefCntPtr FS) {
@@ -793,13 +794,14 @@
   // Do counter promotion at Level greater than O0.
   Options.DoCounterPromotion = true;
   Options.UseBFIInPromotion = IsCS;
+  Options.Atomic = AtomicCounterUpdate;
   MPM.addPass(InstrProfiling(Options, IsCS));
 }
 
 void PassBuilder::addPGOInstrPassesForO0(
 ModulePassManager &MPM, bool RunProfileGen, bool IsCS,
-std::string ProfileFile, std::string ProfileRemappingFile,
-IntrusiveRefCntPtr FS) {
+bool AtomicCounterUpdate, std::string ProfileFile,
+std::string ProfileRemappingFile, IntrusiveRefCntPtr FS) {
   if (!RunProfileGen) {
 assert(!ProfileFile.empty() && "Profile use expecting a profile file!");
 MPM.addPass(
@@ -819,6 +821,7 @@
   // Do not do counter promotion at O0.
   Options.DoCounterPromotion = false;
   Options.UseBFIInPromotion = IsCS;
+  Options.Atomic = AtomicCounterUpdate;
   MPM.addPass(InstrProfiling(Options, IsCS));
 }
 
@@ -1093,9 +1096,10 @@
   (PGOOpt->Action == PGOOptions::IRInstr ||
PGOOpt->Action == PGOOptions::IRUse)) {
 addPGOInstrPasses(MPM, Level,
-  /* RunProfileGen */ PGOOpt->Action == PGOOptions::IRInstr,
-  /* IsCS */ false, PGOOpt->ProfileFile,
-  PGOOpt->ProfileRemappingFile, Phase, PGOOpt->FS);
+  /*RunProfileGen=*/PGOOpt->Action == PGOOptions::IRInstr,
+  /*IsCS=*/false, PGOOpt->AtomicCounterUpdate,
+  PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile, Phase,
+  PGOOpt->FS);
 MPM.addPass(PGOIndirectCallPromotion(false, false));
   }
   if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink &&
@@ -1306,13 +1310,15 @@
   // instrumentation is after all the inlines are done.
   if (!LTOPreLink && PGOOpt) {
 if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
-  addPGOInstrPasses(MPM, Level, /* RunProfileGen */ true,
-/* IsCS */ true, PGOOpt->CSProfileGenFile,
-PGOOpt->ProfileRemappingFile, LTOPhase, PGOOpt->FS);
+  addPGOInstrPasses(MPM, Level, /*RunProfileGen=*/true,
+/*IsCS=*/true, PGOOpt->AtomicCounterUpdate,
+PGOOpt->CSProfileGenFile, PGOOpt->ProfileRemappingFile,
+LTOPhase, PGOOpt->FS);
 else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
-  addPGOInstrPasses(MPM, Level, /* RunProfileGen */ false,
-   

[PATCH] D74094: Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas

2023-08-15 Thread Lei Huang via Phabricator via cfe-commits
lei added a comment.

Sorry I missed this.  Will kick off now and let you know the results soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74094

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


[PATCH] D157879: [clang] Report missing designated initializers in C++

2023-08-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for working on this! The changes should come with a release note.

I think the diagnostic is triggered a bit to aggressively in the case where 
there is an invalid initializer for a field -- we'll claim there is no 
initializer in that case, but that effectively duplicates the diagnostics 
without adding anything actionable for the user to do (once they fix the 
initialization, both diagnostics go away). Can we silence the diagnostic in 
these cases?




Comment at: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp:64
+   // wmissing-warning@-1 {{missing field 'y' initializer}}
+   // wmissing-warning@-2 {{missing field 'a' initializer}}
 struct C { int :0, x, :0, y, :0; };

This second warning seems wrong, there is an initializer for `a`, it's just not 
a valid one.



Comment at: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp:73
   .x = 1, // override-error {{overrides prior initialization}}
-};
+}; //wmissing-warning {{missing field 'x' initializer}}
+

This warning is quite wrong, there's a whole pile of initializers for `x`. :-)



Comment at: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp:229
 .a = 1, // reorder-error {{field 'b' will be initialized after field 'a'}}
-};
+}; // wmissing-warning {{missing field 'a' initializer}}
 }

I also think this one is wrong.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157879

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


[PATCH] D155081: Specify the developer policy around links to external resources

2023-08-15 Thread Philip Reames via Phabricator via cfe-commits
reames added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:349
 
-* If the patch has been reviewed, add a link to its review page, as shown
-  `here `_.

Removing this item seems very off topic for the change description, and 
certainly hasn't been discussed in the linked thread.  Please add this back in 
a separate commit.

(To be clear, no objections to the overall change, just the removal of the phab 
link text.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155081

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


[PATCH] D157989: [NFC] Initialize pointer field

2023-08-15 Thread Soumi Manna via Phabricator via cfe-commits
Manna created this revision.
Manna added reviewers: aaron.ballman, tahonermann.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Manna requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157989

Files:
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp


Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -931,7 +931,7 @@
   (void)OutlinedFnID;
 
   // Return value of the runtime offloading call.
-  Value *Return;
+  Value *Return = nullptr;
 
   // Arguments for the target kernel.
   SmallVector ArgsVector;


Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -931,7 +931,7 @@
   (void)OutlinedFnID;
 
   // Return value of the runtime offloading call.
-  Value *Return;
+  Value *Return = nullptr;
 
   // Arguments for the target kernel.
   SmallVector ArgsVector;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155081: Specify the developer policy around links to external resources

2023-08-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:349
 
-* If the patch has been reviewed, add a link to its review page, as shown
-  `here `_.

reames wrote:
> Removing this item seems very off topic for the change description, and 
> certainly hasn't been discussed in the linked thread.  Please add this back 
> in a separate commit.
> 
> (To be clear, no objections to the overall change, just the removal of the 
> phab link text.)
Hmm, I thought this was obsoleted by the new text (it is covered by "other 
kinds of metadata"). That said, losing that link is definitely a regression, so 
thank you for pointing this out! I'll find a way to add it back in (either as a 
stand-alone bullet point or incorporated into the new text).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155081

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


[clang] 7a1735c - Add a triple to clang/test/AST/ast-dump-attr-json.cpp

2023-08-15 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2023-08-15T17:05:31+02:00
New Revision: 7a1735cd05c2bc0c336f122f01fb35de66e85e16

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

LOG: Add a triple to clang/test/AST/ast-dump-attr-json.cpp

Otherwise the mangledName field won't match.

Added: 


Modified: 
clang/test/AST/ast-dump-attr-json.cpp

Removed: 




diff  --git a/clang/test/AST/ast-dump-attr-json.cpp 
b/clang/test/AST/ast-dump-attr-json.cpp
index a9679695e954f1..63b33081fba8cb 100644
--- a/clang/test/AST/ast-dump-attr-json.cpp
+++ b/clang/test/AST/ast-dump-attr-json.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -Wdocumentation -ast-dump=json %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux -Wdocumentation -ast-dump=json %s | 
FileCheck %s
 
 int global_decl;
 extern __attribute__((alias("global_decl"))) int global_alias;
@@ -24,7 +24,7 @@ __attribute__ ((section ("SECTION_NAME"))) int section_var;
 // CHECK-NOT: {{^}}Dumping
 // CHECK:  "kind": "VarDecl",
 // CHECK-NEXT:  "loc": {
-// CHECK-NEXT:   "offset": 73,
+// CHECK-NEXT:   "offset": 97,
 // CHECK-NEXT:   "file": "{{.*}}",
 // CHECK-NEXT:   "line": 3,
 // CHECK-NEXT:   "col": 5,
@@ -32,12 +32,12 @@ __attribute__ ((section ("SECTION_NAME"))) int section_var;
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "range": {
 // CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": 69,
+// CHECK-NEXT:"offset": 93,
 // CHECK-NEXT:"col": 1,
 // CHECK-NEXT:"tokLen": 3
 // CHECK-NEXT:   },
 // CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": 73,
+// CHECK-NEXT:"offset": 97,
 // CHECK-NEXT:"col": 5,
 // CHECK-NEXT:"tokLen": 11
 // CHECK-NEXT:   }
@@ -53,19 +53,19 @@ __attribute__ ((section ("SECTION_NAME"))) int section_var;
 // CHECK-NOT: {{^}}Dumping
 // CHECK:  "kind": "VarDecl",
 // CHECK-NEXT:  "loc": {
-// CHECK-NEXT:   "offset": 135,
+// CHECK-NEXT:   "offset": 159,
 // CHECK-NEXT:   "line": 4,
 // CHECK-NEXT:   "col": 50,
 // CHECK-NEXT:   "tokLen": 12
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "range": {
 // CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": 86,
+// CHECK-NEXT:"offset": 110,
 // CHECK-NEXT:"col": 1,
 // CHECK-NEXT:"tokLen": 6
 // CHECK-NEXT:   },
 // CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": 135,
+// CHECK-NEXT:"offset": 159,
 // CHECK-NEXT:"col": 50,
 // CHECK-NEXT:"tokLen": 12
 // CHECK-NEXT:   }
@@ -82,12 +82,12 @@ __attribute__ ((section ("SECTION_NAME"))) int section_var;
 // CHECK-NEXT:"kind": "AliasAttr",
 // CHECK-NEXT:"range": {
 // CHECK-NEXT: "begin": {
-// CHECK-NEXT:  "offset": 108,
+// CHECK-NEXT:  "offset": 132,
 // CHECK-NEXT:  "col": 23,
 // CHECK-NEXT:  "tokLen": 5
 // CHECK-NEXT: },
 // CHECK-NEXT: "end": {
-// CHECK-NEXT:  "offset": 127,
+// CHECK-NEXT:  "offset": 151,
 // CHECK-NEXT:  "col": 42,
 // CHECK-NEXT:  "tokLen": 1
 // CHECK-NEXT: }
@@ -101,18 +101,18 @@ __attribute__ ((section ("SECTION_NAME"))) int 
section_var;
 // CHECK-NOT: {{^}}Dumping
 // CHECK:  "kind": "VarDecl",
 // CHECK-NEXT:  "loc": {
-// CHECK-NEXT:   "offset": 242,
+// CHECK-NEXT:   "offset": 266,
 // CHECK-NEXT:   "col": 50,
 // CHECK-NEXT:   "tokLen": 3
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "range": {
 // CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": 195,
+// CHECK-NEXT:"offset": 219,
 // CHECK-NEXT:"col": 3,
 // CHECK-NEXT:"tokLen": 13
 // CHECK-NEXT:   },
 // CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": 242,
+// CHECK-NEXT:"offset": 266,
 // CHECK-NEXT:"col": 50,
 // CHECK-NEXT:"tokLen": 3
 // CHECK-NEXT:   }
@@ -127,12 +127,12 @@ __attribute__ ((section ("SECTION_NAME"))) int 
section_var;
 // CHECK-NEXT:"kind": "CleanupAttr",
 // CHECK-NEXT:"range": {
 // CHECK-NEXT: "begin": {
-// CHECK-NEXT:  "offset": 210,
+// CHECK-NEXT:  "offset": 234,
 // CHECK-NEXT:  "col": 18,
 // CHECK-NEXT:  "tokLen": 7
 // CHECK-NEXT: },
 // CHECK-NEXT: "end": {
-// CHECK-NEXT:  "offset": 234,
+// CHECK-NEXT:  "offset": 258,
 // CHECK-NEXT:  "col": 42,
 // CHECK-NEXT:  "tokLen": 1
 // CHECK-NEXT: }
@@ -153,19 +153,19 @@ __attribute__ ((section ("SECTION_NAME"))) int 
section_var;
 // CHECK-NOT: {{^}}Dumping
 // CHECK:  "kind": "VarDecl",
 // CHECK-NEXT:  "loc": {
-// CHECK-NEXT:   "offset": 282,
+// CHECK-NEXT:   "offset": 306,
 // CHECK-NEXT:   "line": 11,
 // CHECK-NEXT:   "col": 33,
 // CHECK-NEXT:   "tokLen": 15
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "range": {
 // CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": 250,
+// CHECK-NEXT:"offset": 274,
 // CHECK-NEXT:"col": 1,
 // CHECK-NEXT:"tokLen": 13
 // CHECK-NEXT:   },
 // CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": 282,
+// CHECK-NEXT:"offset": 306,
 // CHECK-NEXT

[PATCH] D157808: [clang] Add missing field to VisibilityAttr json AST dump

2023-08-15 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Since reverting seems non-trivial, I added a triple in 
https://github.com/llvm/llvm-project/commit/7a1735cd05c2bc0c336f122f01fb35de66e85e16
 which I believe should fix the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157808

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


[PATCH] D155081: Specify the developer policy around links to external resources

2023-08-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman marked an inline comment as done.
aaron.ballman added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:349
 
-* If the patch has been reviewed, add a link to its review page, as shown
-  `here `_.

aaron.ballman wrote:
> reames wrote:
> > Removing this item seems very off topic for the change description, and 
> > certainly hasn't been discussed in the linked thread.  Please add this back 
> > in a separate commit.
> > 
> > (To be clear, no objections to the overall change, just the removal of the 
> > phab link text.)
> Hmm, I thought this was obsoleted by the new text (it is covered by "other 
> kinds of metadata"). That said, losing that link is definitely a regression, 
> so thank you for pointing this out! I'll find a way to add it back in (either 
> as a stand-alone bullet point or incorporated into the new text).
I restored the link in 
https://github.com/llvm/llvm-project/commit/a1562bbc63b49a70b39ba075d9a3332f50cea11d
 as part of the new bullet; please let me know if you have additional concerns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155081

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


[PATCH] D157917: clang/HIP: Use abs builtins instead of implementing them

2023-08-15 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx accepted this revision.
AlexVlx added a comment.
This revision is now accepted and ready to land.

LGTM, thanks.


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

https://reviews.llvm.org/D157917

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


[PATCH] D156693: [clang][ASTImporter]Skip check depth of friend template parameter

2023-08-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/unittests/AST/StructuralEquivalenceTest.cpp:1716
+   IgnoreTemplateParmDepthAtNonTypeTemplateParmDecl) {
+  auto t = makeDecls(
+  R"(

The convention is to start variable names with uppercase, for example "Decls".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

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


[PATCH] D157989: [NFC] Initialize pointer field

2023-08-15 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann accepted this revision.
tahonermann added a comment.
This revision is now accepted and ready to land.

Looks good to me. I see that `OpenMPIRBuilder::emitTargetKernel()` can return 
without having assigned the `Return` parameter.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157989

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


[PATCH] D157687: [clang][AST] TextNodeDumper learned to dump NRVO candidates of return stmts

2023-08-15 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!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157687

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


[PATCH] D156320: [Flang][Driver] Add support for Rpass and related options

2023-08-15 Thread victorkingi via Phabricator via cfe-commits
victorkingi updated this revision to Diff 550345.
victorkingi added a comment.

rebasing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156320

Files:
  flang/include/flang/Frontend/CodeGenOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/Frontend/TextDiagnosticPrinter.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/optimization-remark.f90

Index: flang/test/Driver/optimization-remark.f90
===
--- /dev/null
+++ flang/test/Driver/optimization-remark.f90
@@ -0,0 +1,52 @@
+! This file tests the -Rpass family of flags (-Rpass, -Rpass-missed
+! and -Rpass-analysis)
+! loop-delete isn't enabled at O0 so we use at least O1
+
+! Check that we can override -Rpass= with -Rno-pass.
+! RUN: %flang_fc1 %s -O1 -Rpass -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
+! RUN: %flang_fc1 %s -O1 -Rpass -Rno-pass -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-REMARKS
+
+! Check "unknown remark option" warning
+! RUN: %flang %s -O1 -R 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-WARN
+
+! Check "unknown remark option" warning with suggestion
+! RUN: %flang %s -O1 -Rpas 2>&1 | FileCheck %s --check-prefix=CHECK-WARN-SUGGEST
+
+! Check -Rno-pass, -Rno-pass-analysis, -Rno-pass-missed nothing emitted
+! RUN: %flang %s -O1 -Rno-pass 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+! RUN: %flang %s -O1 -Rno-pass-missed 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+! RUN: %flang %s -O1 -Rno-pass-analysis 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-NO-REMARKS
+
+! Check full -Rpass message is emitted
+! RUN: %flang %s -O1 -Rpass 2>&1 | FileCheck %s
+
+! Check full -Rpass-missed message is emitted
+! RUN: %flang %s -O1 -Rpass-missed 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-MISSED
+
+! Check full -Rpass-analysis message is emitted
+! RUN: %flang %s -O1 -Rpass-analysis 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS-ANALYSIS
+
+! CHECK: optimization-remark.f90:48:5: remark: Loop deleted because it is invariant [-Rpass=loop-delete]
+! CHECK-REMARKS-MISSED: optimization-remark.f90:43:5: remark: loop not vectorized [-Rpass-missed=loop-vectorize]
+! CHECK-REMARKS-ANALYSIS: optimization-remark.f90:43:5: remark: loop not vectorized: instruction cannot be vectorized [-Rpass-analysis=loop-vectorize]
+! CHECK-REMARKS: remark:
+! CHECK-NO-REMARKS-NOT: remark:
+
+! CHECK-REMARKS-WARN: warning: unknown remark option '-R' [-Wunknown-warning-option]
+! CHECK-WARN-SUGGEST: warning: unknown remark option '-Rpas'; did you mean '-Rpass'? [-Wunknown-warning-option]
+
+program forttest
+implicit none
+real, dimension(1:50) :: aR1
+integer :: n
+
+do n = 1,50
+aR1(n) = n * 1.34
+print *, "hello"
+end do
+
+do n = 1,50
+aR1(n) = n * 1.34
+end do
+
+end program forttest
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -22,6 +22,7 @@
 #include "mlir/IR/AsmState.h"
 #include "mlir/IR/MLIRContext.h"
 #include "mlir/Pass/PassManager.h"
+#include "clang/Basic/DiagnosticFrontend.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
@@ -100,6 +101,50 @@
   llvm_unreachable("Invalid program action!");
 }
 
+// Emit a warning and typo hint for unknown warning opts
+static void emitUnknownDiagWarning(clang::DiagnosticsEngine &diags,
+   clang::diag::Flavor flavor,
+   llvm::StringRef prefix,
+   llvm::StringRef opt) {
+  llvm::StringRef suggestion =
+  clang::DiagnosticIDs::getNearestOption(flavor, opt);
+  diags.Report(clang::diag::warn_unknown_diag_option)
+  << (flavor == clang::diag::Flavor::WarningOrError ? 0 : 1)
+  << (prefix.str() += std::string(opt)) << !suggestion.empty()
+  << (prefix.str() += std::string(suggestion));
+}
+
+// Remarks are ignored by default in Diagnostic.td, hence, we have to
+// enable them here before execution. Clang follows same idea using
+// ProcessWarningOptions in Warnings.cpp
+// This function is also responsible for emitting early warnings for
+// invalid -R options.
+static void processRemarkOptions(clang::DiagnosticsEngine &diags,
+ const clang::DiagnosticOptions &opts,
+ bool reportDiags = true) {
+  llvm::SmallVector _diags;
+  const llvm::IntrusiveRefCntPtr diagIDs =
+  diags.getDiagnosticIDs();
+
+  for (unsigned i = 0; i < opts.Remarks.size(); i++) {
+llvm::StringRef opt = opts.Remarks[i];
+const auto flavor = clang::diag::

[PATCH] D155081: Specify the developer policy around links to external resources

2023-08-15 Thread Philip Reames via Phabricator via cfe-commits
reames added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:349
 
-* If the patch has been reviewed, add a link to its review page, as shown
-  `here `_.

aaron.ballman wrote:
> aaron.ballman wrote:
> > reames wrote:
> > > Removing this item seems very off topic for the change description, and 
> > > certainly hasn't been discussed in the linked thread.  Please add this 
> > > back in a separate commit.
> > > 
> > > (To be clear, no objections to the overall change, just the removal of 
> > > the phab link text.)
> > Hmm, I thought this was obsoleted by the new text (it is covered by "other 
> > kinds of metadata"). That said, losing that link is definitely a 
> > regression, so thank you for pointing this out! I'll find a way to add it 
> > back in (either as a stand-alone bullet point or incorporated into the new 
> > text).
> I restored the link in 
> https://github.com/llvm/llvm-project/commit/a1562bbc63b49a70b39ba075d9a3332f50cea11d
>  as part of the new bullet; please let me know if you have additional 
> concerns.
That 90% covers it.  What's left is some minor framing.  I'd suggest separating 
that point into two.  The first should be recommended metadata (phab, issues 
link), and the second can be the additional metadata point.  Something like:

```
If the patch has been reviewed, add a link to its review page, as shown
  `here `_. If 
the patch fixes a bug in GitHub Issues, we encourage adding a reference to the 
issue being closed, as described `here 
`_.

It is also acceptable to add other metadata to the commit message to automate 
processes, including for downstream consumers. and including links to resources 
that are not available to the entire community. However, such links and/or 
metadata should not be used in place of making the commit message 
self-explanatory.  

```
All of the above is just reorganizing what you had written with some very minor 
copy editing.  I'd separately suggest adding the following sentence at the end 
of the second bullet.

Note that such non-public links are *only* allowed in commit messages, and 
should not be included in the submitted code.  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155081

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


[clang] 1849318 - [clang][ExtractAPI] Add support for Objective-C categories

2023-08-15 Thread via cfe-commits

Author: ruturaj4
Date: 2023-08-15T10:34:21-05:00
New Revision: 184931853924b53f5f07602229b9d129540ab02a

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

LOG: [clang][ExtractAPI] Add support for Objective-C categories

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

Added: 
clang/test/ExtractAPI/objc_module_category.m
clang/test/ExtractAPI/objc_various_categories.m

Modified: 
clang/include/clang/ExtractAPI/API.h
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/lib/ExtractAPI/API.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index 437ac953b7409d..a965f49c8e91b2 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -80,6 +80,7 @@ struct APIRecord {
 RK_ObjCInstanceMethod,
 RK_ObjCInterface,
 RK_ObjCCategory,
+RK_ObjCCategoryModule,
 RK_ObjCProtocol,
 RK_MacroDefinition,
 RK_Typedef,
@@ -153,6 +154,9 @@ struct APIRecord {
 Comment(Comment), Declaration(Declaration), SubHeading(SubHeading),
 IsFromSystemHeader(IsFromSystemHeader), Kind(Kind) {}
 
+  APIRecord(RecordKind Kind, StringRef USR, StringRef Name)
+  : USR(USR), Name(Name), Kind(Kind) {}
+
   // Pure virtual destructor to make APIRecord abstract
   virtual ~APIRecord() = 0;
 };
@@ -643,6 +647,8 @@ struct CXXClassRecord : APIRecord {
 /// This holds information associated with Objective-C categories.
 struct ObjCCategoryRecord : ObjCContainerRecord {
   SymbolReference Interface;
+  /// Determine whether the Category is derived from external class interface.
+  bool IsFromExternalModule = false;
 
   ObjCCategoryRecord(StringRef USR, StringRef Name, PresumedLoc Loc,
  AvailabilitySet Availabilities, const DocComment &Comment,
@@ -895,7 +901,7 @@ class APISet {
   AvailabilitySet Availability, const DocComment &Comment,
   DeclarationFragments Declaration,
   DeclarationFragments SubHeading, SymbolReference Interface,
-  bool IsFromSystemHeader);
+  bool IsFromSystemHeader, bool IsFromExternalModule);
 
   /// Create and add an Objective-C interface record into the API set.
   ///

diff  --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h 
b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
index bc35ee73ca8ad5..904942a69691a6 100644
--- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -578,9 +578,17 @@ bool ExtractAPIVisitorBase::VisitObjCCategoryDecl(
   SymbolReference Interface(InterfaceDecl->getName(),
 API.recordUSR(InterfaceDecl));
 
+  bool IsFromExternalModule = true;
+  for (const auto &Interface : API.getObjCInterfaces()) {
+if (InterfaceDecl->getName() == Interface.second.get()->Name) {
+  IsFromExternalModule = false;
+  break;
+}
+  }
+
   ObjCCategoryRecord *ObjCCategoryRecord = API.addObjCCategory(
   Name, USR, Loc, AvailabilitySet(Decl), Comment, Declaration, SubHeading,
-  Interface, isInSystemHeader(Decl));
+  Interface, isInSystemHeader(Decl), IsFromExternalModule);
 
   getDerivedExtractAPIVisitor().recordObjCMethods(ObjCCategoryRecord,
   Decl->methods());

diff  --git a/clang/include/clang/ExtractAPI/Serialization/SerializerBase.h 
b/clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
index afb84c20ddefea..68c20b3f6c6f9d 100644
--- a/clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
+++ b/clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
@@ -39,6 +39,8 @@ template  class APISetVisitor {
 
 getDerived()->traverseObjCProtocols();
 
+getDerived()->traverseObjCCategories();
+
 getDerived()->traverseMacroDefinitionRecords();
 
 getDerived()->traverseTypedefRecords();
@@ -84,6 +86,11 @@ template  class APISetVisitor {
   getDerived()->visitObjCContainerRecord(*Protocol.second);
   }
 
+  void traverseObjCCategories() {
+for (const auto &Category : API.getObjCCategories())
+  getDerived()->visitObjCCategoryRecord(*Category.second);
+  }
+
   void traverseMacroDefinitionRecords() {
 for (const auto &Macro : API.getMacros())
   getDerived()->visitMacroDefinitionRecord(*Macro.second);
@@ -113,6 +120,9 @@ template  class APISetVisitor {
   /// Visit an Objective-C container record.
   void visitObjCContainerRecord(const ObjCContainerRecord &Record){};
 
+  /// Visit an Objective-C category re

[PATCH] D152770: [clang][ExtractAPI] Add support for Objective-C categories

2023-08-15 Thread R4444 via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG184931853924: [clang][ExtractAPI] Add support for 
Objective-C categories (authored by Ruturaj4).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152770

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/objc_module_category.m
  clang/test/ExtractAPI/objc_various_categories.m

Index: clang/test/ExtractAPI/objc_various_categories.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_various_categories.m
@@ -0,0 +1,507 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang -extract-api -x objective-c-header \
+// RUN: -target arm64-apple-macosx \
+// RUN: %t/myclass_1.h \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+#import "myclass_1.h"
+#import "Foundation.h"
+
+@interface MyClass1 (MyCategory1)
+- (int) SomeMethod;
+@end
+
+@interface NSString (Category1)
+-(void) StringMethod;
+@end
+
+@interface NSString (Category2)
+-(void) StringMethod2;
+@end
+
+//--- myclass_1.h
+@interface MyClass1
+@end
+
+//--- Foundation.h
+@interface NSString
+@end
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)MyClass1(im)SomeMethod",
+  "target": "c:objc(cs)MyClass1",
+  "targetFallback": "MyClass1"
+},
+{
+  "kind": "extensionTo",
+  "source": "c:objc(cy)NSString@Category1",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod",
+  "target": "c:objc(cy)NSString@Category1",
+  "targetFallback": "Category1"
+},
+{
+  "kind": "extensionTo",
+  "source": "c:objc(cy)NSString@Category2",
+  "target": "c:objc(cs)NSString",
+  "targetFallback": "NSString"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)NSString(im)StringMethod2",
+  "target": "c:objc(cy)NSString@Category2",
+  "targetFallback": "Category2"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyClass1"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyClass1"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"position": {
+  "character": 12,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/myclass_1.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "MyClass1"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "MyClass1"
+  }
+],
+"title": "MyClass1"
+  },
+  "pathComponents": [
+"MyClass1"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "text",
+  "spelling": "- ("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": ") "
+},
+{
+  "kind": "identifier",
+  "spelling": "SomeMethod"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+

[PATCH] D157989: [NFC] Initialize pointer field

2023-08-15 Thread Soumi Manna via Phabricator via cfe-commits
Manna added a comment.

Thank you @tahonermann for reviews and feedbacks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157989

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


[PATCH] D157990: [clangd] Add --query-driver flag to clangd-indexer

2023-08-15 Thread Alex Cameron via Phabricator via cfe-commits
tetsuo-cpp created this revision.
tetsuo-cpp added reviewers: sammccall, nridge.
tetsuo-cpp added projects: clang-tools-extra, All.
Herald added subscribers: kadircet, arphaman.
tetsuo-cpp requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

When using `clangd` for cross-compiled projects, it's necessary to use the 
`--query-driver` flag so that `clangd` can extract the compiler's built-in 
header paths. However, there's no such flag for `clangd-indexer` so we're 
unable to build a working static index for these projects.

This patch adds a `--query-driver` flag to `clangd-indexer` for this scenario.

I saw some tests under `clang-tools-extra/clangd/test/` but I think the 
cross-compilation case is a bit more complex to test. Let me know if you'd like 
me to look into this further.

Resolves: https://github.com/clangd/clangd/issues/1717


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157990

Files:
  clang-tools-extra/clangd/indexer/IndexerMain.cpp


Index: clang-tools-extra/clangd/indexer/IndexerMain.cpp
===
--- clang-tools-extra/clangd/indexer/IndexerMain.cpp
+++ clang-tools-extra/clangd/indexer/IndexerMain.cpp
@@ -38,6 +38,16 @@
"binary RIFF format")),
llvm::cl::init(IndexFileFormat::RIFF));
 
+static llvm::cl::list QueryDriverGlobs{
+"query-driver",
+llvm::cl::desc(
+"Comma separated list of globs for white-listing gcc-compatible "
+"drivers that are safe to execute. Drivers matching any of these globs 
"
+"will be used to extract system includes. e.g. "
+"/usr/bin/**/clang-*,/path/to/repo/**/g++-*"),
+llvm::cl::CommaSeparated,
+};
+
 class IndexActionFactory : public tooling::FrontendActionFactory {
 public:
   IndexActionFactory(IndexFileIn &Result) : Result(Result) {}
@@ -144,12 +154,16 @@
 
   // Collect symbols found in each translation unit, merging as we go.
   clang::clangd::IndexFileIn Data;
+  auto Mangler = std::make_shared(
+  clang::clangd::CommandMangler::detect());
+  Mangler->SystemIncludeExtractor = clang::clangd::getSystemIncludeExtractor(
+  static_cast>(
+  clang::clangd::QueryDriverGlobs));
   auto Err = Executor->get()->execute(
   std::make_unique(Data),
   clang::tooling::ArgumentsAdjuster(
-  [Mangler = std::make_shared(
-   clang::clangd::CommandMangler::detect())](
-  const std::vector &Args, llvm::StringRef File) {
+  [Mangler = std::move(Mangler)](const std::vector &Args,
+ llvm::StringRef File) {
 clang::tooling::CompileCommand Cmd;
 Cmd.CommandLine = Args;
 Mangler->operator()(Cmd, File);


Index: clang-tools-extra/clangd/indexer/IndexerMain.cpp
===
--- clang-tools-extra/clangd/indexer/IndexerMain.cpp
+++ clang-tools-extra/clangd/indexer/IndexerMain.cpp
@@ -38,6 +38,16 @@
"binary RIFF format")),
llvm::cl::init(IndexFileFormat::RIFF));
 
+static llvm::cl::list QueryDriverGlobs{
+"query-driver",
+llvm::cl::desc(
+"Comma separated list of globs for white-listing gcc-compatible "
+"drivers that are safe to execute. Drivers matching any of these globs "
+"will be used to extract system includes. e.g. "
+"/usr/bin/**/clang-*,/path/to/repo/**/g++-*"),
+llvm::cl::CommaSeparated,
+};
+
 class IndexActionFactory : public tooling::FrontendActionFactory {
 public:
   IndexActionFactory(IndexFileIn &Result) : Result(Result) {}
@@ -144,12 +154,16 @@
 
   // Collect symbols found in each translation unit, merging as we go.
   clang::clangd::IndexFileIn Data;
+  auto Mangler = std::make_shared(
+  clang::clangd::CommandMangler::detect());
+  Mangler->SystemIncludeExtractor = clang::clangd::getSystemIncludeExtractor(
+  static_cast>(
+  clang::clangd::QueryDriverGlobs));
   auto Err = Executor->get()->execute(
   std::make_unique(Data),
   clang::tooling::ArgumentsAdjuster(
-  [Mangler = std::make_shared(
-   clang::clangd::CommandMangler::detect())](
-  const std::vector &Args, llvm::StringRef File) {
+  [Mangler = std::move(Mangler)](const std::vector &Args,
+ llvm::StringRef File) {
 clang::tooling::CompileCommand Cmd;
 Cmd.CommandLine = Args;
 Mangler->operator()(Cmd, File);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156693: [clang][ASTImporter]Skip check depth of friend template parameter

2023-08-15 Thread Qizhi Hu via Phabricator via cfe-commits
jcsxky updated this revision to Diff 550352.
jcsxky added a comment.

Fix variable names according to the convention.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

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

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1,5 +1,6 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTStructuralEquivalence.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Testing/CommandLineArgs.h"
@@ -130,15 +131,18 @@
 return makeStmts(Wrap(SrcCode0), Wrap(SrcCode1), Lang, AMatcher);
   }
 
-  bool testStructuralMatch(Decl *D0, Decl *D1) {
+  bool testStructuralMatch(Decl *D0, Decl *D1,
+   bool IgnoreTemplateParmDepth = false) {
 llvm::DenseSet> NonEquivalentDecls01;
 llvm::DenseSet> NonEquivalentDecls10;
 StructuralEquivalenceContext Ctx01(
-D0->getASTContext(), D1->getASTContext(),
-NonEquivalentDecls01, StructuralEquivalenceKind::Default, false, false);
+D0->getASTContext(), D1->getASTContext(), NonEquivalentDecls01,
+StructuralEquivalenceKind::Default, false, false, false,
+IgnoreTemplateParmDepth);
 StructuralEquivalenceContext Ctx10(
-D1->getASTContext(), D0->getASTContext(),
-NonEquivalentDecls10, StructuralEquivalenceKind::Default, false, false);
+D1->getASTContext(), D0->getASTContext(), NonEquivalentDecls10,
+StructuralEquivalenceKind::Default, false, false, false,
+IgnoreTemplateParmDepth);
 bool Eq01 = Ctx01.IsEquivalent(D0, D1);
 bool Eq10 = Ctx10.IsEquivalent(D1, D0);
 EXPECT_EQ(Eq01, Eq10);
@@ -165,8 +169,9 @@
 return testStructuralMatch(get<0>(t), get<1>(t));
   }
 
-  bool testStructuralMatch(std::tuple t) {
-return testStructuralMatch(get<0>(t), get<1>(t));
+  bool testStructuralMatch(std::tuple t,
+   bool IgnoreTemplateParmDepth = false) {
+return testStructuralMatch(get<0>(t), get<1>(t), IgnoreTemplateParmDepth);
   }
 };
 
@@ -1689,6 +1694,40 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceTemplateTest,
+   IgnoreTemplateParmDepthAtTemplateTypeParmDecl) {
+  auto Decls = makeDecls(
+  R"(
+template struct A;
+  )",
+  R"(
+template struct S {
+  template friend struct A;
+};
+  )",
+  Lang_CXX03, classTemplateDecl(hasName("A")),
+  classTemplateDecl(hasName("A")));
+  EXPECT_TRUE(testStructuralMatch(Decls));
+  EXPECT_TRUE(testStructuralMatch(Decls, true));
+}
+
+TEST_F(StructuralEquivalenceTemplateTest,
+   IgnoreTemplateParmDepthAtNonTypeTemplateParmDecl) {
+  auto Decls = makeDecls(
+  R"(
+template struct A;
+  )",
+  R"(
+template struct S {
+  template friend struct A;
+};
+  )",
+  Lang_CXX03, classTemplateDecl(hasName("A")),
+  classTemplateDecl(hasName("A")));
+  EXPECT_FALSE(testStructuralMatch(Decls));
+  EXPECT_TRUE(testStructuralMatch(Decls, true));
+}
+
 TEST_F(
 StructuralEquivalenceTemplateTest,
 ClassTemplSpecWithInequivalentShadowedTemplArg) {
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4246,6 +4246,58 @@
   EXPECT_TRUE(Imported->getPreviousDecl());
 }
 
+TEST_P(ImportFriendClasses, SkipComparingFriendTemplateDepth) {
+  Decl *ToTU = getToTuDecl(
+  R"(
+  template 
+  class A;
+
+  template 
+  class A {
+  public:
+template 
+friend class A;
+
+A(T x)  :x(x) {}
+
+  private:
+T x;
+  };
+  )",
+  Lang_CXX11);
+
+  auto *Fwd = FirstDeclMatcher().match(
+  ToTU,
+  classTemplateDecl(has(cxxRecordDecl(hasDefinition(), hasName("A");
+  Decl *FromTU = getTuDecl(
+  R"(
+  template 
+  class A;
+
+  template 
+  class A {
+  public:
+template 
+friend class A;
+
+A(T x) : x(x) {}
+
+  private:
+T x;
+  };
+
+  A a1(0);
+  )",
+  Lang_CXX11, "input1.cc");
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU,
+  classTemplateDecl(has(cxxRecordDecl(hasDefinition(), hasName("A");
+  auto *ToA = Import(FromA, Lang_CXX11);
+  EXPECT_TRUE(ToA);
+  EXPECT_EQ(Fwd->getTemplatedDecl()->getTypeForDecl(),
+ToA->getTemplatedDecl()->getTypeForDe

[clang] 3bfafc4 - [clang][AST] TextNodeDumper learned to output template specialization kind

2023-08-15 Thread Timo Stripf via cfe-commits

Author: Timo Stripf
Date: 2023-08-15T15:46:31Z
New Revision: 3bfafc4f22870d00631fe1466676007d73bf6794

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

LOG: [clang][AST] TextNodeDumper learned to output template specialization kind

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/include/clang/AST/TextNodeDumper.h
clang/lib/AST/TextNodeDumper.cpp
clang/test/AST/HLSL/this-reference-template.hlsl
clang/test/AST/ast-dump-decl.cpp
clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
clang/test/SemaCXX/lambda-conversion-op-cc.cpp
clang/test/SemaOpenCLCXX/address-space-deduction.clcpp

Removed: 




diff  --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index e8480543a3b87e..771dab01c2ba04 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -202,6 +202,7 @@ class TextNodeDumper
   void dumpName(const NamedDecl *ND);
   void dumpAccessSpecifier(AccessSpecifier AS);
   void dumpCleanupObject(const ExprWithCleanups::CleanupObject &C);
+  void dumpTemplateSpecializationKind(TemplateSpecializationKind TSK);
 
   void dumpDeclRef(const Decl *D, StringRef Label = {});
 

diff  --git a/clang/lib/AST/TextNodeDumper.cpp 
b/clang/lib/AST/TextNodeDumper.cpp
index d6c72d6207df22..a562e6d8140115 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -734,6 +734,26 @@ void TextNodeDumper::dumpCleanupObject(
 llvm_unreachable("unexpected cleanup type");
 }
 
+void clang::TextNodeDumper::dumpTemplateSpecializationKind(
+TemplateSpecializationKind TSK) {
+  switch (TSK) {
+  case TSK_Undeclared:
+break;
+  case TSK_ImplicitInstantiation:
+OS << " implicit_instantiation";
+break;
+  case TSK_ExplicitSpecialization:
+OS << " explicit_specialization";
+break;
+  case TSK_ExplicitInstantiationDeclaration:
+OS << " explicit_instantiation_declaration";
+break;
+  case TSK_ExplicitInstantiationDefinition:
+OS << " explicit_instantiation_definition";
+break;
+  }
+}
+
 void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef Label) {
   if (!D)
 return;
@@ -1744,6 +1764,7 @@ void TextNodeDumper::VisitIndirectFieldDecl(const 
IndirectFieldDecl *D) {
 void TextNodeDumper::VisitFunctionDecl(const FunctionDecl *D) {
   dumpName(D);
   dumpType(D->getType());
+  dumpTemplateSpecializationKind(D->getTemplateSpecializationKind());
 
   StorageClass SC = D->getStorageClass();
   if (SC != SC_None)
@@ -1840,6 +1861,7 @@ void TextNodeDumper::VisitFieldDecl(const FieldDecl *D) {
 void TextNodeDumper::VisitVarDecl(const VarDecl *D) {
   dumpName(D);
   dumpType(D->getType());
+  dumpTemplateSpecializationKind(D->getTemplateSpecializationKind());
   StorageClass SC = D->getStorageClass();
   if (SC != SC_None)
 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
@@ -2028,6 +2050,9 @@ void TextNodeDumper::VisitTypeAliasTemplateDecl(
 
 void TextNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
   VisitRecordDecl(D);
+  if (const auto *CTSD = dyn_cast(D))
+dumpTemplateSpecializationKind(CTSD->getSpecializationKind());
+
   if (!D->isCompleteDefinition())
 return;
 

diff  --git a/clang/test/AST/HLSL/this-reference-template.hlsl 
b/clang/test/AST/HLSL/this-reference-template.hlsl
index c27d69d36ca3e9..3b7fba3efdc747 100644
--- a/clang/test/AST/HLSL/this-reference-template.hlsl
+++ b/clang/test/AST/HLSL/this-reference-template.hlsl
@@ -32,13 +32,13 @@ void main() {
 // CHECK-NEXT:-MemberExpr 0x{{[0-9A-Fa-f]+}}  'V' lvalue .Second 
0x{{[0-9A-Fa-f]+}}
 // CHECK-NEXT:-CXXThisExpr 0x{{[0-9A-Fa-f]+}}  'Pair' lvalue 
implicit this
 
-// CHECK: -CXXMethodDecl 0x{{[0-9A-Fa-f]+}}  line:8:5 
used getFirst 'int ()' implicit-inline
+// CHECK: -CXXMethodDecl 0x{{[0-9A-Fa-f]+}}  line:8:5 
used getFirst 'int ()' implicit_instantiation implicit-inline
 // CHECK-NEXT:-CompoundStmt 0x{{[0-9A-Fa-f]+}} 
 // CHECK-NEXT:-ReturnStmt 0x{{[0-9A-Fa-f]+}} 
 // CHECK-NEXT:-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  
'int':'int' 
 // CHECK-NEXT:-MemberExpr 0x{{[0-9A-Fa-f]+}}  'int':'int' 
lvalue .First 0x{{[0-9A-Fa-f]+}}
 // CHECK-NEXT:-CXXThisExpr 0x{{[0-9A-Fa-f]+}}  'Pair' 
lvalue this
-// CHECK-NEXT:-CXXMethodDecl 0x{{[0-9A-Fa-f]+}}  
line:12:5 used getSecond 'float ()' implicit-inline
+// CHECK-NEXT:-CXXMethodDecl 0x{{[0-9A-Fa-f]+}}  
line:12:5 used getSecond 'float ()' implicit_instantiation implicit-inline
 // CHECK-NEXT:-CompoundStmt 0x{{[0-9A-Fa-f]+}} 
 // CHECK-NEXT:-ReturnStmt 0x{{[0-9A-Fa-f]+}} 
 // CHECK-NEXT:-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'float':'float' 


diff  --git a/clang/test/AST/ast-dump-decl.cpp 
b/clang/test/AST/ast-dump-dec

[PATCH] D157705: [clang][AST] TextNodeDumper learned to output template specialization kind

2023-08-15 Thread Timo Stripf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3bfafc4f2287: [clang][AST] TextNodeDumper learned to output 
template specialization kind (authored by strimo378).

Changed prior to commit:
  https://reviews.llvm.org/D157705?vs=549346&id=550354#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157705

Files:
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/HLSL/this-reference-template.hlsl
  clang/test/AST/ast-dump-decl.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
  clang/test/SemaCXX/lambda-conversion-op-cc.cpp
  clang/test/SemaOpenCLCXX/address-space-deduction.clcpp

Index: clang/test/SemaOpenCLCXX/address-space-deduction.clcpp
===
--- clang/test/SemaOpenCLCXX/address-space-deduction.clcpp
+++ clang/test/SemaOpenCLCXX/address-space-deduction.clcpp
@@ -6,7 +6,7 @@
 constexpr int foo = 0;
 
 //CHECK: |-VarDecl {{.*}} foo1 'T' cinit
-//CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global long':'__global long' cinit
+//CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global long':'__global long' implicit_instantiation cinit
 template 
 T foo1 = 0;
 
Index: clang/test/SemaCXX/lambda-conversion-op-cc.cpp
===
--- clang/test/SemaCXX/lambda-conversion-op-cc.cpp
+++ clang/test/SemaCXX/lambda-conversion-op-cc.cpp
@@ -67,11 +67,11 @@
   //
   // CHECK: FunctionTemplateDecl {{.*}} operator()
   // LIN64: CXXMethodDecl {{.*}} operator() 'auto (auto) const' inline
-  // LIN64: CXXMethodDecl {{.*}} operator() 'void (char) const' inline
-  // LIN64: CXXMethodDecl {{.*}} operator() 'void (int) const' inline
+  // LIN64: CXXMethodDecl {{.*}} operator() 'void (char) const' implicit_instantiation inline
+  // LIN64: CXXMethodDecl {{.*}} operator() 'void (int) const' implicit_instantiation inline
   // WIN32: CXXMethodDecl {{.*}} operator() 'auto (auto) __attribute__((thiscall)) const' inline
-  // WIN32: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((thiscall)) const' inline
-  // WIN32: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((thiscall)) const' inline
+  // WIN32: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((thiscall)) const' implicit_instantiation inline
+  // WIN32: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((thiscall)) const' implicit_instantiation inline
   //
   // NODEF: FunctionTemplateDecl {{.*}} operator auto (*)(type-parameter-0-0)
   // VECDEF: FunctionTemplateDecl {{.*}} operator auto (*)(type-parameter-0-0) __attribute__((vectorcall))
@@ -108,8 +108,8 @@
   // CHECK: LambdaExpr
   // CHECK: FunctionTemplateDecl {{.*}} operator()
   // CHECK: CXXMethodDecl {{.*}} operator() 'auto (auto) __attribute__((vectorcall)) const' inline
-  // CHECK: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((vectorcall)) const' inline
-  // CHECK: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((vectorcall)) const' inline
+  // CHECK: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((vectorcall)) const' implicit_instantiation inline
+  // CHECK: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((vectorcall)) const' implicit_instantiation inline
   // CHECK: FunctionTemplateDecl {{.*}} operator auto (*)(type-parameter-0-0) __attribute__((vectorcall))
   // LIN64: CXXConversionDecl {{.*}} operator auto (*)(type-parameter-0-0) __attribute__((vectorcall)) 'auto (*() const noexcept)(auto) __attribute__((vectorcall))'
   // LIN64: CXXConversionDecl {{.*}} operator auto (*)(char) __attribute__((vectorcall)) 'void (*() const noexcept)(char) __attribute__((vectorcall))'
Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
===
--- clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
@@ -184,7 +184,7 @@
 // CHECK-NEXT: | |   `-ReturnStmt [[ADDR_39:0x[a-z0-9]*]] 
 // CHECK-NEXT: | | `-CXXStaticCastExpr [[ADDR_40:0x[a-z0-9]*]]  '_Up':'typename remove_reference<_Tp>::type' xvalue static_cast<_Up &&> 
 // CHECK-NEXT: | |   `-DeclRefExpr [[ADDR_41:0x[a-z0-9]*]]  '_Tp' {{.*}}ParmVar [[ADDR_34]] '__t' '_Tp &&'
-// CHECK-NEXT: | |-FunctionDecl [[ADDR_42:0x[a-z0-9]*]]  line:11:1 used move 'typename remove_reference::type &&(float &)' inline
+// CHECK-NEXT: | |-FunctionDecl [[ADDR_42:0x[a-z0-9]*]]  line:11:1 used move 'typename remove_reference::type &&(float &)' implicit_instantiation inline
 // CHECK-NEXT: | | |-TemplateArgument type 'float &'
 // CHECK-NEXT: | | | `-LValueReferenceType [[ADDR_7]] 'float &'
 // CHECK-NEXT: | | |   `-BuiltinType [[ADDR_8]] 'float'
@@ -201,7 +201,7 @@
 // CHECK-NEXT: | |   `-ReturnStmt [[ADDR_49:0

[PATCH] D155081: Specify the developer policy around links to external resources

2023-08-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:349
 
-* If the patch has been reviewed, add a link to its review page, as shown
-  `here `_.

reames wrote:
> aaron.ballman wrote:
> > aaron.ballman wrote:
> > > reames wrote:
> > > > Removing this item seems very off topic for the change description, and 
> > > > certainly hasn't been discussed in the linked thread.  Please add this 
> > > > back in a separate commit.
> > > > 
> > > > (To be clear, no objections to the overall change, just the removal of 
> > > > the phab link text.)
> > > Hmm, I thought this was obsoleted by the new text (it is covered by 
> > > "other kinds of metadata"). That said, losing that link is definitely a 
> > > regression, so thank you for pointing this out! I'll find a way to add it 
> > > back in (either as a stand-alone bullet point or incorporated into the 
> > > new text).
> > I restored the link in 
> > https://github.com/llvm/llvm-project/commit/a1562bbc63b49a70b39ba075d9a3332f50cea11d
> >  as part of the new bullet; please let me know if you have additional 
> > concerns.
> That 90% covers it.  What's left is some minor framing.  I'd suggest 
> separating that point into two.  The first should be recommended metadata 
> (phab, issues link), and the second can be the additional metadata point.  
> Something like:
> 
> ```
> If the patch has been reviewed, add a link to its review page, as shown
>   `here `_. 
> If the patch fixes a bug in GitHub Issues, we encourage adding a reference to 
> the issue being closed, as described `here 
> `_.
> 
> It is also acceptable to add other metadata to the commit message to automate 
> processes, including for downstream consumers. and including links to 
> resources that are not available to the entire community. However, such links 
> and/or metadata should not be used in place of making the commit message 
> self-explanatory.  
> 
> ```
> All of the above is just reorganizing what you had written with some very 
> minor copy editing.  I'd separately suggest adding the following sentence at 
> the end of the second bullet.
> 
> Note that such non-public links are *only* allowed in commit messages, and 
> should not be included in the submitted code.  
I did some minor rewording for clarity, so how about:
```
* If the patch has been reviewed, add a link to its review page, as shown
  `here `__.
  If the patch fixes a bug in GitHub Issues, we encourage adding a reference to
  the issue being closed, as described
  `here `__.

* It is also acceptable to add other metadata to the commit message to automate
  processes, including for downstream consumers. This metadata can include
  links to resources that are not available to the entire community. However,
  such links and/or metadata should not be used in place of making the commit
  message self-explanatory.
```

> All of the above is just reorganizing what you had written with some very 
> minor copy editing. I'd separately suggest adding the following sentence at 
> the end of the second bullet.
> 
> Note that such non-public links are *only* allowed in commit messages, and 
> should not be included in the submitted code.

I think this might need more wordsmithing, which is why I left out of the 
simple reorganization. The non-public links aren't limited to commit messages 
-- for example, they're fine to use in a phabricator review or github issue 
comment, etc. So I don't want to be too restrictive with the wording, though I 
agree with the intent. How about something along the lines of:

Note that such non-public links should not be included in the submitted code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155081

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


[PATCH] D155081: Specify the developer policy around links to external resources

2023-08-15 Thread Philip Reames via Phabricator via cfe-commits
reames added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:349
 
-* If the patch has been reviewed, add a link to its review page, as shown
-  `here `_.

aaron.ballman wrote:
> reames wrote:
> > aaron.ballman wrote:
> > > aaron.ballman wrote:
> > > > reames wrote:
> > > > > Removing this item seems very off topic for the change description, 
> > > > > and certainly hasn't been discussed in the linked thread.  Please add 
> > > > > this back in a separate commit.
> > > > > 
> > > > > (To be clear, no objections to the overall change, just the removal 
> > > > > of the phab link text.)
> > > > Hmm, I thought this was obsoleted by the new text (it is covered by 
> > > > "other kinds of metadata"). That said, losing that link is definitely a 
> > > > regression, so thank you for pointing this out! I'll find a way to add 
> > > > it back in (either as a stand-alone bullet point or incorporated into 
> > > > the new text).
> > > I restored the link in 
> > > https://github.com/llvm/llvm-project/commit/a1562bbc63b49a70b39ba075d9a3332f50cea11d
> > >  as part of the new bullet; please let me know if you have additional 
> > > concerns.
> > That 90% covers it.  What's left is some minor framing.  I'd suggest 
> > separating that point into two.  The first should be recommended metadata 
> > (phab, issues link), and the second can be the additional metadata point.  
> > Something like:
> > 
> > ```
> > If the patch has been reviewed, add a link to its review page, as shown
> >   `here `_. 
> > If the patch fixes a bug in GitHub Issues, we encourage adding a reference 
> > to the issue being closed, as described `here 
> > `_.
> > 
> > It is also acceptable to add other metadata to the commit message to 
> > automate processes, including for downstream consumers. and including links 
> > to resources that are not available to the entire community. However, such 
> > links and/or metadata should not be used in place of making the commit 
> > message self-explanatory.  
> > 
> > ```
> > All of the above is just reorganizing what you had written with some very 
> > minor copy editing.  I'd separately suggest adding the following sentence 
> > at the end of the second bullet.
> > 
> > Note that such non-public links are *only* allowed in commit messages, and 
> > should not be included in the submitted code.  
> I did some minor rewording for clarity, so how about:
> ```
> * If the patch has been reviewed, add a link to its review page, as shown
>   `here `__.
>   If the patch fixes a bug in GitHub Issues, we encourage adding a reference 
> to
>   the issue being closed, as described
>   `here `__.
> 
> * It is also acceptable to add other metadata to the commit message to 
> automate
>   processes, including for downstream consumers. This metadata can include
>   links to resources that are not available to the entire community. However,
>   such links and/or metadata should not be used in place of making the commit
>   message self-explanatory.
> ```
> 
> > All of the above is just reorganizing what you had written with some very 
> > minor copy editing. I'd separately suggest adding the following sentence at 
> > the end of the second bullet.
> > 
> > Note that such non-public links are *only* allowed in commit messages, and 
> > should not be included in the submitted code.
> 
> I think this might need more wordsmithing, which is why I left out of the 
> simple reorganization. The non-public links aren't limited to commit messages 
> -- for example, they're fine to use in a phabricator review or github issue 
> comment, etc. So I don't want to be too restrictive with the wording, though 
> I agree with the intent. How about something along the lines of:
> 
> Note that such non-public links should not be included in the submitted code.
LGTM to both parts.  Wording is hard, and good catch on the second.  :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155081

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


[PATCH] D155081: Specify the developer policy around links to external resources

2023-08-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman marked 2 inline comments as done.
aaron.ballman added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:349
 
-* If the patch has been reviewed, add a link to its review page, as shown
-  `here `_.

reames wrote:
> aaron.ballman wrote:
> > reames wrote:
> > > aaron.ballman wrote:
> > > > aaron.ballman wrote:
> > > > > reames wrote:
> > > > > > Removing this item seems very off topic for the change description, 
> > > > > > and certainly hasn't been discussed in the linked thread.  Please 
> > > > > > add this back in a separate commit.
> > > > > > 
> > > > > > (To be clear, no objections to the overall change, just the removal 
> > > > > > of the phab link text.)
> > > > > Hmm, I thought this was obsoleted by the new text (it is covered by 
> > > > > "other kinds of metadata"). That said, losing that link is definitely 
> > > > > a regression, so thank you for pointing this out! I'll find a way to 
> > > > > add it back in (either as a stand-alone bullet point or incorporated 
> > > > > into the new text).
> > > > I restored the link in 
> > > > https://github.com/llvm/llvm-project/commit/a1562bbc63b49a70b39ba075d9a3332f50cea11d
> > > >  as part of the new bullet; please let me know if you have additional 
> > > > concerns.
> > > That 90% covers it.  What's left is some minor framing.  I'd suggest 
> > > separating that point into two.  The first should be recommended metadata 
> > > (phab, issues link), and the second can be the additional metadata point. 
> > >  Something like:
> > > 
> > > ```
> > > If the patch has been reviewed, add a link to its review page, as shown
> > >   `here 
> > > `_. If 
> > > the patch fixes a bug in GitHub Issues, we encourage adding a reference 
> > > to the issue being closed, as described `here 
> > > `_.
> > > 
> > > It is also acceptable to add other metadata to the commit message to 
> > > automate processes, including for downstream consumers. and including 
> > > links to resources that are not available to the entire community. 
> > > However, such links and/or metadata should not be used in place of making 
> > > the commit message self-explanatory.  
> > > 
> > > ```
> > > All of the above is just reorganizing what you had written with some very 
> > > minor copy editing.  I'd separately suggest adding the following sentence 
> > > at the end of the second bullet.
> > > 
> > > Note that such non-public links are *only* allowed in commit messages, 
> > > and should not be included in the submitted code.  
> > I did some minor rewording for clarity, so how about:
> > ```
> > * If the patch has been reviewed, add a link to its review page, as shown
> >   `here `__.
> >   If the patch fixes a bug in GitHub Issues, we encourage adding a 
> > reference to
> >   the issue being closed, as described
> >   `here `__.
> > 
> > * It is also acceptable to add other metadata to the commit message to 
> > automate
> >   processes, including for downstream consumers. This metadata can include
> >   links to resources that are not available to the entire community. 
> > However,
> >   such links and/or metadata should not be used in place of making the 
> > commit
> >   message self-explanatory.
> > ```
> > 
> > > All of the above is just reorganizing what you had written with some very 
> > > minor copy editing. I'd separately suggest adding the following sentence 
> > > at the end of the second bullet.
> > > 
> > > Note that such non-public links are *only* allowed in commit messages, 
> > > and should not be included in the submitted code.
> > 
> > I think this might need more wordsmithing, which is why I left out of the 
> > simple reorganization. The non-public links aren't limited to commit 
> > messages -- for example, they're fine to use in a phabricator review or 
> > github issue comment, etc. So I don't want to be too restrictive with the 
> > wording, though I agree with the intent. How about something along the 
> > lines of:
> > 
> > Note that such non-public links should not be included in the submitted 
> > code.
> LGTM to both parts.  Wording is hard, and good catch on the second.  :)
Thank you for the help! Because this is rearranging existing text and the 
additional text is a minor point of clarity, I'll land those changes shortly -- 
but as always, if folks have more post-commit review feedback on those changes, 
please speak up and I'll work with you on it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155081

___
cfe-commits mailing list
cfe-commits@lists.

  1   2   3   >