[PATCH] D100713: [clang] NFC: refactor usage of getDecltypeForParenthesizedExpr and getValueKind

2021-04-17 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:5845
+  if (!To->isRValue()) {
+QualType T = Self.Context.getDecltypeForParenthesizedExpr(To);
 InitializedEntity Entity = InitializedEntity::InitializeTemporary(T);

aaronpuchert wrote:
> The quote doesn't reference parenthesized expressions, isn't this just 
> coincidentally the same thing?
It's fundamentally the same thing. The `getDecltypeForParenthesizedExpr` name 
is what I tried to keep, I don't have better ideas there.



Comment at: clang/lib/StaticAnalyzer/Core/CallEvent.cpp:73
   const Expr *E = getOriginExpr();
-  if (!E)
-return Ctx.VoidTy;
-  assert(E);
-
-  QualType ResultTy = E->getType();
-
-  // A function that returns a reference to 'int' will have a result type
-  // of simply 'int'. Check the origin expr's value kind to recover the
-  // proper type.
-  switch (E->getValueKind()) {
-  case VK_LValue:
-ResultTy = Ctx.getLValueReferenceType(ResultTy);
-break;
-  case VK_XValue:
-ResultTy = Ctx.getRValueReferenceType(ResultTy);
-break;
-  case VK_RValue:
-// No adjustment is necessary.
-break;
-  }
-
-  return ResultTy;
+  return E ? Ctx.getDecltypeForParenthesizedExpr(E) : Ctx.VoidTy;
 }

aaronpuchert wrote:
> This seems also more of a coincidence. There is no parenthesized expression, 
> we're just trying to figure out a function return type.
> 
> (Ok, it's not a pure coincidence, the decltype is probably chosen to match 
> that type.)
Yes, not a coincidence, still fundamentally the same thing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100713

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


[PATCH] D100713: [clang] NFC: refactor usage of getDecltypeForParenthesizedExpr and getValueKind

2021-04-17 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

It seems that using `is*Value` and the introduction of 
`getDecltypeForParenthesizedExpr` could be two separate changes.




Comment at: clang/lib/Sema/SemaExprCXX.cpp:5845
+  if (!To->isRValue()) {
+QualType T = Self.Context.getDecltypeForParenthesizedExpr(To);
 InitializedEntity Entity = InitializedEntity::InitializeTemporary(T);

The quote doesn't reference parenthesized expressions, isn't this just 
coincidentally the same thing?



Comment at: clang/lib/StaticAnalyzer/Core/CallEvent.cpp:73
   const Expr *E = getOriginExpr();
-  if (!E)
-return Ctx.VoidTy;
-  assert(E);
-
-  QualType ResultTy = E->getType();
-
-  // A function that returns a reference to 'int' will have a result type
-  // of simply 'int'. Check the origin expr's value kind to recover the
-  // proper type.
-  switch (E->getValueKind()) {
-  case VK_LValue:
-ResultTy = Ctx.getLValueReferenceType(ResultTy);
-break;
-  case VK_XValue:
-ResultTy = Ctx.getRValueReferenceType(ResultTy);
-break;
-  case VK_RValue:
-// No adjustment is necessary.
-break;
-  }
-
-  return ResultTy;
+  return E ? Ctx.getDecltypeForParenthesizedExpr(E) : Ctx.VoidTy;
 }

This seems also more of a coincidence. There is no parenthesized expression, 
we're just trying to figure out a function return type.

(Ok, it's not a pure coincidence, the decltype is probably chosen to match that 
type.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100713

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


[PATCH] D100713: [clang] NFC: refactor usage of getDecltypeForParenthesizedExpr and getValueKind

2021-04-17 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 338352.
mizvekov added a comment.

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100713

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprObjC.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp

Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -70,28 +70,7 @@
 QualType CallEvent::getResultType() const {
   ASTContext  = getState()->getStateManager().getContext();
   const Expr *E = getOriginExpr();
-  if (!E)
-return Ctx.VoidTy;
-  assert(E);
-
-  QualType ResultTy = E->getType();
-
-  // A function that returns a reference to 'int' will have a result type
-  // of simply 'int'. Check the origin expr's value kind to recover the
-  // proper type.
-  switch (E->getValueKind()) {
-  case VK_LValue:
-ResultTy = Ctx.getLValueReferenceType(ResultTy);
-break;
-  case VK_XValue:
-ResultTy = Ctx.getRValueReferenceType(ResultTy);
-break;
-  case VK_RValue:
-// No adjustment is necessary.
-break;
-  }
-
-  return ResultTy;
+  return E ? Ctx.getDecltypeForParenthesizedExpr(E) : Ctx.VoidTy;
 }
 
 static bool isCallback(QualType T) {
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8830,29 +8830,6 @@
   return Context.getTypeOfExprType(E);
 }
 
-/// getDecltypeForParenthesizedExpr - Given an expr, will return the type for
-/// that expression, as in [dcl.type.simple]p4 but without taking id-expressions
-/// and class member access into account.
-QualType Sema::getDecltypeForParenthesizedExpr(Expr *E) {
-  // C++11 [dcl.type.simple]p4:
-  //   [...]
-  QualType T = E->getType();
-  switch (E->getValueKind()) {
-  // - otherwise, if e is an xvalue, decltype(e) is T&&, where T is the
-  //   type of e;
-  case VK_XValue:
-return Context.getRValueReferenceType(T);
-  // - otherwise, if e is an lvalue, decltype(e) is T&, where T is the
-  //   type of e;
-  case VK_LValue:
-return Context.getLValueReferenceType(T);
-  //  - otherwise, decltype(e) is the type of e.
-  case VK_RValue:
-return T;
-  }
-  llvm_unreachable("Unknown value kind");
-}
-
 /// getDecltypeForExpr - Given an expr, will return the decltype for
 /// that expression, according to the rules in C++11
 /// [dcl.type.simple]p4 and C++11 [expr.lambda.prim]p18.
@@ -8917,7 +8894,7 @@
 }
   }
 
-  return S.getDecltypeForParenthesizedExpr(E);
+  return S.Context.getDecltypeForParenthesizedExpr(E);
 }
 
 QualType Sema::BuildDecltypeType(Expr *E, SourceLocation Loc,
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5830,7 +5830,7 @@
  Entity.getType()) &&
 canPerformArrayCopy(Entity)) {
   // If source is a prvalue, use it directly.
-  if (Initializer->getValueKind() == VK_RValue) {
+  if (Initializer->isRValue()) {
 AddArrayInitStep(DestType, /*IsGNUExtension*/false);
 return;
   }
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -5841,10 +5841,8 @@
   //   -- If E2 is an xvalue: E1 can be converted to match E2 if E1 can be
   //  implicitly converted to the type "rvalue reference to R2", subject to
   //  the constraint that the reference must bind directly.
-  if (To->isLValue() || To->isXValue()) {
-QualType T = To->isLValue() ? Self.Context.getLValueReferenceType(ToType)
-: Self.Context.getRValueReferenceType(ToType);
-
+  if (!To->isRValue()) {
+QualType T = Self.Context.getDecltypeForParenthesizedExpr(To);
 InitializedEntity Entity = InitializedEntity::InitializeTemporary(T);
 
 InitializationSequence InitSeq(Self, Entity, Kind, From);
@@ -8663,7 +8661,7 @@
 TemplateParameterList *TPL =
 ReturnTypeRequirement.getTypeConstraintTemplateParameterList();
 QualType MatchedType =
-getDecltypeForParenthesizedExpr(E).getCanonicalType();
+Context.getDecltypeForParenthesizedExpr(E).getCanonicalType();
 llvm::SmallVector Args;
 

[PATCH] D100713: [clang] NFC: refactor usage of getDecltypeForParenthesizedExpr and getValueKind

2021-04-17 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added subscribers: lxfind, martong.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This clenaup patch:

- Refactors a bunch of duplicates of getDecltypeForParenthesizedExpr into a 
common implementation.
- Converts `Expr->getValueKind()` uses into calls to `is?Value` helpers.

Signed-off-by: Matheus Izvekov 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100713

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprObjC.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp

Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -70,28 +70,7 @@
 QualType CallEvent::getResultType() const {
   ASTContext  = getState()->getStateManager().getContext();
   const Expr *E = getOriginExpr();
-  if (!E)
-return Ctx.VoidTy;
-  assert(E);
-
-  QualType ResultTy = E->getType();
-
-  // A function that returns a reference to 'int' will have a result type
-  // of simply 'int'. Check the origin expr's value kind to recover the
-  // proper type.
-  switch (E->getValueKind()) {
-  case VK_LValue:
-ResultTy = Ctx.getLValueReferenceType(ResultTy);
-break;
-  case VK_XValue:
-ResultTy = Ctx.getRValueReferenceType(ResultTy);
-break;
-  case VK_RValue:
-// No adjustment is necessary.
-break;
-  }
-
-  return ResultTy;
+  return E ? Ctx.getDecltypeForParenthesizedExpr(E) : Ctx.VoidTy;
 }
 
 static bool isCallback(QualType T) {
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8830,29 +8830,6 @@
   return Context.getTypeOfExprType(E);
 }
 
-/// getDecltypeForParenthesizedExpr - Given an expr, will return the type for
-/// that expression, as in [dcl.type.simple]p4 but without taking id-expressions
-/// and class member access into account.
-QualType Sema::getDecltypeForParenthesizedExpr(Expr *E) {
-  // C++11 [dcl.type.simple]p4:
-  //   [...]
-  QualType T = E->getType();
-  switch (E->getValueKind()) {
-  // - otherwise, if e is an xvalue, decltype(e) is T&&, where T is the
-  //   type of e;
-  case VK_XValue:
-return Context.getRValueReferenceType(T);
-  // - otherwise, if e is an lvalue, decltype(e) is T&, where T is the
-  //   type of e;
-  case VK_LValue:
-return Context.getLValueReferenceType(T);
-  //  - otherwise, decltype(e) is the type of e.
-  case VK_RValue:
-return T;
-  }
-  llvm_unreachable("Unknown value kind");
-}
-
 /// getDecltypeForExpr - Given an expr, will return the decltype for
 /// that expression, according to the rules in C++11
 /// [dcl.type.simple]p4 and C++11 [expr.lambda.prim]p18.
@@ -8917,7 +8894,7 @@
 }
   }
 
-  return S.getDecltypeForParenthesizedExpr(E);
+  return S.Context.getDecltypeForParenthesizedExpr(E);
 }
 
 QualType Sema::BuildDecltypeType(Expr *E, SourceLocation Loc,
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5830,7 +5830,7 @@
  Entity.getType()) &&
 canPerformArrayCopy(Entity)) {
   // If source is a prvalue, use it directly.
-  if (Initializer->getValueKind() == VK_RValue) {
+  if (Initializer->isRValue()) {
 AddArrayInitStep(DestType, /*IsGNUExtension*/false);
 return;
   }
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -5841,10 +5841,8 @@
   //   -- If E2 is an xvalue: E1 can be converted to match E2 if E1 can be
   //  implicitly converted to the type "rvalue reference to R2", subject to
   //  the constraint that the reference must bind directly.
-  if (To->isLValue() || To->isXValue()) {
-QualType T = To->isLValue() ? Self.Context.getLValueReferenceType(ToType)
-: Self.Context.getRValueReferenceType(ToType);
-
+  if (!To->isRValue()) {
+QualType T = Self.Context.getDecltypeForParenthesizedExpr(To);
 InitializedEntity Entity = InitializedEntity::InitializeTemporary(T);
 
 InitializationSequence InitSeq(Self, Entity, Kind, From);
@@ -8663,7 +8661,7 @@
 TemplateParameterList *TPL =
 

[PATCH] D100712: [AST] Add NestedNameSpecifierLoc accessors to node introspection

2021-04-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: njames93.
Herald added subscribers: mgrang, mgorny.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Change the GetLocations API to take instances by const-ref.  This class
is copyable.  APIs return copies, so the API taking a pointer was
needlessly hard to use.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100712

Files:
  clang/include/clang/Tooling/NodeIntrospection.h
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/DumpTool/APIData.h
  clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
  clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
  clang/unittests/Introspection/IntrospectionTest.cpp

Index: clang/unittests/Introspection/IntrospectionTest.cpp
===
--- clang/unittests/Introspection/IntrospectionTest.cpp
+++ clang/unittests/Introspection/IntrospectionTest.cpp
@@ -205,6 +205,30 @@
 STRING_LOCATION_STDPAIR(MethodDecl, getInnerLocStart()),
 STRING_LOCATION_STDPAIR(MethodDecl, getLocation()),
 STRING_LOCATION_STDPAIR(MethodDecl, getOuterLocStart()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getLocalBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getLocalEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getLocalBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getLocalEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getLocalBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getLocalEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getPrefix().getBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getPrefix().getEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getPrefix().getLocalBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getPrefix().getPrefix().getLocalEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getTypeLoc().getAs().getLAngleLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getTypeLoc().getAs().getRAngleLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getTypeLoc().getAs().getTemplateNameLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getTypeLoc().getBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getPrefix().getTypeLoc().getEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getTypeLoc().getAs().getNameLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getTypeLoc().getBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getQualifierLoc().getTypeLoc().getEndLoc()),
 STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getLParenLoc()),
 STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getLocalRangeBegin()),
 STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getLocalRangeEnd()),
@@ -214,6 +238,14 @@
 STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getNamedTypeLoc().getAs().getTemplateNameLoc()),
 STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getNamedTypeLoc().getBeginLoc()),
 STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getNamedTypeLoc().getEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getLocalBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getLocalEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getPrefix().getBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getQualifierLoc().getPrefix().getEndLoc()),

[PATCH] D100516: [AST] Add TypeLoc support to node introspection

2021-04-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp:172-176
+  if (TypeLocBase && Node->getName() == "getLocalSourceRange")
+continue;
+  if ((ASTClass->getName() == "PointerLikeTypeLoc" ||
+   ASTClass->getName() == "TypeofLikeTypeLoc") &&
+  Node->getName() == "getLocalSourceRange")

njames93 wrote:
> njames93 wrote:
> > Can we have a comment explaining why we are discarding these?
> nit: can this be addressed?
There is a comment above, so I'm not sure what's missing. But please feel free 
to adjust it post commit!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100516

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


[PATCH] D100516: [AST] Add TypeLoc support to node introspection

2021-04-17 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdd68942f1d79: [AST] Add TypeLoc support to node 
introspection (authored by stephenkelly).

Changed prior to commit:
  https://reviews.llvm.org/D100516?vs=338049=338342#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100516

Files:
  clang/include/clang/Tooling/NodeIntrospection.h
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/DumpTool/APIData.h
  clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
  clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.h
  clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
  clang/unittests/Introspection/IntrospectionTest.cpp

Index: clang/unittests/Introspection/IntrospectionTest.cpp
===
--- clang/unittests/Introspection/IntrospectionTest.cpp
+++ clang/unittests/Introspection/IntrospectionTest.cpp
@@ -26,25 +26,27 @@
 using ::testing::Pair;
 using ::testing::UnorderedElementsAre;
 
-template
-std::map
+template 
+std::vector>
 FormatExpected(const MapType ) {
-  std::map Result;
+  std::vector> Result;
   llvm::transform(llvm::make_filter_range(Accessors,
   [](const auto ) {
 return Accessor.first.isValid();
   }),
-  std::inserter(Result, Result.end()),
-  [](const auto ) {
-return std::make_pair(LocationCallFormatterCpp::format(
-  *Accessor.second.get()),
-  Accessor.first);
+  std::back_inserter(Result), [](const auto ) {
+return std::make_pair(
+LocationCallFormatterCpp::format(*Accessor.second),
+Accessor.first);
   });
   return Result;
 }
 
 #define STRING_LOCATION_PAIR(INSTANCE, LOC) Pair(#LOC, INSTANCE->LOC)
 
+#define STRING_LOCATION_STDPAIR(INSTANCE, LOC) \
+  std::make_pair(std::string(#LOC), INSTANCE->LOC)
+
 /**
   A test formatter for a hypothetical language which needs
   neither casts nor '->'.
@@ -191,26 +193,85 @@
   auto ExpectedLocations =
   FormatExpected(Result.LocationAccessors);
 
-  EXPECT_THAT(ExpectedLocations,
-  UnorderedElementsAre(
-  STRING_LOCATION_PAIR(MethodDecl, getBeginLoc()),
-  STRING_LOCATION_PAIR(MethodDecl, getBodyRBrace()),
-  STRING_LOCATION_PAIR(MethodDecl, getInnerLocStart()),
-  STRING_LOCATION_PAIR(MethodDecl, getLocation()),
-  STRING_LOCATION_PAIR(MethodDecl, getOuterLocStart()),
-  STRING_LOCATION_PAIR(MethodDecl, getTypeSpecEndLoc()),
-  STRING_LOCATION_PAIR(MethodDecl, getTypeSpecStartLoc()),
-  STRING_LOCATION_PAIR(MethodDecl, getEndLoc(;
+  llvm::sort(ExpectedLocations);
+
+  // clang-format off
+  EXPECT_EQ(
+  llvm::makeArrayRef(ExpectedLocations),
+  (ArrayRef>{
+STRING_LOCATION_STDPAIR(MethodDecl, getBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getBodyRBrace()),
+STRING_LOCATION_STDPAIR(MethodDecl, getEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getInnerLocStart()),
+STRING_LOCATION_STDPAIR(MethodDecl, getLocation()),
+STRING_LOCATION_STDPAIR(MethodDecl, getOuterLocStart()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getLParenLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getLocalRangeBegin()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getLocalRangeEnd()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getRParenLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getNamedTypeLoc().getAs().getLAngleLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getNamedTypeLoc().getAs().getRAngleLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getNamedTypeLoc().getAs().getTemplateNameLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getNamedTypeLoc().getBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getAs().getNamedTypeLoc().getEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getBeginLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getEndLoc()),
+STRING_LOCATION_STDPAIR(MethodDecl, getTypeSourceInfo()->getTypeLoc().getAs().getReturnLoc().getNextTypeLoc().getAs().getLAngleLoc()),

[clang] dd68942 - [AST] Add TypeLoc support to node introspection

2021-04-17 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-04-17T22:58:02+01:00
New Revision: dd68942f1d79986267a58c9a9924522680d5c82b

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

LOG: [AST] Add TypeLoc support to node introspection

Extend the matchers gathering API for types to record template
parameters.  The TypeLoc type hierarchy has some types which are
templates used in CRTP such as PointerLikeTypeLoc.  Record the inherited
template and template arguments of types inheriting those CRTP types in
the ClassInheritance map.  Because the name inherited from is now
computed, the value type in that map changes from StringRef to
std::string.  This also causes the toJSON override signature used to
serialize that map to change.

Remove the logic for skipping over empty ClassData instances.  Several
classes such as TypeOfExprTypeLoc inherit a CRTP class which provides
interesting locations though the derived class does not.  Record it as a
class to make the locations it inherits available.

Record the typeSourceInfo accessors too as they provide access to
TypeLocs in many classes.

The existing unit tests use UnorderedElementsAre to compare the
introspection result with the expected result.  Our current
implementation of google mock (in gmock-generated-matchers.h) is limited
to support for comparing a container of 10 elements.  As we are now
returning more than 10 results for one of the introspection tests,
change it to instead compare against an ordered vector of pairs.

Because a macro is used to generate API strings and API calls, disable
clang-format in blocks of expected results.  Otherwise clang-format
would insert whitespaces which would then be compared against the
introspected strings and fail the test.

Introduce a recursion guard in the generated code.  The TypeLoc class
has IgnoreParens() API which by default returns itself, so it would
otherwise recurse infinitely.

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

Added: 


Modified: 
clang/include/clang/Tooling/NodeIntrospection.h
clang/lib/Tooling/CMakeLists.txt
clang/lib/Tooling/DumpTool/APIData.h
clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.h
clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
clang/unittests/Introspection/IntrospectionTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/NodeIntrospection.h 
b/clang/include/clang/Tooling/NodeIntrospection.h
index c8518ea635461..dd7ffe3991207 100644
--- a/clang/include/clang/Tooling/NodeIntrospection.h
+++ b/clang/include/clang/Tooling/NodeIntrospection.h
@@ -86,6 +86,7 @@ NodeLocationAccessors GetLocations(clang::CXXCtorInitializer 
const *Object);
 NodeLocationAccessors GetLocations(clang::NestedNameSpecifierLoc const *);
 NodeLocationAccessors GetLocations(clang::TemplateArgumentLoc const *);
 NodeLocationAccessors GetLocations(clang::CXXBaseSpecifier const *);
+NodeLocationAccessors GetLocations(clang::TypeLoc const &);
 NodeLocationAccessors GetLocations(clang::DynTypedNode const );
 } // namespace NodeIntrospection
 } // namespace tooling

diff  --git a/clang/lib/Tooling/CMakeLists.txt 
b/clang/lib/Tooling/CMakeLists.txt
index e90b681e16f42..dfb732371dfbf 100644
--- a/clang/lib/Tooling/CMakeLists.txt
+++ b/clang/lib/Tooling/CMakeLists.txt
@@ -58,6 +58,10 @@ NodeLocationAccessors NodeIntrospection::GetLocations(
 clang::CXXBaseSpecifier const*) {
   return {};
 }
+NodeLocationAccessors NodeIntrospection::GetLocations(
+clang::TypeLoc const&) {
+  return {};
+}
 NodeLocationAccessors
 NodeIntrospection::GetLocations(clang::DynTypedNode const &) {
   return {};

diff  --git a/clang/lib/Tooling/DumpTool/APIData.h 
b/clang/lib/Tooling/DumpTool/APIData.h
index 0ec53f6e7dc3c..6ebf017b5c8f7 100644
--- a/clang/lib/Tooling/DumpTool/APIData.h
+++ b/clang/lib/Tooling/DumpTool/APIData.h
@@ -16,13 +16,11 @@ namespace clang {
 namespace tooling {
 
 struct ClassData {
-
-  bool isEmpty() const {
-return ASTClassLocations.empty() && ASTClassRanges.empty();
-  }
-
   std::vector ASTClassLocations;
   std::vector ASTClassRanges;
+  std::vector TemplateParms;
+  std::vector TypeSourceInfos;
+  std::vector TypeLocs;
   // TODO: Extend this with locations available via typelocs etc.
 };
 

diff  --git a/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp 
b/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
index a19114a060645..497cd3bdce2ca 100644
--- a/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
+++ b/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
@@ -22,18 +22,24 @@ ASTSrcLocProcessor::ASTSrcLocProcessor(StringRef JsonPath)
 
   Finder = std::make_unique(std::move(FinderOptions));
   Finder->addMatcher(
-  cxxRecordDecl(
-  isDefinition(),
-  isSameOrDerivedFrom(
-  

[PATCH] D79714: [Diagnostics] Restore -Wdeprecated warning when user-declared copy assignment operator is defined as deleted (PR45634)

2021-04-17 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 338336.

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

https://reviews.llvm.org/D79714

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/deprecated-copy-dtor.cpp
  clang/test/SemaCXX/deprecated-copy-user-provided-copy.cpp
  clang/test/SemaCXX/deprecated-copy-user-provided-dtor.cpp
  clang/test/SemaCXX/deprecated-copy.cpp
  clang/test/SemaCXX/deprecated.cpp

Index: clang/test/SemaCXX/deprecated.cpp
===
--- clang/test/SemaCXX/deprecated.cpp
+++ clang/test/SemaCXX/deprecated.cpp
@@ -83,30 +83,31 @@
 #if __cplusplus >= 201103L
 namespace DeprecatedCopy {
   struct Assign {
-Assign =(const Assign&); // expected-warning {{definition of implicit copy constructor for 'Assign' is deprecated because it has a user-declared copy assignment operator}}
+Assign =(const Assign&); // expected-warning {{definition of implicit copy constructor for 'Assign' is deprecated because it has a user-provided copy assignment operator}}
   };
   Assign a1, a2(a1); // expected-note {{implicit copy constructor for 'DeprecatedCopy::Assign' first required here}}
 
   struct Ctor {
 Ctor();
-Ctor(const Ctor&); // expected-warning {{definition of implicit copy assignment operator for 'Ctor' is deprecated because it has a user-declared copy constructor}}
+Ctor(const Ctor&); // expected-warning {{definition of implicit copy assignment operator for 'Ctor' is deprecated because it has a user-provided copy constructor}}
   };
   Ctor b1, b2;
   void f() { b1 = b2; } // expected-note {{implicit copy assignment operator for 'DeprecatedCopy::Ctor' first required here}}
 
   struct Dtor {
 ~Dtor();
-// expected-warning@-1 {{definition of implicit copy constructor for 'Dtor' is deprecated because it has a user-declared destructor}}
-// expected-warning@-2 {{definition of implicit copy assignment operator for 'Dtor' is deprecated because it has a user-declared destructor}}
+// expected-warning@-1 {{definition of implicit copy constructor for 'Dtor' is deprecated because it has a user-provided destructor}}
+// expected-warning@-2 {{definition of implicit copy assignment operator for 'Dtor' is deprecated because it has a user-provided destructor}}
   };
   Dtor c1, c2(c1); // expected-note {{implicit copy constructor for 'DeprecatedCopy::Dtor' first required here}}
   void g() { c1 = c2; } // expected-note {{implicit copy assignment operator for 'DeprecatedCopy::Dtor' first required here}}
 
   struct DefaultedDtor {
-~DefaultedDtor() = default;
-  };
-  DefaultedDtor d1, d2(d1);
-  void h() { d1 = d2; }
+~DefaultedDtor() = default; // expected-warning {{definition of implicit copy constructor for 'DefaultedDtor' is deprecated because it has a user-declared destructor}}
+  };// expected-warning@-1 {{definition of implicit copy assignment operator for 'DefaultedDtor' is deprecated because it has a user-declared destructor}}
+  DefaultedDtor d1;
+  DefaultedDtor d2(d1); // expected-note {{in implicit copy constructor for 'DeprecatedCopy::DefaultedDtor' first required here}}
+  void h() { d1 = d2; } // expected-note {{in implicit copy assignment operator for 'DeprecatedCopy::DefaultedDtor' first required here}}
 }
 #endif
 
Index: clang/test/SemaCXX/deprecated-copy.cpp
===
--- clang/test/SemaCXX/deprecated-copy.cpp
+++ clang/test/SemaCXX/deprecated-copy.cpp
@@ -1,23 +1,18 @@
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy -verify
-// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy-dtor -DDEPRECATED_COPY_DTOR -verify
-// RUN: %clang_cc1 -std=c++11 %s -Wextra -verify
 
-#ifdef DEPRECATED_COPY_DTOR
 struct A {
-  int *ptr;
-  ~A() { delete ptr; } // expected-warning {{definition of implicit copy constructor for 'A' is deprecated because it has a user-declared destructor}}
+A& operator=(const A&) = default; // expected-warning {{definition of implicit copy constructor for 'A' is deprecated because it has a user-declared copy assignment operator}}
 };
 
-void foo() {
-  A a{};
-  A b = a; // expected-note {{implicit copy constructor for 'A' first required here}}
-}
-#else
 struct B {
-  B =(const B &); // expected-warning {{definition of implicit copy constructor for 'B' is deprecated because it has a user-declared copy assignment operator}}
+B& operator=(const B&) = delete; // expected-warning {{definition of implicit copy constructor for 'B' is deprecated because it has a user-declared copy assignment operator}}
 };
 
-void bar() {
-  B b1, b2(b1); // expected-note {{implicit copy constructor for 'B' first required here}}
+void foo() {
+  A a1;
+  A a2(a1); // expected-note {{implicit copy constructor for 'A' 

[PATCH] D79714: [Diagnostics] Restore -Wdeprecated warning when user-declared copy assignment operator is defined as deleted (PR45634)

2021-04-17 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 338334.
xbolva00 marked 5 inline comments as done.
xbolva00 added a comment.

Updated, addressed review feedback.


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

https://reviews.llvm.org/D79714

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/deprecated-copy-dtor.cpp
  clang/test/SemaCXX/deprecated-copy-user-provided-copy.cpp
  clang/test/SemaCXX/deprecated-copy-user-provided-dtor.cpp
  clang/test/SemaCXX/deprecated-copy.cpp
  clang/test/SemaCXX/deprecated.cpp

Index: clang/test/SemaCXX/deprecated.cpp
===
--- clang/test/SemaCXX/deprecated.cpp
+++ clang/test/SemaCXX/deprecated.cpp
@@ -83,21 +83,21 @@
 #if __cplusplus >= 201103L
 namespace DeprecatedCopy {
   struct Assign {
-Assign =(const Assign&); // expected-warning {{definition of implicit copy constructor for 'Assign' is deprecated because it has a user-declared copy assignment operator}}
+Assign =(const Assign&); // expected-warning {{definition of implicit copy constructor for 'Assign' is deprecated because it has a user-provided copy assignment operator}}
   };
   Assign a1, a2(a1); // expected-note {{implicit copy constructor for 'DeprecatedCopy::Assign' first required here}}
 
   struct Ctor {
 Ctor();
-Ctor(const Ctor&); // expected-warning {{definition of implicit copy assignment operator for 'Ctor' is deprecated because it has a user-declared copy constructor}}
+Ctor(const Ctor&); // expected-warning {{definition of implicit copy assignment operator for 'Ctor' is deprecated because it has a user-provided copy constructor}}
   };
   Ctor b1, b2;
   void f() { b1 = b2; } // expected-note {{implicit copy assignment operator for 'DeprecatedCopy::Ctor' first required here}}
 
   struct Dtor {
 ~Dtor();
-// expected-warning@-1 {{definition of implicit copy constructor for 'Dtor' is deprecated because it has a user-declared destructor}}
-// expected-warning@-2 {{definition of implicit copy assignment operator for 'Dtor' is deprecated because it has a user-declared destructor}}
+// expected-warning@-1 {{definition of implicit copy constructor for 'Dtor' is deprecated because it has a user-provided destructor}}
+// expected-warning@-2 {{definition of implicit copy assignment operator for 'Dtor' is deprecated because it has a user-provided destructor}}
   };
   Dtor c1, c2(c1); // expected-note {{implicit copy constructor for 'DeprecatedCopy::Dtor' first required here}}
   void g() { c1 = c2; } // expected-note {{implicit copy assignment operator for 'DeprecatedCopy::Dtor' first required here}}
@@ -105,7 +105,8 @@
   struct DefaultedDtor {
 ~DefaultedDtor() = default; // expected-warning {{definition of implicit copy constructor for 'DefaultedDtor' is deprecated because it has a user-declared destructor}}
   };// expected-warning@-1 {{definition of implicit copy assignment operator for 'DefaultedDtor' is deprecated because it has a user-declared destructor}}
-  DefaultedDtor d1, d2(d1); // expected-note {{in implicit copy constructor for 'DeprecatedCopy::DefaultedDtor' first required here}}
+  DefaultedDtor d1;
+  DefaultedDtor d2(d1); // expected-note {{in implicit copy constructor for 'DeprecatedCopy::DefaultedDtor' first required here}}
   void h() { d1 = d2; } // expected-note {{in implicit copy assignment operator for 'DeprecatedCopy::DefaultedDtor' first required here}}
 }
 #endif
Index: clang/test/SemaCXX/deprecated-copy.cpp
===
--- clang/test/SemaCXX/deprecated-copy.cpp
+++ clang/test/SemaCXX/deprecated-copy.cpp
@@ -1,9 +1,18 @@
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy -verify
 
-struct S {
-int i;
-S& operator=(const S&) = delete; // expected-warning {{definition of implicit copy constructor for 'S' is deprecated because it has a user-declared copy assignment operator}}
+struct A {
+A& operator=(const A&) = default; // expected-warning {{definition of implicit copy constructor for 'A' is deprecated because it has a user-declared copy assignment operator}}
 };
 
-S test(const S& s) { return S(s); } // expected-note {{implicit copy constructor for 'S' first required here}}
\ No newline at end of file
+struct B {
+B& operator=(const B&) = delete; // expected-warning {{definition of implicit copy constructor for 'B' is deprecated because it has a user-declared copy assignment operator}}
+};
+
+void foo() {
+  A a1;
+  A a2(a1); // expected-note {{implicit copy constructor for 'A' first required here}}
+
+  B b1;
+  B b2(b1); // expected-note {{implicit copy constructor for 'B' first required here}}
+}
Index: clang/test/SemaCXX/deprecated-copy-user-provided-dtor.cpp

[PATCH] D92191: [clang-scan-deps] Add support for clang-cl

2021-04-17 Thread Alexandre Ganea via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbb26fa8c286b: [clang-scan-deps] Add support for clang-cl 
(authored by saudi, committed by aganea).

Changed prior to commit:
  https://reviews.llvm.org/D92191?vs=318553=338330#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92191

Files:
  clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
  clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
  clang/test/ClangScanDeps/Inputs/headerwithdirname.json
  clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
  clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
  clang/test/ClangScanDeps/Inputs/no-werror.json
  clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json
  clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
  clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
  clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
  clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
  clang/test/ClangScanDeps/error.cpp
  clang/test/ClangScanDeps/has_include_if_elif.cpp
  clang/test/ClangScanDeps/header_stat_before_open.m
  clang/test/ClangScanDeps/headerwithdirname.cpp
  clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules.cpp
  clang/test/ClangScanDeps/no-werror.cpp
  clang/test/ClangScanDeps/regular_cdb.cpp
  clang/test/ClangScanDeps/static-analyzer.c
  clang/test/ClangScanDeps/strip_diag_serialize.cpp
  clang/test/ClangScanDeps/target-filename.cpp
  clang/test/ClangScanDeps/vfsoverlay.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -12,6 +12,8 @@
 #include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
 #include "clang/Tooling/JSONCompilationDatabase.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/InitLLVM.h"
@@ -49,7 +51,8 @@
   /// option and cache the results for reuse. \returns resource directory path
   /// associated with the given invocation command or empty string if the
   /// compiler path is NOT an absolute path.
-  StringRef findResourceDir(const tooling::CommandLineArguments ) {
+  StringRef findResourceDir(const tooling::CommandLineArguments ,
+bool ClangCLMode) {
 if (Args.size() < 1)
   return "";
 
@@ -65,8 +68,12 @@
 if (CachedResourceDir != Cache.end())
   return CachedResourceDir->second;
 
-std::vector PrintResourceDirArgs{ClangBinaryName,
-"-print-resource-dir"};
+std::vector PrintResourceDirArgs{ClangBinaryName};
+if (ClangCLMode)
+  PrintResourceDirArgs.push_back("/clang:-print-resource-dir");
+else
+  PrintResourceDirArgs.push_back("-print-resource-dir");
+
 llvm::SmallString<64> OutputFile, ErrorFile;
 llvm::sys::fs::createTemporaryFile("print-resource-dir-output",
"" /*no-suffix*/, OutputFile);
@@ -418,24 +425,52 @@
 bool HasMQ = false;
 bool HasMD = false;
 bool HasResourceDir = false;
+bool ClangCLMode = false;
 auto FlagsEnd = llvm::find(Args, "--");
 if (FlagsEnd != Args.begin()) {
+  ClangCLMode =
+  llvm::sys::path::stem(Args[0]).contains_lower("clang-cl") ||
+  llvm::is_contained(Args, "--driver-mode=cl");
+
   // Reverse scan, starting at the end or at the element before "--".
   auto R = llvm::make_reverse_iterator(FlagsEnd);
   for (auto I = R, E = Args.rend(); I != E; ++I) {
 StringRef Arg = *I;
-if (LastO.empty()) {
-  if (Arg == "-o" && I != R)
-LastO = I[-1]; // Next argument (reverse iterator)
-  else if (Arg.startswith("-o"))
-LastO = Arg.drop_front(2).str();
+if (ClangCLMode) {
+  if (LastO.empty()) {
+// With clang-cl, the output obj file can be specified with
+// "/opath", "/o path", "/Fopath", and the dash counterparts.
+// Also, clang-cl adds ".obj" extension if none is found.
+if ((Arg == "-o" || Arg == "/o") && I != R)
+  LastO = I[-1]; // Next argument (reverse iterator)
+else if (Arg.startswith("/Fo") || Arg.startswith("-Fo"))
+  LastO = Arg.drop_front(3).str();
+else if (Arg.startswith("/o") || Arg.startswith("-o"))
+  LastO = Arg.drop_front(2).str();
+

[PATCH] D95099: [clang-scan-deps] : Support -- in clang command lines.

2021-04-17 Thread Alexandre Ganea via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG488a19d00cba: [clang-scan-deps] Support double-dashes in 
clang command lines (authored by saudi, committed by aganea).

Changed prior to commit:
  https://reviews.llvm.org/D95099?vs=318304=338329#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95099

Files:
  clang/test/ClangScanDeps/Inputs/regular_cdb.json
  clang/tools/clang-scan-deps/ClangScanDeps.cpp


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -418,14 +418,15 @@
 bool HasMQ = false;
 bool HasMD = false;
 bool HasResourceDir = false;
-// We need to find the last -o value.
-if (!Args.empty()) {
-  std::size_t Idx = Args.size() - 1;
-  for (auto It = Args.rbegin(); It != Args.rend(); ++It) {
-StringRef Arg = Args[Idx];
+auto FlagsEnd = llvm::find(Args, "--");
+if (FlagsEnd != Args.begin()) {
+  // Reverse scan, starting at the end or at the element before "--".
+  auto R = llvm::make_reverse_iterator(FlagsEnd);
+  for (auto I = R, E = Args.rend(); I != E; ++I) {
+StringRef Arg = *I;
 if (LastO.empty()) {
-  if (Arg == "-o" && It != Args.rbegin())
-LastO = Args[Idx + 1];
+  if (Arg == "-o" && I != R)
+LastO = I[-1]; // Next argument (reverse iterator)
   else if (Arg.startswith("-o"))
 LastO = Arg.drop_front(2).str();
 }
@@ -437,12 +438,11 @@
   HasMD = true;
 if (Arg == "-resource-dir")
   HasResourceDir = true;
---Idx;
   }
 }
 // If there's no -MT/-MQ Driver would add -MT with the value of the 
last
 // -o option.
-tooling::CommandLineArguments AdjustedArgs = Args;
+tooling::CommandLineArguments AdjustedArgs(Args.begin(), FlagsEnd);
 AdjustedArgs.push_back("-o");
 AdjustedArgs.push_back("/dev/null");
 if (!HasMT && !HasMQ) {
@@ -472,6 +472,7 @@
 AdjustedArgs.push_back(std::string(ResourceDir));
   }
 }
+AdjustedArgs.insert(AdjustedArgs.end(), FlagsEnd, Args.end());
 return AdjustedArgs;
   });
   AdjustingCompilations->appendArgumentsAdjuster(
Index: clang/test/ClangScanDeps/Inputs/regular_cdb.json
===
--- clang/test/ClangScanDeps/Inputs/regular_cdb.json
+++ clang/test/ClangScanDeps/Inputs/regular_cdb.json
@@ -11,7 +11,7 @@
 },
 {
   "directory": "DIR",
-  "command": "clang -E DIR/regular_cdb_input.cpp -IInputs -o adena.o",
+  "command": "clang -E -IInputs -o adena.o -- DIR/regular_cdb_input.cpp",
   "file": "DIR/regular_cdb_input.cpp"
 }
 ]


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -418,14 +418,15 @@
 bool HasMQ = false;
 bool HasMD = false;
 bool HasResourceDir = false;
-// We need to find the last -o value.
-if (!Args.empty()) {
-  std::size_t Idx = Args.size() - 1;
-  for (auto It = Args.rbegin(); It != Args.rend(); ++It) {
-StringRef Arg = Args[Idx];
+auto FlagsEnd = llvm::find(Args, "--");
+if (FlagsEnd != Args.begin()) {
+  // Reverse scan, starting at the end or at the element before "--".
+  auto R = llvm::make_reverse_iterator(FlagsEnd);
+  for (auto I = R, E = Args.rend(); I != E; ++I) {
+StringRef Arg = *I;
 if (LastO.empty()) {
-  if (Arg == "-o" && It != Args.rbegin())
-LastO = Args[Idx + 1];
+  if (Arg == "-o" && I != R)
+LastO = I[-1]; // Next argument (reverse iterator)
   else if (Arg.startswith("-o"))
 LastO = Arg.drop_front(2).str();
 }
@@ -437,12 +438,11 @@
   HasMD = true;
 if (Arg == "-resource-dir")
   HasResourceDir = true;
---Idx;
   }
 }
 // If there's no -MT/-MQ Driver would add -MT with the value of the last
 // -o option.
-tooling::CommandLineArguments AdjustedArgs = Args;
+tooling::CommandLineArguments AdjustedArgs(Args.begin(), FlagsEnd);
 AdjustedArgs.push_back("-o");
 AdjustedArgs.push_back("/dev/null");
 if (!HasMT && !HasMQ) {
@@ -472,6 +472,7 @@
 AdjustedArgs.push_back(std::string(ResourceDir));
   }
 }
+AdjustedArgs.insert(AdjustedArgs.end(), 

[clang] bb26fa8 - [clang-scan-deps] Add support for clang-cl

2021-04-17 Thread Alexandre Ganea via cfe-commits

Author: Sylvain Audi
Date: 2021-04-17T14:22:51-04:00
New Revision: bb26fa8c286bf524ed9235c3e293ad22ecf3e984

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

LOG: [clang-scan-deps] Add support for clang-cl

clang-scan-deps contains some command line parsing and modifications.
This patch adds support for clang-cl command options.

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

Added: 
clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json

Modified: 
clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
clang/test/ClangScanDeps/Inputs/headerwithdirname.json
clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
clang/test/ClangScanDeps/Inputs/no-werror.json
clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
clang/test/ClangScanDeps/error.cpp
clang/test/ClangScanDeps/has_include_if_elif.cpp
clang/test/ClangScanDeps/header_stat_before_open.m
clang/test/ClangScanDeps/headerwithdirname.cpp
clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
clang/test/ClangScanDeps/modules-full.cpp
clang/test/ClangScanDeps/modules.cpp
clang/test/ClangScanDeps/no-werror.cpp
clang/test/ClangScanDeps/regular_cdb.cpp
clang/test/ClangScanDeps/static-analyzer.c
clang/test/ClangScanDeps/strip_diag_serialize.cpp
clang/test/ClangScanDeps/target-filename.cpp
clang/test/ClangScanDeps/vfsoverlay.cpp
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 




diff  --git a/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json 
b/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
index 36ca006b03297..8fcc7ea34a9bc 100644
--- a/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
+++ b/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
@@ -3,5 +3,10 @@
   "directory": "DIR",
   "command": "clang -E DIR/has_include_if_elif2.cpp -IInputs",
   "file": "DIR/has_include_if_elif2.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /IInputs -- DIR/has_include_if_elif2_clangcl.cpp",
+  "file": "DIR/has_include_if_elif2_clangcl.cpp"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json 
b/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
index c5f027e9fd28a..b99b541b12986 100644
--- a/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
+++ b/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
@@ -3,5 +3,10 @@
   "directory": "DIR",
   "command": "clang -E DIR/header_stat_before_open_input.m -iframework 
Inputs/frameworks",
   "file": "DIR/header_stat_before_open_input.m"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E -Xclang -iframework -Xclang Inputs/frameworks -- 
DIR/header_stat_before_open_input_clangcl.m",
+  "file": "DIR/header_stat_before_open_input_clangcl.m"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/headerwithdirname.json 
b/clang/test/ClangScanDeps/Inputs/headerwithdirname.json
index 2ae561935bec3..ac12c92308fda 100644
--- a/clang/test/ClangScanDeps/Inputs/headerwithdirname.json
+++ b/clang/test/ClangScanDeps/Inputs/headerwithdirname.json
@@ -3,5 +3,10 @@
   "directory": "DIR",
   "command": "clang -c -IDIR -IDIR/foodir -IInputs 
DIR/headerwithdirname_input.cpp",
   "file": "DIR/headerwithdirname_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /c /IDIR /IDIR/foodir -IInputs -- 
DIR/headerwithdirname_input_clangcl.cpp",
+  "file": "DIR/headerwithdirname_input_clangcl.cpp"
 }
 ]

diff  --git 
a/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json 
b/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
index de7759d0b110c..1886328a9c3e9 100644
--- a/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
+++ b/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
@@ -3,5 +3,10 @@
   "directory": "DIR",
   "command": "clang -c -IDIR -IInputs DIR/headerwithdirname_input.cpp",
   "file": "DIR/headerwithdirname_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /c /IDIR /IInputs -- 
DIR/headerwithdirname_input_clangcl.cpp",
+  "file": "DIR/headerwithdirname_input_clangcl.cpp"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json 
b/clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
new file mode 100644
index 0..a1f12867c45d5
--- /dev/null
+++ 

[clang] 488a19d - [clang-scan-deps] Support double-dashes in clang command lines

2021-04-17 Thread Alexandre Ganea via cfe-commits

Author: Sylvain Audi
Date: 2021-04-17T14:22:51-04:00
New Revision: 488a19d00cbaec479f8c5c298556d2246978f9e6

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

LOG: [clang-scan-deps] Support double-dashes in clang command lines

This fixes argument injection in clang command lines, by adding them before 
"--".

Previously, the arguments were injected at the end of the command line and 
could be added after "--", which would be wrongly interpreted as input file 
paths.

This fix is needed for a subsequent patch, see D92191.

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

Added: 


Modified: 
clang/test/ClangScanDeps/Inputs/regular_cdb.json
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 




diff  --git a/clang/test/ClangScanDeps/Inputs/regular_cdb.json 
b/clang/test/ClangScanDeps/Inputs/regular_cdb.json
index 902c0b7761fb5..938880c1304f1 100644
--- a/clang/test/ClangScanDeps/Inputs/regular_cdb.json
+++ b/clang/test/ClangScanDeps/Inputs/regular_cdb.json
@@ -11,7 +11,7 @@
 },
 {
   "directory": "DIR",
-  "command": "clang -E DIR/regular_cdb_input.cpp -IInputs -o adena.o",
+  "command": "clang -E -IInputs -o adena.o -- DIR/regular_cdb_input.cpp",
   "file": "DIR/regular_cdb_input.cpp"
 }
 ]

diff  --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index a8ff42ab104ca..e3ea098d8211a 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -418,14 +418,15 @@ int main(int argc, const char **argv) {
 bool HasMQ = false;
 bool HasMD = false;
 bool HasResourceDir = false;
-// We need to find the last -o value.
-if (!Args.empty()) {
-  std::size_t Idx = Args.size() - 1;
-  for (auto It = Args.rbegin(); It != Args.rend(); ++It) {
-StringRef Arg = Args[Idx];
+auto FlagsEnd = llvm::find(Args, "--");
+if (FlagsEnd != Args.begin()) {
+  // Reverse scan, starting at the end or at the element before "--".
+  auto R = llvm::make_reverse_iterator(FlagsEnd);
+  for (auto I = R, E = Args.rend(); I != E; ++I) {
+StringRef Arg = *I;
 if (LastO.empty()) {
-  if (Arg == "-o" && It != Args.rbegin())
-LastO = Args[Idx + 1];
+  if (Arg == "-o" && I != R)
+LastO = I[-1]; // Next argument (reverse iterator)
   else if (Arg.startswith("-o"))
 LastO = Arg.drop_front(2).str();
 }
@@ -437,12 +438,11 @@ int main(int argc, const char **argv) {
   HasMD = true;
 if (Arg == "-resource-dir")
   HasResourceDir = true;
---Idx;
   }
 }
 // If there's no -MT/-MQ Driver would add -MT with the value of the 
last
 // -o option.
-tooling::CommandLineArguments AdjustedArgs = Args;
+tooling::CommandLineArguments AdjustedArgs(Args.begin(), FlagsEnd);
 AdjustedArgs.push_back("-o");
 AdjustedArgs.push_back("/dev/null");
 if (!HasMT && !HasMQ) {
@@ -472,6 +472,7 @@ int main(int argc, const char **argv) {
 AdjustedArgs.push_back(std::string(ResourceDir));
   }
 }
+AdjustedArgs.insert(AdjustedArgs.end(), FlagsEnd, Args.end());
 return AdjustedArgs;
   });
   AdjustingCompilations->appendArgumentsAdjuster(



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


[clang] 141945f - [AST] Enable AST node introspection on WIN32

2021-04-17 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-04-17T18:59:35+01:00
New Revision: 141945f950e2f3fd58bc6db3afb5d3b10cb2b0c9

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

LOG: [AST] Enable AST node introspection on WIN32

Added: 


Modified: 
clang/lib/Tooling/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Tooling/CMakeLists.txt 
b/clang/lib/Tooling/CMakeLists.txt
index 0da3dbd0b927c..e90b681e16f42 100644
--- a/clang/lib/Tooling/CMakeLists.txt
+++ b/clang/lib/Tooling/CMakeLists.txt
@@ -24,7 +24,6 @@ string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} ${PATH_LIB_END} 
-1 PATH_TAIL)
 string(CONCAT BINARY_INCLUDE_DIR ${PATH_HEAD} "/include/clang/" ${PATH_TAIL})
 
 if (NOT Python3_EXECUTABLE
-OR WIN32
 OR APPLE
 OR GENERATOR_IS_MULTI_CONFIG
 OR NOT LLVM_NATIVE_ARCH IN_LIST LLVM_TARGETS_TO_BUILD



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


[PATCH] D100705: Fixed Typos

2021-04-17 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

Thanks, @Mordante for the tips, I remember from next time :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100705

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


[PATCH] D100567: BPF: emit debuginfo for Function of DeclRefExpr if requested

2021-04-17 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

I did some debugging on why DeclRefExpr evaluated not to be a Function pointer. 
Here is what I got.
I made the following clang change to dump out the pointer to the emited value 
(''):

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index a784aade88da..80d19c7bcdf7 100644

- a/clang/lib/CodeGen/CGExpr.cpp

+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2840,6 +2840,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const 
DeclRefExpr *E) {

  // Emit debuginfo for the function declaration if the target wants to.
  if (getContext().getTargetInfo().allowDebugInfoForExternalRef()) {
CGDebugInfo *DI = CGM.getModuleDebugInfo();

+  LV.getPointer(*this)->dump();

  auto *Fn = dyn_cast(LV.getPointer(*this));
  if (DI && Fn && !Fn->getSubprogram())
DI->EmitFunctionDecl(FD, FD->getLocation(), T, Fn);

The C code and the compiler run:

$ cat t1.c
 extern int foo() __attribute__((section("abc")));
 long test() {

  return (long)

}
 int foo() { return 0; }
 long test2() {

  return (long)

}
 $ clang -target bpf -O2 -S -g -emit-llvm t1.c
 declare dso_local i32 @foo(...) #0 section "abc"

i32 (...)* bitcast (i32 ()* @foo to i32 (...)*)

You can see, if there is no definition, the emitted insn for '' is a 
reference
to a declaration (llvm::Function type).
After the function definition, the emitted insn for '' is a reference to
some kind of a function definition (I checked it is a llvm:ConstantExpr).
That is the reason why I hit a NULL pointer for

  auto *Fn = dyn_cast(LV.getPointer(*this));

in one of tests.

@dblaikie the code is ready to be reviewed again. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100567

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


[PATCH] D100705: Fixed Typos

2021-04-17 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

In D100705#2696708 , @xgupta wrote:

> Nice work @jnyfah!
>
> @Mordante Review is already accepted by @curdeius in 
> https://reviews.llvm.org/D100696. And actually, I see your message after 
> committing the patch.

In general when a patch is blocked by a reviewer it shouldn't be committed. 
However the patch is trivial so not a big issue.
Secondly, if I'd known @curdeius approved it I would have approved as libc++.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100705

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


[PATCH] D100567: BPF: emit debuginfo for Function of DeclRefExpr if requested

2021-04-17 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 338323.
yonghong-song added a comment.

- add checking CGDebugInfo pointer. In my original patch but got lost in the 
revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100567

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/BPF.h
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGen/debug-info-extern-callback.c

Index: clang/test/CodeGen/debug-info-extern-callback.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-extern-callback.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -x c -debug-info-kind=limited -triple bpf-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+extern int do_work1(int);
+long bpf_helper1(void *callback_fn);
+long prog1() {
+  return bpf_helper1(_work1);
+}
+
+extern int do_work2(int);
+long bpf_helper2(void *callback_fn);
+int do_work2(int arg) {
+  return arg;
+}
+long prog2() {
+  return bpf_helper2(_work2);
+}
+
+extern int do_work3(int);
+long bpf_helper3(void *callback_fn);
+long prog3() {
+  return bpf_helper3(_work3);
+}
+int do_work3(int arg) {
+  return arg;
+}
+
+// CHECK: declare !dbg ![[FUNC1:[0-9]+]] i32 @do_work1(i32)
+// CHECK: define dso_local i32 @do_work2(i32 %arg) #{{[0-9]+}} !dbg ![[FUNC2:[0-9]+]]
+// CHECK: define dso_local i32 @do_work3(i32 %arg) #{{[0-9]+}} !dbg ![[FUNC3:[0-9]+]]
+
+// CHECK: ![[FUNC1]] = !DISubprogram(name: "do_work1"
+// CHECK: ![[FUNC2]] = distinct !DISubprogram(name: "do_work2"
+// CHECK: ![[FUNC3]] = distinct !DISubprogram(name: "do_work3"
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12667,7 +12667,7 @@
 Diag(Var->getLocation(), diag::note_private_extern);
   }
 
-  if (Context.getTargetInfo().allowDebugInfoForExternalVar() &&
+  if (Context.getTargetInfo().allowDebugInfoForExternalRef() &&
   !Var->isInvalidDecl() && !getLangOpts().CPlusPlus)
 ExternalDeclarations.push_back(Var);
 
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -2834,8 +2834,19 @@
 return LV;
   }
 
-  if (const auto *FD = dyn_cast(ND))
-return EmitFunctionDeclLValue(*this, E, FD);
+  if (const auto *FD = dyn_cast(ND)) {
+LValue LV = EmitFunctionDeclLValue(*this, E, FD);
+
+// Emit debuginfo for the function declaration if the target wants to.
+if (getContext().getTargetInfo().allowDebugInfoForExternalRef()) {
+  CGDebugInfo *DI = CGM.getModuleDebugInfo();
+  auto *Fn = dyn_cast(LV.getPointer(*this));
+  if (DI && Fn && !Fn->getSubprogram())
+DI->EmitFunctionDecl(FD, FD->getLocation(), T, Fn);
+}
+
+return LV;
+  }
 
   // FIXME: While we're emitting a binding from an enclosing scope, all other
   // DeclRefExprs we see should be implicitly treated as if they also refer to
Index: clang/lib/Basic/Targets/BPF.h
===
--- clang/lib/Basic/Targets/BPF.h
+++ clang/lib/Basic/Targets/BPF.h
@@ -76,7 +76,7 @@
 return None;
   }
 
-  bool allowDebugInfoForExternalVar() const override { return true; }
+  bool allowDebugInfoForExternalRef() const override { return true; }
 
   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
 switch (CC) {
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -1538,8 +1538,8 @@
 
   virtual void setAuxTarget(const TargetInfo *Aux) {}
 
-  /// Whether target allows debuginfo types for decl only variables.
-  virtual bool allowDebugInfoForExternalVar() const { return false; }
+  /// Whether target allows debuginfo types for decl only variables/functions.
+  virtual bool allowDebugInfoForExternalRef() const { return false; }
 
 protected:
   /// Copy type and layout related info.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D100696: Fixed typos

2021-04-17 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

@jnyfah you may close this revision. changes are committed by 
https://reviews.llvm.org/rG21bef4e11e48d5d4bff7a23babbd420e86dd420a.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100696

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


[PATCH] D100705: Fixed Typos

2021-04-17 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a subscriber: curdeius.
xgupta added a comment.

Nice work @jnyfah!

@Mordante Review is already accepted by @curdeius in 
https://reviews.llvm.org/D100696. And actually, I see your message after 
committing the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100705

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


[PATCH] D100705: Fixed Typos

2021-04-17 Thread Shivam Gupta via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG21bef4e11e48: [NFC] Fixed Typos (authored by jnyfah, 
committed by xgupta).

Changed prior to commit:
  https://reviews.llvm.org/D100705?vs=338309=338317#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100705

Files:
  clang/docs/UsersManual.rst
  libcxx/docs/UsingLibcxx.rst


Index: libcxx/docs/UsingLibcxx.rst
===
--- libcxx/docs/UsingLibcxx.rst
+++ libcxx/docs/UsingLibcxx.rst
@@ -114,10 +114,10 @@
 GCC does not provide a way to switch from libstdc++ to libc++. You must 
manually
 configure the compile and link commands.
 
-In particular you must tell GCC to remove the libstdc++ include directories
+In particular, you must tell GCC to remove the libstdc++ include directories
 using ``-nostdinc++`` and to not link libstdc++.so using ``-nodefaultlibs``.
 
-Note that ``-nodefaultlibs`` removes all of the standard system libraries and
+Note that ``-nodefaultlibs`` removes all the standard system libraries and
 not just libstdc++ so they must be manually linked. For example:
 
 .. code-block:: bash
@@ -151,7 +151,7 @@
 
 **_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS**:
   This macro is used to enable -Wthread-safety annotations on libc++'s
-  ``std::mutex`` and ``std::lock_guard``. By default these annotations are
+  ``std::mutex`` and ``std::lock_guard``. By default, these annotations are
   disabled and must be manually enabled by the user.
 
 **_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS**:
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -686,7 +686,7 @@
 .. option:: -gen-reproducer
 
   Generates preprocessed source files, a reproducer script and if relevant, a
-  cache containing: built module pcm's and all headers needed to rebuilt the
+  cache containing: built module pcm's and all headers needed to rebuild the
   same modules.
 
 .. _rpass:


Index: libcxx/docs/UsingLibcxx.rst
===
--- libcxx/docs/UsingLibcxx.rst
+++ libcxx/docs/UsingLibcxx.rst
@@ -114,10 +114,10 @@
 GCC does not provide a way to switch from libstdc++ to libc++. You must manually
 configure the compile and link commands.
 
-In particular you must tell GCC to remove the libstdc++ include directories
+In particular, you must tell GCC to remove the libstdc++ include directories
 using ``-nostdinc++`` and to not link libstdc++.so using ``-nodefaultlibs``.
 
-Note that ``-nodefaultlibs`` removes all of the standard system libraries and
+Note that ``-nodefaultlibs`` removes all the standard system libraries and
 not just libstdc++ so they must be manually linked. For example:
 
 .. code-block:: bash
@@ -151,7 +151,7 @@
 
 **_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS**:
   This macro is used to enable -Wthread-safety annotations on libc++'s
-  ``std::mutex`` and ``std::lock_guard``. By default these annotations are
+  ``std::mutex`` and ``std::lock_guard``. By default, these annotations are
   disabled and must be manually enabled by the user.
 
 **_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS**:
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -686,7 +686,7 @@
 .. option:: -gen-reproducer
 
   Generates preprocessed source files, a reproducer script and if relevant, a
-  cache containing: built module pcm's and all headers needed to rebuilt the
+  cache containing: built module pcm's and all headers needed to rebuild the
   same modules.
 
 .. _rpass:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 21bef4e - [NFC] Fixed Typos

2021-04-17 Thread via cfe-commits

Author: Jennifer Chukwu
Date: 2021-04-17T22:02:23+05:30
New Revision: 21bef4e11e48d5d4bff7a23babbd420e86dd420a

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

LOG: [NFC] Fixed Typos

Reviewed By: xgupta

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

Added: 


Modified: 
clang/docs/UsersManual.rst
libcxx/docs/UsingLibcxx.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 9053398c937a..ec521155a7f7 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -686,7 +686,7 @@ generate a reproducer for warnings or errors while using 
modules.
 .. option:: -gen-reproducer
 
   Generates preprocessed source files, a reproducer script and if relevant, a
-  cache containing: built module pcm's and all headers needed to rebuilt the
+  cache containing: built module pcm's and all headers needed to rebuild the
   same modules.
 
 .. _rpass:

diff  --git a/libcxx/docs/UsingLibcxx.rst b/libcxx/docs/UsingLibcxx.rst
index 0e6d92bbbcd7..f7de6f64c10d 100644
--- a/libcxx/docs/UsingLibcxx.rst
+++ b/libcxx/docs/UsingLibcxx.rst
@@ -114,10 +114,10 @@ Using libc++ with GCC
 GCC does not provide a way to switch from libstdc++ to libc++. You must 
manually
 configure the compile and link commands.
 
-In particular you must tell GCC to remove the libstdc++ include directories
+In particular, you must tell GCC to remove the libstdc++ include directories
 using ``-nostdinc++`` and to not link libstdc++.so using ``-nodefaultlibs``.
 
-Note that ``-nodefaultlibs`` removes all of the standard system libraries and
+Note that ``-nodefaultlibs`` removes all the standard system libraries and
 not just libstdc++ so they must be manually linked. For example:
 
 .. code-block:: bash
@@ -151,7 +151,7 @@ thread safety annotations.
 
 **_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS**:
   This macro is used to enable -Wthread-safety annotations on libc++'s
-  ``std::mutex`` and ``std::lock_guard``. By default these annotations are
+  ``std::mutex`` and ``std::lock_guard``. By default, these annotations are
   disabled and must be manually enabled by the user.
 
 **_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS**:



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


[PATCH] D100705: Fixed Typos

2021-04-17 Thread Mark de Wever via Phabricator via cfe-commits
Mordante accepted this revision as: Mordante.
Mordante added a comment.

Thanks for your contribution. Next time, please provide a patch with more 
context.
The  instructions can be found at 
https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface.
LGTM, but please wait for an approval of the libc++ group.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100705

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


[PATCH] D100688: [AST] Remove args from LocationCall

2021-04-17 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGebc6608fb790: [AST] Remove args from LocationCall (authored 
by stephenkelly).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100688

Files:
  clang/include/clang/Tooling/NodeIntrospection.h
  clang/lib/Tooling/NodeIntrospection.cpp
  clang/unittests/Introspection/IntrospectionTest.cpp


Index: clang/unittests/Introspection/IntrospectionTest.cpp
===
--- clang/unittests/Introspection/IntrospectionTest.cpp
+++ clang/unittests/Introspection/IntrospectionTest.cpp
@@ -61,16 +61,7 @@
   print(*On, OS);
   OS << '.';
 }
-OS << Call.name();
-if (Call.args().empty()) {
-  OS << "()";
-  return;
-}
-OS << '(' << Call.args().front();
-for (const std::string  : Call.args().drop_front()) {
-  OS << ", " << Arg;
-}
-OS << ')';
+OS << Call.name() << "()";
   }
 
   static std::string format(const LocationCall ) {
Index: clang/lib/Tooling/NodeIntrospection.cpp
===
--- clang/lib/Tooling/NodeIntrospection.cpp
+++ clang/lib/Tooling/NodeIntrospection.cpp
@@ -29,16 +29,7 @@
   OS << '.';
   }
 
-  OS << Call.name();
-  if (Call.args().empty()) {
-OS << "()";
-return;
-  }
-  OS << '(' << Call.args().front();
-  for (const std::string  : Call.args().drop_front()) {
-OS << ", " << Arg;
-  }
-  OS << ')';
+  OS << Call.name() << "()";
 }
 
 std::string LocationCallFormatterCpp::format(const LocationCall ) {
Index: clang/include/clang/Tooling/NodeIntrospection.h
===
--- clang/include/clang/Tooling/NodeIntrospection.h
+++ clang/include/clang/Tooling/NodeIntrospection.h
@@ -38,14 +38,9 @@
   LocationCall(SharedLocationCall on, std::string name,
LocationCallFlags flags = NoFlags)
   : m_flags(flags), m_on(std::move(on)), m_name(std::move(name)) {}
-  LocationCall(SharedLocationCall on, std::string name,
-   std::vector args, LocationCallFlags flags = 
NoFlags)
-  : m_flags(flags), m_on(std::move(on)), m_name(std::move(name)),
-m_args(std::move(args)) {}
 
   LocationCall *on() const { return m_on.get(); }
   StringRef name() const { return m_name; }
-  ArrayRef args() const { return m_args; }
   bool returnsPointer() const { return m_flags & ReturnsPointer; }
   bool isCast() const { return m_flags & IsCast; }
 
@@ -53,7 +48,6 @@
   LocationCallFlags m_flags;
   SharedLocationCall m_on;
   std::string m_name;
-  std::vector m_args;
 };
 
 class LocationCallFormatterCpp {


Index: clang/unittests/Introspection/IntrospectionTest.cpp
===
--- clang/unittests/Introspection/IntrospectionTest.cpp
+++ clang/unittests/Introspection/IntrospectionTest.cpp
@@ -61,16 +61,7 @@
   print(*On, OS);
   OS << '.';
 }
-OS << Call.name();
-if (Call.args().empty()) {
-  OS << "()";
-  return;
-}
-OS << '(' << Call.args().front();
-for (const std::string  : Call.args().drop_front()) {
-  OS << ", " << Arg;
-}
-OS << ')';
+OS << Call.name() << "()";
   }
 
   static std::string format(const LocationCall ) {
Index: clang/lib/Tooling/NodeIntrospection.cpp
===
--- clang/lib/Tooling/NodeIntrospection.cpp
+++ clang/lib/Tooling/NodeIntrospection.cpp
@@ -29,16 +29,7 @@
   OS << '.';
   }
 
-  OS << Call.name();
-  if (Call.args().empty()) {
-OS << "()";
-return;
-  }
-  OS << '(' << Call.args().front();
-  for (const std::string  : Call.args().drop_front()) {
-OS << ", " << Arg;
-  }
-  OS << ')';
+  OS << Call.name() << "()";
 }
 
 std::string LocationCallFormatterCpp::format(const LocationCall ) {
Index: clang/include/clang/Tooling/NodeIntrospection.h
===
--- clang/include/clang/Tooling/NodeIntrospection.h
+++ clang/include/clang/Tooling/NodeIntrospection.h
@@ -38,14 +38,9 @@
   LocationCall(SharedLocationCall on, std::string name,
LocationCallFlags flags = NoFlags)
   : m_flags(flags), m_on(std::move(on)), m_name(std::move(name)) {}
-  LocationCall(SharedLocationCall on, std::string name,
-   std::vector args, LocationCallFlags flags = NoFlags)
-  : m_flags(flags), m_on(std::move(on)), m_name(std::move(name)),
-m_args(std::move(args)) {}
 
   LocationCall *on() const { return m_on.get(); }
   StringRef name() const { return m_name; }
-  ArrayRef args() const { return m_args; }
   bool returnsPointer() const { return m_flags & ReturnsPointer; }
   bool isCast() const { return m_flags & IsCast; }
 
@@ -53,7 +48,6 @@
   LocationCallFlags m_flags;
   SharedLocationCall m_on;
   

[clang] ebc6608 - [AST] Remove args from LocationCall

2021-04-17 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-04-17T17:21:55+01:00
New Revision: ebc6608fb79057eaed27435d62d5dea0979bd9d3

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

LOG: [AST] Remove args from LocationCall

This class initially had args to be generic to future needs. In
particular, I thought that source location introspection should show the
getBeginLoc of CallExpr args and the getArgLoc of
TemplateSpecializationLocInfo etc.  However, that is probably best left
out of source location introspection because it involves node traversal.

If something like this is needed in the future, it can be added in the
future.

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

Added: 


Modified: 
clang/include/clang/Tooling/NodeIntrospection.h
clang/lib/Tooling/NodeIntrospection.cpp
clang/unittests/Introspection/IntrospectionTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/NodeIntrospection.h 
b/clang/include/clang/Tooling/NodeIntrospection.h
index 5489a67efa22..c8518ea63546 100644
--- a/clang/include/clang/Tooling/NodeIntrospection.h
+++ b/clang/include/clang/Tooling/NodeIntrospection.h
@@ -38,14 +38,9 @@ class LocationCall : public 
llvm::ThreadSafeRefCountedBase {
   LocationCall(SharedLocationCall on, std::string name,
LocationCallFlags flags = NoFlags)
   : m_flags(flags), m_on(std::move(on)), m_name(std::move(name)) {}
-  LocationCall(SharedLocationCall on, std::string name,
-   std::vector args, LocationCallFlags flags = 
NoFlags)
-  : m_flags(flags), m_on(std::move(on)), m_name(std::move(name)),
-m_args(std::move(args)) {}
 
   LocationCall *on() const { return m_on.get(); }
   StringRef name() const { return m_name; }
-  ArrayRef args() const { return m_args; }
   bool returnsPointer() const { return m_flags & ReturnsPointer; }
   bool isCast() const { return m_flags & IsCast; }
 
@@ -53,7 +48,6 @@ class LocationCall : public 
llvm::ThreadSafeRefCountedBase {
   LocationCallFlags m_flags;
   SharedLocationCall m_on;
   std::string m_name;
-  std::vector m_args;
 };
 
 class LocationCallFormatterCpp {

diff  --git a/clang/lib/Tooling/NodeIntrospection.cpp 
b/clang/lib/Tooling/NodeIntrospection.cpp
index 0e3ef3c6a01e..6a8d7267f8ae 100644
--- a/clang/lib/Tooling/NodeIntrospection.cpp
+++ b/clang/lib/Tooling/NodeIntrospection.cpp
@@ -29,16 +29,7 @@ void LocationCallFormatterCpp::print(const LocationCall 
,
   OS << '.';
   }
 
-  OS << Call.name();
-  if (Call.args().empty()) {
-OS << "()";
-return;
-  }
-  OS << '(' << Call.args().front();
-  for (const std::string  : Call.args().drop_front()) {
-OS << ", " << Arg;
-  }
-  OS << ')';
+  OS << Call.name() << "()";
 }
 
 std::string LocationCallFormatterCpp::format(const LocationCall ) {

diff  --git a/clang/unittests/Introspection/IntrospectionTest.cpp 
b/clang/unittests/Introspection/IntrospectionTest.cpp
index ad21748f11f8..e56963aa41a6 100644
--- a/clang/unittests/Introspection/IntrospectionTest.cpp
+++ b/clang/unittests/Introspection/IntrospectionTest.cpp
@@ -61,16 +61,7 @@ class LocationCallFormatterSimple {
   print(*On, OS);
   OS << '.';
 }
-OS << Call.name();
-if (Call.args().empty()) {
-  OS << "()";
-  return;
-}
-OS << '(' << Call.args().front();
-for (const std::string  : Call.args().drop_front()) {
-  OS << ", " << Arg;
-}
-OS << ')';
+OS << Call.name() << "()";
   }
 
   static std::string format(const LocationCall ) {



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


[PATCH] D100652: [HIP] Support hipRTC in header

2021-04-17 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6823af0ca858: [HIP] Support hipRTC in header (authored by 
yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100652

Files:
  clang/lib/Headers/__clang_hip_cmath.h
  clang/lib/Headers/__clang_hip_math.h
  clang/lib/Headers/__clang_hip_runtime_wrapper.h
  clang/test/Headers/hip-header.hip
  clang/test/lit.cfg.py

Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -25,7 +25,7 @@
 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
 
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.c', '.cpp', '.i', '.cppm', '.m', '.mm', '.cu',
+config.suffixes = ['.c', '.cpp', '.i', '.cppm', '.m', '.mm', '.cu', '.hip',
'.ll', '.cl', '.clcpp', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs']
 
 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
Index: clang/test/Headers/hip-header.hip
===
--- /dev/null
+++ clang/test/Headers/hip-header.hip
@@ -0,0 +1,20 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
+// RUN:   -internal-isystem %S/../../lib/Headers/cuda_wrappers \
+// RUN:   -internal-isystem %S/Inputs/include \
+// RUN:   -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
+// RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
+// RUN:   -D__HIPCC_RTC__ | FileCheck %s
+
+// expected-no-diagnostics
+
+// CHECK-LABEL: amdgpu_kernel void @_Z4kernPff
+__global__ void kern(float *x, float y) {
+  *x = sin(y);
+}
+
+// CHECK-LABEL: define{{.*}} i64 @_Z11test_size_tv
+// CHEC: ret i64 8
+__device__ size_t test_size_t() {
+  return sizeof(size_t);
+}
Index: clang/lib/Headers/__clang_hip_runtime_wrapper.h
===
--- clang/lib/Headers/__clang_hip_runtime_wrapper.h
+++ clang/lib/Headers/__clang_hip_runtime_wrapper.h
@@ -18,9 +18,27 @@
 
 #if __HIP__
 
+#if !defined(__HIPCC_RTC__)
 #include 
 #include 
 #include 
+#else
+typedef __SIZE_TYPE__ size_t;
+// Define macros which are needed to declare HIP device API's without standard
+// C/C++ headers. This is for readability so that these API's can be written
+// the same way as non-hipRTC use case. These macros need to be popped so that
+// they do not pollute users' name space.
+#pragma push_macro("NULL")
+#pragma push_macro("uint32_t")
+#pragma push_macro("uint64_t")
+#pragma push_macro("CHAR_BIT")
+#pragma push_macro("INT_MAX")
+#define NULL (void *)0
+#define uint32_t __UINT32_TYPE__
+#define uint64_t __UINT64_TYPE__
+#define CHAR_BIT __CHAR_BIT__
+#define INT_MAX __INTMAX_MAX__
+#endif // __HIPCC_RTC__
 
 #define __host__ __attribute__((host))
 #define __device__ __attribute__((device))
@@ -54,6 +72,7 @@
 #include <__clang_hip_libdevice_declares.h>
 #include <__clang_hip_math.h>
 
+#if !defined(__HIPCC_RTC__)
 #if !_OPENMP || __HIP_ENABLE_CUDA_WRAPPER_FOR_OPENMP__
 #include <__clang_cuda_math_forward_declares.h>
 #include <__clang_hip_cmath.h>
@@ -62,9 +81,16 @@
 #include 
 #include 
 #include 
+#endif // __HIPCC_RTC__
 #endif // !_OPENMP || __HIP_ENABLE_CUDA_WRAPPER_FOR_OPENMP__
 
 #define __CLANG_HIP_RUNTIME_WRAPPER_INCLUDED__ 1
-
+#if defined(__HIPCC_RTC__)
+#pragma pop_macro("NULL")
+#pragma pop_macro("uint32_t")
+#pragma pop_macro("uint64_t")
+#pragma pop_macro("CHAR_BIT")
+#pragma pop_macro("INT_MAX")
+#endif // __HIPCC_RTC__
 #endif // __HIP__
 #endif // __CLANG_HIP_RUNTIME_WRAPPER_H__
Index: clang/lib/Headers/__clang_hip_math.h
===
--- clang/lib/Headers/__clang_hip_math.h
+++ clang/lib/Headers/__clang_hip_math.h
@@ -13,11 +13,13 @@
 #error "This file is for HIP and OpenMP AMDGCN device compilation only."
 #endif
 
+#if !defined(__HIPCC_RTC__)
 #if defined(__cplusplus)
 #include 
 #endif
 #include 
 #include 
+#endif // __HIPCC_RTC__
 
 #pragma push_macro("__DEVICE__")
 #define __DEVICE__ static __device__ inline __attribute__((always_inline))
@@ -1260,6 +1262,7 @@
 __DEVICE__
 double min(double __x, double __y) { return fmin(__x, __y); }
 
+#if !defined(__HIPCC_RTC__)
 __host__ inline static int min(int __arg1, int __arg2) {
   return std::min(__arg1, __arg2);
 }
@@ -1267,6 +1270,7 @@
 __host__ inline static int max(int __arg1, int __arg2) {
   return std::max(__arg1, __arg2);
 }
+#endif // __HIPCC_RTC__
 #endif
 
 #pragma pop_macro("__DEVICE__")
Index: clang/lib/Headers/__clang_hip_cmath.h
===
--- clang/lib/Headers/__clang_hip_cmath.h
+++ clang/lib/Headers/__clang_hip_cmath.h
@@ -14,6 +14,7 @@
 #error "This file is for HIP and OpenMP 

[clang] 6823af0 - [HIP] Support hipRTC in header

2021-04-17 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-04-17T11:34:52-04:00
New Revision: 6823af0ca858b54e09e5be61a19d067ccd0bd6b7

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

LOG: [HIP] Support hipRTC in header

hipRTC compiles HIP device code at run time. Since the system may not
have development tools installed, when a HIP program is compiled through
hipRTC, there is no standard C or C++ header available. As such, the HIP
headers should not depend on standard C or C++ headers when used
with hipRTC. Basically when hipRTC is used, HIP headers only provides
definitions of HIP device API functions. This is in line with what nvRTC does.

This patch adds support of hipRTC to HIP headers in clang. Basically hipRTC
defines a macro __HIPCC_RTC__ when compile HIP code at run time. When
this macro is defined, HIP headers do not include standard C/C++ headers.

Reviewed by: Artem Belevich

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

Added: 
clang/test/Headers/hip-header.hip

Modified: 
clang/lib/Headers/__clang_hip_cmath.h
clang/lib/Headers/__clang_hip_math.h
clang/lib/Headers/__clang_hip_runtime_wrapper.h
clang/test/lit.cfg.py

Removed: 




diff  --git a/clang/lib/Headers/__clang_hip_cmath.h 
b/clang/lib/Headers/__clang_hip_cmath.h
index 18871e63bfa0f..632d46e47f8b9 100644
--- a/clang/lib/Headers/__clang_hip_cmath.h
+++ b/clang/lib/Headers/__clang_hip_cmath.h
@@ -14,6 +14,7 @@
 #error "This file is for HIP and OpenMP AMDGCN device compilation only."
 #endif
 
+#if !defined(__HIPCC_RTC__)
 #if defined(__cplusplus)
 #include 
 #include 
@@ -21,6 +22,7 @@
 #endif
 #include 
 #include 
+#endif // __HIPCC_RTC__
 
 #pragma push_macro("__DEVICE__")
 #define __DEVICE__ static __device__ inline __attribute__((always_inline))

diff  --git a/clang/lib/Headers/__clang_hip_math.h 
b/clang/lib/Headers/__clang_hip_math.h
index 14d91c66b3522..35cf0ad3ba6c5 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -13,11 +13,13 @@
 #error "This file is for HIP and OpenMP AMDGCN device compilation only."
 #endif
 
+#if !defined(__HIPCC_RTC__)
 #if defined(__cplusplus)
 #include 
 #endif
 #include 
 #include 
+#endif // __HIPCC_RTC__
 
 #pragma push_macro("__DEVICE__")
 #define __DEVICE__ static __device__ inline __attribute__((always_inline))
@@ -1260,6 +1262,7 @@ float min(float __x, float __y) { return fminf(__x, __y); 
}
 __DEVICE__
 double min(double __x, double __y) { return fmin(__x, __y); }
 
+#if !defined(__HIPCC_RTC__)
 __host__ inline static int min(int __arg1, int __arg2) {
   return std::min(__arg1, __arg2);
 }
@@ -1267,6 +1270,7 @@ __host__ inline static int min(int __arg1, int __arg2) {
 __host__ inline static int max(int __arg1, int __arg2) {
   return std::max(__arg1, __arg2);
 }
+#endif // __HIPCC_RTC__
 #endif
 
 #pragma pop_macro("__DEVICE__")

diff  --git a/clang/lib/Headers/__clang_hip_runtime_wrapper.h 
b/clang/lib/Headers/__clang_hip_runtime_wrapper.h
index 4fd8f23d49f38..8ee5566b33cf8 100644
--- a/clang/lib/Headers/__clang_hip_runtime_wrapper.h
+++ b/clang/lib/Headers/__clang_hip_runtime_wrapper.h
@@ -18,9 +18,27 @@
 
 #if __HIP__
 
+#if !defined(__HIPCC_RTC__)
 #include 
 #include 
 #include 
+#else
+typedef __SIZE_TYPE__ size_t;
+// Define macros which are needed to declare HIP device API's without standard
+// C/C++ headers. This is for readability so that these API's can be written
+// the same way as non-hipRTC use case. These macros need to be popped so that
+// they do not pollute users' name space.
+#pragma push_macro("NULL")
+#pragma push_macro("uint32_t")
+#pragma push_macro("uint64_t")
+#pragma push_macro("CHAR_BIT")
+#pragma push_macro("INT_MAX")
+#define NULL (void *)0
+#define uint32_t __UINT32_TYPE__
+#define uint64_t __UINT64_TYPE__
+#define CHAR_BIT __CHAR_BIT__
+#define INT_MAX __INTMAX_MAX__
+#endif // __HIPCC_RTC__
 
 #define __host__ __attribute__((host))
 #define __device__ __attribute__((device))
@@ -54,6 +72,7 @@ static inline __device__ void *free(void *__ptr) {
 #include <__clang_hip_libdevice_declares.h>
 #include <__clang_hip_math.h>
 
+#if !defined(__HIPCC_RTC__)
 #if !_OPENMP || __HIP_ENABLE_CUDA_WRAPPER_FOR_OPENMP__
 #include <__clang_cuda_math_forward_declares.h>
 #include <__clang_hip_cmath.h>
@@ -62,9 +81,16 @@ static inline __device__ void *free(void *__ptr) {
 #include 
 #include 
 #include 
+#endif // __HIPCC_RTC__
 #endif // !_OPENMP || __HIP_ENABLE_CUDA_WRAPPER_FOR_OPENMP__
 
 #define __CLANG_HIP_RUNTIME_WRAPPER_INCLUDED__ 1
-
+#if defined(__HIPCC_RTC__)
+#pragma pop_macro("NULL")
+#pragma pop_macro("uint32_t")
+#pragma pop_macro("uint64_t")
+#pragma pop_macro("CHAR_BIT")
+#pragma pop_macro("INT_MAX")
+#endif // __HIPCC_RTC__
 #endif // __HIP__
 #endif // __CLANG_HIP_RUNTIME_WRAPPER_H__

diff 

[clang] 12a1f1d - [Pragma] Added support for GCC unroll/nounroll

2021-04-17 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-04-17T17:29:55+02:00
New Revision: 12a1f1d9d7e4f7ce416d0602d18991973986dfb5

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

LOG: [Pragma] Added support for GCC unroll/nounroll

GCC 8 introduced these new pragmas to control loop unrolling. We should support 
them for compatibility reasons and the implementation itself requires few lines 
of code, since everything needed is already implemented for #pragma 
unroll/nounroll.

Added: 
clang/test/CodeGenCXX/pragma-gcc-unroll.cpp

Modified: 
clang/include/clang/Basic/AttrDocs.td
clang/lib/Parse/ParsePragma.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 867865e91056b..0af5b790d8a36 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3243,7 +3243,9 @@ def UnrollHintDocs : Documentation {
   let Content = [{
 Loop unrolling optimization hints can be specified with ``#pragma unroll`` and
 ``#pragma nounroll``. The pragma is placed immediately before a for, while,
-do-while, or c++11 range-based for loop.
+do-while, or c++11 range-based for loop. GCC's loop unrolling hints
+``#pragma GCC unroll`` and ``#pragma GCC nounroll`` are also supported and have
+identical semantics to ``#pragma unroll`` and ``#pragma nounroll``.
 
 Specifying ``#pragma unroll`` without a parameter directs the loop unroller to
 attempt to fully unroll the loop if the trip count is known at compile time and

diff  --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 4ce8e4c4bb9d9..660d317f57d07 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -405,9 +405,11 @@ void Parser::initializePragmaHandlers() {
 
   UnrollHintHandler = std::make_unique("unroll");
   PP.AddPragmaHandler(UnrollHintHandler.get());
+  PP.AddPragmaHandler("GCC", UnrollHintHandler.get());
 
   NoUnrollHintHandler = std::make_unique("nounroll");
   PP.AddPragmaHandler(NoUnrollHintHandler.get());
+  PP.AddPragmaHandler("GCC", NoUnrollHintHandler.get());
 
   UnrollAndJamHintHandler =
   std::make_unique("unroll_and_jam");
@@ -523,9 +525,11 @@ void Parser::resetPragmaHandlers() {
   LoopHintHandler.reset();
 
   PP.RemovePragmaHandler(UnrollHintHandler.get());
+  PP.RemovePragmaHandler("GCC", UnrollHintHandler.get());
   UnrollHintHandler.reset();
 
   PP.RemovePragmaHandler(NoUnrollHintHandler.get());
+  PP.RemovePragmaHandler("GCC", NoUnrollHintHandler.get());
   NoUnrollHintHandler.reset();
 
   PP.RemovePragmaHandler(UnrollAndJamHintHandler.get());

diff  --git a/clang/test/CodeGenCXX/pragma-gcc-unroll.cpp 
b/clang/test/CodeGenCXX/pragma-gcc-unroll.cpp
new file mode 100644
index 0..ed75e0b6e3c36
--- /dev/null
+++ b/clang/test/CodeGenCXX/pragma-gcc-unroll.cpp
@@ -0,0 +1,109 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s | 
FileCheck %s
+
+// Check that passing -fno-unroll-loops does not impact the decision made 
using pragmas.
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - -O1 
-disable-llvm-optzns -fno-unroll-loops %s | FileCheck %s
+
+// Verify while loop is recognized after unroll pragma.
+void while_test(int *List, int Length) {
+  // CHECK: define {{.*}} @_Z10while_test
+  int i = 0;
+
+#pragma GCC unroll
+  while (i < Length) {
+// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_1:.*]]
+List[i] = i * 2;
+i++;
+  }
+}
+
+// Verify do loop is recognized after multi-option pragma clang loop directive.
+void do_test(int *List, int Length) {
+  // CHECK: define {{.*}} @_Z7do_test
+  int i = 0;
+
+#pragma GCC nounroll
+  do {
+// CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop 
![[LOOP_2:.*]]
+List[i] = i * 2;
+i++;
+  } while (i < Length);
+}
+
+// Verify for loop is recognized after unroll pragma.
+void for_test(int *List, int Length) {
+// CHECK: define {{.*}} @_Z8for_test
+#pragma GCC unroll 8
+  for (int i = 0; i < Length; i++) {
+// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_3:.*]]
+List[i] = i * 2;
+  }
+}
+
+// Verify c++11 for range loop is recognized after unroll pragma.
+void for_range_test() {
+  // CHECK: define {{.*}} @_Z14for_range_test
+  double List[100];
+
+#pragma GCC unroll(4)
+  for (int i : List) {
+// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_4:.*]]
+List[i] = i;
+  }
+}
+
+#define UNROLLCOUNT 8
+
+// Verify defines are correctly resolved in unroll pragmas.
+void for_define_test(int *List, int Length, int Value) {
+// CHECK: define {{.*}} @_Z15for_define_test
+#pragma GCC unroll(UNROLLCOUNT)
+  for (int i = 0; i < Length; i++) {
+// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_5:.*]]
+List[i] = i * Value;
+  }
+}
+
+// Verify 

[PATCH] D98814: [CUDA][HIP] Mark device var used by host only

2021-04-17 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
yaxunl marked 2 inline comments as done.
Closed by commit rGd5c0f00e216a: [CUDA][HIP] Mark device var used by host only 
(authored by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D98814?vs=332157=338313#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98814

Files:
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/test/CodeGenCUDA/host-used-device-var.cu


Index: clang/test/CodeGenCUDA/host-used-device-var.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/host-used-device-var.cu
@@ -0,0 +1,47 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -std=c++11 -O3 -mllvm -amdgpu-internalize-symbols -emit-llvm -o - \
+// RUN:   | FileCheck %s
+
+#include "Inputs/cuda.h"
+
+// Check device variables used by neither host nor device functioins are not 
kept.
+
+// CHECK-NOT: @v1
+__device__ int v1;
+
+// CHECK-NOT: @v2
+__constant__ int v2;
+
+// CHECK-NOT: @_ZL2v3
+static __device__ int v3;
+
+// Check device variables used by host functions are kept.
+
+// CHECK-DAG: @u1
+__device__ int u1;
+
+// CHECK-DAG: @u2
+__constant__ int u2;
+
+// Check host-used static device var is in llvm.compiler.used.
+// CHECK-DAG: @_ZL2u3
+static __device__ int u3;
+
+// Check device-used static device var is emitted but is not in 
llvm.compiler.used.
+// CHECK-DAG: @_ZL2u4
+static __device__ int u4;
+
+// Check device variables with used attribute are always kept.
+// CHECK-DAG: @u5
+__device__ __attribute__((used)) int u5;
+
+int fun1() {
+  return u1 + u2 + u3;
+}
+
+__global__ void kern1(int **x) {
+  *x = 
+}
+// Check the exact list of variables to ensure @_ZL2u4 is not among them.
+// CHECK: @llvm.compiler.used = {{[^@]*}} @_ZL2u3 {{[^@]*}} @u1 {{[^@]*}} @u2 
{{[^@]*}} @u5
Index: clang/lib/CodeGen/CGCUDANV.cpp
===
--- clang/lib/CodeGen/CGCUDANV.cpp
+++ clang/lib/CodeGen/CGCUDANV.cpp
@@ -1089,6 +1089,28 @@
 llvm::Function *CGNVCUDARuntime::finalizeModule() {
   if (CGM.getLangOpts().CUDAIsDevice) {
 transformManagedVars();
+
+// Mark ODR-used device variables as compiler used to prevent it from being
+// eliminated by optimization. This is necessary for device variables
+// ODR-used by host functions. Sema correctly marks them as ODR-used no
+// matter whether they are ODR-used by device or host functions.
+//
+// We do not need to do this if the variable has used attribute since it
+// has already been added.
+//
+// Static device variables have been externalized at this point, therefore
+// variables with LLVM private or internal linkage need not be added.
+for (auto & : DeviceVars) {
+  auto Kind = Info.Flags.getKind();
+  if (!Info.Var->isDeclaration() &&
+  !llvm::GlobalValue::isLocalLinkage(Info.Var->getLinkage()) &&
+  (Kind == DeviceVarFlags::Variable ||
+   Kind == DeviceVarFlags::Surface ||
+   Kind == DeviceVarFlags::Texture) &&
+  Info.D->isUsed() && !Info.D->hasAttr()) {
+CGM.addCompilerUsedGlobal(Info.Var);
+  }
+}
 return nullptr;
   }
   return makeModuleCtorFunction();


Index: clang/test/CodeGenCUDA/host-used-device-var.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/host-used-device-var.cu
@@ -0,0 +1,47 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -std=c++11 -O3 -mllvm -amdgpu-internalize-symbols -emit-llvm -o - \
+// RUN:   | FileCheck %s
+
+#include "Inputs/cuda.h"
+
+// Check device variables used by neither host nor device functioins are not kept.
+
+// CHECK-NOT: @v1
+__device__ int v1;
+
+// CHECK-NOT: @v2
+__constant__ int v2;
+
+// CHECK-NOT: @_ZL2v3
+static __device__ int v3;
+
+// Check device variables used by host functions are kept.
+
+// CHECK-DAG: @u1
+__device__ int u1;
+
+// CHECK-DAG: @u2
+__constant__ int u2;
+
+// Check host-used static device var is in llvm.compiler.used.
+// CHECK-DAG: @_ZL2u3
+static __device__ int u3;
+
+// Check device-used static device var is emitted but is not in llvm.compiler.used.
+// CHECK-DAG: @_ZL2u4
+static __device__ int u4;
+
+// Check device variables with used attribute are always kept.
+// CHECK-DAG: @u5
+__device__ __attribute__((used)) int u5;
+
+int fun1() {
+  return u1 + u2 + u3;
+}
+
+__global__ void kern1(int **x) {
+  *x = 
+}
+// Check the exact list of variables to ensure @_ZL2u4 is not among them.
+// CHECK: @llvm.compiler.used = {{[^@]*}} @_ZL2u3 {{[^@]*}} @u1 {{[^@]*}} @u2 {{[^@]*}} @u5
Index: clang/lib/CodeGen/CGCUDANV.cpp

[clang] d5c0f00 - [CUDA][HIP] Mark device var used by host only

2021-04-17 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-04-17T11:25:25-04:00
New Revision: d5c0f00e216aa6797499bb4c8aacac930d8a819b

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

LOG: [CUDA][HIP] Mark device var used by host only

Add device variables to llvm.compiler.used if they are
ODR-used by either host or device functions.

This is necessary to prevent them from being
eliminated by whole-program optimization
where the compiler has no way to know a device
variable is used by some host code.

Reviewed by: Artem Belevich

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

Added: 
clang/test/CodeGenCUDA/host-used-device-var.cu

Modified: 
clang/lib/CodeGen/CGCUDANV.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index b224de7c197ae..27fe048f827d0 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1089,6 +1089,28 @@ void CGNVCUDARuntime::transformManagedVars() {
 llvm::Function *CGNVCUDARuntime::finalizeModule() {
   if (CGM.getLangOpts().CUDAIsDevice) {
 transformManagedVars();
+
+// Mark ODR-used device variables as compiler used to prevent it from being
+// eliminated by optimization. This is necessary for device variables
+// ODR-used by host functions. Sema correctly marks them as ODR-used no
+// matter whether they are ODR-used by device or host functions.
+//
+// We do not need to do this if the variable has used attribute since it
+// has already been added.
+//
+// Static device variables have been externalized at this point, therefore
+// variables with LLVM private or internal linkage need not be added.
+for (auto & : DeviceVars) {
+  auto Kind = Info.Flags.getKind();
+  if (!Info.Var->isDeclaration() &&
+  !llvm::GlobalValue::isLocalLinkage(Info.Var->getLinkage()) &&
+  (Kind == DeviceVarFlags::Variable ||
+   Kind == DeviceVarFlags::Surface ||
+   Kind == DeviceVarFlags::Texture) &&
+  Info.D->isUsed() && !Info.D->hasAttr()) {
+CGM.addCompilerUsedGlobal(Info.Var);
+  }
+}
 return nullptr;
   }
   return makeModuleCtorFunction();

diff  --git a/clang/test/CodeGenCUDA/host-used-device-var.cu 
b/clang/test/CodeGenCUDA/host-used-device-var.cu
new file mode 100644
index 0..fd501ed1f2fd7
--- /dev/null
+++ b/clang/test/CodeGenCUDA/host-used-device-var.cu
@@ -0,0 +1,47 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -std=c++11 -O3 -mllvm -amdgpu-internalize-symbols -emit-llvm -o - \
+// RUN:   | FileCheck %s
+
+#include "Inputs/cuda.h"
+
+// Check device variables used by neither host nor device functioins are not 
kept.
+
+// CHECK-NOT: @v1
+__device__ int v1;
+
+// CHECK-NOT: @v2
+__constant__ int v2;
+
+// CHECK-NOT: @_ZL2v3
+static __device__ int v3;
+
+// Check device variables used by host functions are kept.
+
+// CHECK-DAG: @u1
+__device__ int u1;
+
+// CHECK-DAG: @u2
+__constant__ int u2;
+
+// Check host-used static device var is in llvm.compiler.used.
+// CHECK-DAG: @_ZL2u3
+static __device__ int u3;
+
+// Check device-used static device var is emitted but is not in 
llvm.compiler.used.
+// CHECK-DAG: @_ZL2u4
+static __device__ int u4;
+
+// Check device variables with used attribute are always kept.
+// CHECK-DAG: @u5
+__device__ __attribute__((used)) int u5;
+
+int fun1() {
+  return u1 + u2 + u3;
+}
+
+__global__ void kern1(int **x) {
+  *x = 
+}
+// Check the exact list of variables to ensure @_ZL2u4 is not among them.
+// CHECK: @llvm.compiler.used = {{[^@]*}} @_ZL2u3 {{[^@]*}} @u1 {{[^@]*}} @u2 
{{[^@]*}} @u5



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


[clang] 3597f02 - [AMDGPU] Add GlobalDCE before internalization pass

2021-04-17 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-04-17T11:25:25-04:00
New Revision: 3597f02fd5c62f7c49c71b92e467128ffe2cf9cd

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

LOG: [AMDGPU] Add GlobalDCE before internalization pass

The internalization pass only internalizes global variables
with no users. If the global variable has some dead user,
the internalization pass will not internalize it.

To be able to internalize global variables with dead
users, a global dce pass is needed before the
internalization pass.

This patch adds that.

Reviewed by: Artem Belevich, Matt Arsenault

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

Added: 
clang/test/CodeGenCUDA/unused-global-var.cu

Modified: 
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Removed: 




diff  --git a/clang/test/CodeGenCUDA/unused-global-var.cu 
b/clang/test/CodeGenCUDA/unused-global-var.cu
new file mode 100644
index 0..1dbb3a22563c8
--- /dev/null
+++ b/clang/test/CodeGenCUDA/unused-global-var.cu
@@ -0,0 +1,53 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -std=c++11 -O3 -mllvm -amdgpu-internalize-symbols -emit-llvm -o - \
+// RUN:   -target-cpu gfx906 | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -std=c++11 -O3 -mllvm -amdgpu-internalize-symbols -emit-llvm -o - \
+// RUN:   -target-cpu gfx906 | FileCheck -check-prefix=NEGCHK %s
+
+#include "Inputs/cuda.h"
+
+// AMDGPU internalize unused global variables for whole-program compilation
+// (-fno-gpu-rdc for each TU, or -fgpu-rdc for LTO), which are then
+// eliminated by global DCE. If there are invisible unused address space casts
+// for global variables, these dead users need to be eliminated by global
+// DCE before internalization. This test makes sure unused global variables
+// are eliminated.
+
+// Check unused device/constant variables are eliminated.
+
+// NEGCHK-NOT: @v1
+__device__ int v1;
+
+// NEGCHK-NOT: @v2
+__constant__ int v2;
+
+// NEGCHK-NOT: @_ZL2v3
+constexpr int v3 = 1;
+
+// Check managed variables are always kept.
+
+// CHECK-DAG: @v4
+__managed__ int v4;
+
+// Check used device/constant variables are not eliminated.
+// CHECK-DAG: @u1
+__device__ int u1;
+
+// CHECK-DAG: @u2
+__constant__ int u2;
+
+// Check u3 is kept because its address is taken.
+// CHECK-DAG: @_ZL2u3
+constexpr int u3 = 2;
+
+// Check u4 is not kept because it is not ODR-use.
+// NEGCHK-NOT: @_ZL2u4
+constexpr int u4 = 3;
+
+__device__ int fun1(const int& x);
+
+__global__ void kern1(int *x) {
+  *x = u1 + u2 + fun1(u3) + u4;
+}

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index ce39609da303d..1b3b56f5dc71f 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -575,6 +575,9 @@ void 
AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder ,
 PM.addPass(AMDGPUPrintfRuntimeBindingPass());
 
 if (InternalizeSymbols) {
+  // Global variables may have dead uses which need to be removed.
+  // Otherwise these useless global variables will not get 
internalized.
+  PM.addPass(GlobalDCEPass());
   PM.addPass(InternalizePass(mustPreserveGV));
 }
 PM.addPass(AMDGPUPropagateAttributesLatePass(*this));



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


[PATCH] D98783: [AMDGPU] Add GlobalDCE before internalization pass

2021-04-17 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3597f02fd5c6: [AMDGPU] Add GlobalDCE before internalization 
pass (authored by yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98783

Files:
  clang/test/CodeGenCUDA/unused-global-var.cu
  llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp


Index: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
===
--- llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -575,6 +575,9 @@
 PM.addPass(AMDGPUPrintfRuntimeBindingPass());
 
 if (InternalizeSymbols) {
+  // Global variables may have dead uses which need to be removed.
+  // Otherwise these useless global variables will not get 
internalized.
+  PM.addPass(GlobalDCEPass());
   PM.addPass(InternalizePass(mustPreserveGV));
 }
 PM.addPass(AMDGPUPropagateAttributesLatePass(*this));
Index: clang/test/CodeGenCUDA/unused-global-var.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/unused-global-var.cu
@@ -0,0 +1,53 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -std=c++11 -O3 -mllvm -amdgpu-internalize-symbols -emit-llvm -o - \
+// RUN:   -target-cpu gfx906 | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -std=c++11 -O3 -mllvm -amdgpu-internalize-symbols -emit-llvm -o - \
+// RUN:   -target-cpu gfx906 | FileCheck -check-prefix=NEGCHK %s
+
+#include "Inputs/cuda.h"
+
+// AMDGPU internalize unused global variables for whole-program compilation
+// (-fno-gpu-rdc for each TU, or -fgpu-rdc for LTO), which are then
+// eliminated by global DCE. If there are invisible unused address space casts
+// for global variables, these dead users need to be eliminated by global
+// DCE before internalization. This test makes sure unused global variables
+// are eliminated.
+
+// Check unused device/constant variables are eliminated.
+
+// NEGCHK-NOT: @v1
+__device__ int v1;
+
+// NEGCHK-NOT: @v2
+__constant__ int v2;
+
+// NEGCHK-NOT: @_ZL2v3
+constexpr int v3 = 1;
+
+// Check managed variables are always kept.
+
+// CHECK-DAG: @v4
+__managed__ int v4;
+
+// Check used device/constant variables are not eliminated.
+// CHECK-DAG: @u1
+__device__ int u1;
+
+// CHECK-DAG: @u2
+__constant__ int u2;
+
+// Check u3 is kept because its address is taken.
+// CHECK-DAG: @_ZL2u3
+constexpr int u3 = 2;
+
+// Check u4 is not kept because it is not ODR-use.
+// NEGCHK-NOT: @_ZL2u4
+constexpr int u4 = 3;
+
+__device__ int fun1(const int& x);
+
+__global__ void kern1(int *x) {
+  *x = u1 + u2 + fun1(u3) + u4;
+}


Index: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
===
--- llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -575,6 +575,9 @@
 PM.addPass(AMDGPUPrintfRuntimeBindingPass());
 
 if (InternalizeSymbols) {
+  // Global variables may have dead uses which need to be removed.
+  // Otherwise these useless global variables will not get internalized.
+  PM.addPass(GlobalDCEPass());
   PM.addPass(InternalizePass(mustPreserveGV));
 }
 PM.addPass(AMDGPUPropagateAttributesLatePass(*this));
Index: clang/test/CodeGenCUDA/unused-global-var.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/unused-global-var.cu
@@ -0,0 +1,53 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -std=c++11 -O3 -mllvm -amdgpu-internalize-symbols -emit-llvm -o - \
+// RUN:   -target-cpu gfx906 | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -std=c++11 -O3 -mllvm -amdgpu-internalize-symbols -emit-llvm -o - \
+// RUN:   -target-cpu gfx906 | FileCheck -check-prefix=NEGCHK %s
+
+#include "Inputs/cuda.h"
+
+// AMDGPU internalize unused global variables for whole-program compilation
+// (-fno-gpu-rdc for each TU, or -fgpu-rdc for LTO), which are then
+// eliminated by global DCE. If there are invisible unused address space casts
+// for global variables, these dead users need to be eliminated by global
+// DCE before internalization. This test makes sure unused global variables
+// are eliminated.
+
+// Check unused device/constant variables are eliminated.
+
+// NEGCHK-NOT: @v1
+__device__ int v1;
+
+// NEGCHK-NOT: @v2
+__constant__ int v2;
+
+// NEGCHK-NOT: @_ZL2v3
+constexpr int v3 = 1;
+
+// Check managed variables are always kept.
+
+// CHECK-DAG: @v4
+__managed__ int v4;
+
+// Check used 

[PATCH] D100705: Fixed Typos

2021-04-17 Thread Jennifer Chukwu via Phabricator via cfe-commits
jnyfah created this revision.
jnyfah added a reviewer: xgupta.
jnyfah added a project: LLVM.
jnyfah requested review of this revision.
Herald added projects: clang, libc++.
Herald added subscribers: libcxx-commits, cfe-commits.
Herald added a reviewer: libc++.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100705

Files:
  clang/docs/UsersManual.rst
  libcxx/docs/UsingLibcxx.rst


Index: libcxx/docs/UsingLibcxx.rst
===
--- libcxx/docs/UsingLibcxx.rst
+++ libcxx/docs/UsingLibcxx.rst
@@ -114,10 +114,10 @@
 GCC does not provide a way to switch from libstdc++ to libc++. You must 
manually
 configure the compile and link commands.
 
-In particular you must tell GCC to remove the libstdc++ include directories
+In particular, you must tell GCC to remove the libstdc++ include directories
 using ``-nostdinc++`` and to not link libstdc++.so using ``-nodefaultlibs``.
 
-Note that ``-nodefaultlibs`` removes all of the standard system libraries and
+Note that ``-nodefaultlibs`` removes all the standard system libraries and
 not just libstdc++ so they must be manually linked. For example:
 
 .. code-block:: bash
@@ -151,7 +151,7 @@
 
 **_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS**:
   This macro is used to enable -Wthread-safety annotations on libc++'s
-  ``std::mutex`` and ``std::lock_guard``. By default these annotations are
+  ``std::mutex`` and ``std::lock_guard``. By default, these annotations are
   disabled and must be manually enabled by the user.
 
 **_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS**:
@@ -352,4 +352,4 @@
 * ``move_if_noexcept``
 * ``identity::operator()``
 * ``to_integer``
-* ``to_underlying``
+* ``to_underlying``
\ No newline at end of file
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -686,7 +686,7 @@
 .. option:: -gen-reproducer
 
   Generates preprocessed source files, a reproducer script and if relevant, a
-  cache containing: built module pcm's and all headers needed to rebuilt the
+  cache containing: built module pcm's and all headers needed to rebuild the
   same modules.
 
 .. _rpass:
@@ -3913,4 +3913,4 @@
 If the user is using the static CRT (``/MT``), then different runtimes are used
 to produce DLLs and EXEs. To link a DLL, pass
 ``clang_rt.asan_dll_thunk-x86_64.lib``. To link an EXE, pass
-``-wholearchive:clang_rt.asan-x86_64.lib``.
+``-wholearchive:clang_rt.asan-x86_64.lib``.
\ No newline at end of file


Index: libcxx/docs/UsingLibcxx.rst
===
--- libcxx/docs/UsingLibcxx.rst
+++ libcxx/docs/UsingLibcxx.rst
@@ -114,10 +114,10 @@
 GCC does not provide a way to switch from libstdc++ to libc++. You must manually
 configure the compile and link commands.
 
-In particular you must tell GCC to remove the libstdc++ include directories
+In particular, you must tell GCC to remove the libstdc++ include directories
 using ``-nostdinc++`` and to not link libstdc++.so using ``-nodefaultlibs``.
 
-Note that ``-nodefaultlibs`` removes all of the standard system libraries and
+Note that ``-nodefaultlibs`` removes all the standard system libraries and
 not just libstdc++ so they must be manually linked. For example:
 
 .. code-block:: bash
@@ -151,7 +151,7 @@
 
 **_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS**:
   This macro is used to enable -Wthread-safety annotations on libc++'s
-  ``std::mutex`` and ``std::lock_guard``. By default these annotations are
+  ``std::mutex`` and ``std::lock_guard``. By default, these annotations are
   disabled and must be manually enabled by the user.
 
 **_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS**:
@@ -352,4 +352,4 @@
 * ``move_if_noexcept``
 * ``identity::operator()``
 * ``to_integer``
-* ``to_underlying``
+* ``to_underlying``
\ No newline at end of file
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -686,7 +686,7 @@
 .. option:: -gen-reproducer
 
   Generates preprocessed source files, a reproducer script and if relevant, a
-  cache containing: built module pcm's and all headers needed to rebuilt the
+  cache containing: built module pcm's and all headers needed to rebuild the
   same modules.
 
 .. _rpass:
@@ -3913,4 +3913,4 @@
 If the user is using the static CRT (``/MT``), then different runtimes are used
 to produce DLLs and EXEs. To link a DLL, pass
 ``clang_rt.asan_dll_thunk-x86_64.lib``. To link an EXE, pass
-``-wholearchive:clang_rt.asan-x86_64.lib``.
+``-wholearchive:clang_rt.asan-x86_64.lib``.
\ No newline at end of file
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98814: [CUDA][HIP] Mark device var used by host only

2021-04-17 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added inline comments.



Comment at: clang/test/CodeGenCUDA/host-used-device-var.cu:31-33
+// Check device-used static device var is not in llvm.compiler.used.
+// CHECK-DAG: @_ZL2u4
+static __device__ int u4;

tra wrote:
> I'd rephrase it as 'but is not in llvm.compiler.used'
> 
will do



Comment at: clang/test/CodeGenCUDA/host-used-device-var.cu:46
+}
+// CHECK: @llvm.compiler.used = {{[^@]*}} @_ZL2u3 {{[^@]*}} @u1 {{[^@]*}} @u2 
{{[^@]*}} @u5

tra wrote:
> I'd add a comment that we're effectively matching the exact list of the 
> variables here and that ensures that `@_ZL2u4` is not among them.
> 
will do


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

https://reviews.llvm.org/D98814

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


[PATCH] D100658: [RISCV] Apply __clang_riscv_builtin_alias to overloaded builtins.

2021-04-17 Thread Zakk Chen via Phabricator via cfe-commits
khchen added a comment.

I think you also need to handle `PermuteOperands` field 
?
 
`PermuteOperands` performs the order permutation for non-masked and masked 
intrinsics  when the operand order is different to builtins.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100658

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


[PATCH] D100701: [clang][AVR] Redefine some types to be compatible with avr-gcc

2021-04-17 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.

Though the disabled test builtins.cpp  can pass after my another patch 
https://reviews.llvm.org/D97669, it will still fail on llvm build machines, 
since there are no avr-libc installed on them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100701

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


[PATCH] D100701: [clang][AVR] Redefine some types to be compatible with avr-gcc

2021-04-17 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.

Some key points,

1. This patch fixes the bug https://bugs.llvm.org/show_bug.cgi?id=31530 .

2. The test builtins.cpp is disabled on AVR, due to uint16_t is defined to 
unsigned short. The underlying reason is that the system's libc/stdint.h is 
used instead of avr-libc's stdint.h. And I will re-enable it after my another 
patch is merged. https://reviews.llvm.org/D97669




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100701

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


[PATCH] D93978: [clangd] Use dirty filesystem when performing cross file tweaks

2021-04-17 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 338294.
njames93 marked 4 inline comments as done.
njames93 added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93978

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/refactor/Tweak.cpp
  clang-tools-extra/clangd/refactor/Tweak.h
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/tool/Check.cpp
  clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
@@ -74,7 +74,8 @@
   SelectionTree::createEach(AST.getASTContext(), AST.getTokens(), Range.first,
 Range.second, [&](SelectionTree ST) {
   Tweak::Selection S(Index, AST, Range.first,
- Range.second, std::move(ST));
+ Range.second, std::move(ST),
+ nullptr);
   if (auto T = prepareTweak(TweakID, S, nullptr)) {
 Result = (*T)->apply(S);
 return true;
Index: clang-tools-extra/clangd/tool/Check.cpp
===
--- clang-tools-extra/clangd/tool/Check.cpp
+++ clang-tools-extra/clangd/tool/Check.cpp
@@ -210,7 +210,8 @@
   vlog("  {0} {1}", Pos, Tok.text(AST->getSourceManager()));
   auto Tree = SelectionTree::createRight(AST->getASTContext(),
  AST->getTokens(), Start, End);
-  Tweak::Selection Selection(, *AST, Start, End, std::move(Tree));
+  Tweak::Selection Selection(, *AST, Start, End, std::move(Tree),
+ nullptr);
   for (const auto  :
prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules)) {
 auto Result = T->apply(Selection);
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -64,9 +64,8 @@
 
 llvm::Optional getSourceFile(llvm::StringRef FileName,
const Tweak::Selection ) {
-  if (auto Source = getCorrespondingHeaderOrSource(
-  FileName,
-  >getSourceManager().getFileManager().getVirtualFileSystem()))
+  assert(Sel.FS);
+  if (auto Source = getCorrespondingHeaderOrSource(FileName, Sel.FS))
 return *Source;
   return getCorrespondingHeaderOrSource(FileName, *Sel.AST, Sel.Index);
 }
@@ -414,12 +413,11 @@
   return error("Couldn't get absolute path for main file.");
 
 auto CCFile = getSourceFile(*MainFileName, Sel);
+
 if (!CCFile)
   return error("Couldn't find a suitable implementation file.");
-
-auto  =
-Sel.AST->getSourceManager().getFileManager().getVirtualFileSystem();
-auto Buffer = FS.getBufferForFile(*CCFile);
+assert(Sel.FS && "FS Must be set in apply");
+auto Buffer = Sel.FS->getBufferForFile(*CCFile);
 // FIXME: Maybe we should consider creating the implementation file if it
 // doesn't exist?
 if (!Buffer)
Index: clang-tools-extra/clangd/refactor/Tweak.h
===
--- clang-tools-extra/clangd/refactor/Tweak.h
+++ clang-tools-extra/clangd/refactor/Tweak.h
@@ -51,7 +51,8 @@
   /// Input to prepare and apply tweaks.
   struct Selection {
 Selection(const SymbolIndex *Index, ParsedAST , unsigned RangeBegin,
-  unsigned RangeEnd, SelectionTree ASTSelection);
+  unsigned RangeEnd, SelectionTree ASTSelection,
+  llvm::vfs::FileSystem *VFS);
 /// The text of the active document.
 llvm::StringRef Code;
 /// The Index for handling codebase related queries.
@@ -67,6 +68,9 @@
 unsigned SelectionEnd;
 /// The AST nodes that were selected.
 SelectionTree ASTSelection;
+/// File system used to access source code (for cross-file tweaks).
+/// This is only populated when applying a tweak, not during prepare.
+llvm::vfs::FileSystem *FS = nullptr;
 // FIXME: provide a way to get sources and ASTs for other files.
   };
 
Index: clang-tools-extra/clangd/refactor/Tweak.cpp
===
--- clang-tools-extra/clangd/refactor/Tweak.cpp
+++ clang-tools-extra/clangd/refactor/Tweak.cpp
@@ -61,9 +61,10 @@
 
 Tweak::Selection::Selection(const SymbolIndex *Index, ParsedAST ,
 unsigned RangeBegin, 

[PATCH] D100509: Support GCC's -fstack-usage flag

2021-04-17 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

cc @r




Comment at: clang/include/clang/Basic/CodeGenOptions.h:391
   std::vector SanitizeCoverageBlocklistFiles;
 
+  std::string StackUsageOutput;

Nit: comment? Like one in TargetOptions.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100509

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


[PATCH] D100701: [clang][AVR] Redefine some types to be compatible with avr-gcc

2021-04-17 Thread Ben Shi via Phabricator via cfe-commits
benshi001 created this revision.
benshi001 added reviewers: aykevl, dylanmckay.
Herald added a subscriber: Jim.
benshi001 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100701

Files:
  clang/lib/Basic/Targets/AVR.cpp
  clang/test/CodeGen/builtins.cpp
  clang/test/Preprocessor/init.c


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -1941,7 +1941,7 @@
 // AVR:#define __GXX_ABI_VERSION 1002
 // AVR:#define __INT16_C_SUFFIX__
 // AVR:#define __INT16_MAX__ 32767
-// AVR:#define __INT16_TYPE__ short
+// AVR:#define __INT16_TYPE__ int
 // AVR:#define __INT32_C_SUFFIX__ L
 // AVR:#define __INT32_MAX__ 2147483647L
 // AVR:#define __INT32_TYPE__ long int
@@ -2016,7 +2016,7 @@
 // AVR:#define __SIZE_TYPE__ unsigned int
 // AVR:#define __STDC__ 1
 // AVR:#define __UINT16_MAX__ 65535U
-// AVR:#define __UINT16_TYPE__ unsigned short
+// AVR:#define __UINT16_TYPE__ unsigned int
 // AVR:#define __UINT32_C_SUFFIX__ UL
 // AVR:#define __UINT32_MAX__ 4294967295UL
 // AVR:#define __UINT32_TYPE__ long unsigned int
Index: clang/test/CodeGen/builtins.cpp
===
--- clang/test/CodeGen/builtins.cpp
+++ clang/test/CodeGen/builtins.cpp
@@ -1,6 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-linux-gnu -ffreestanding -verify 
%s
 // RUN: %clang_cc1 -std=c++11 -triple i686-pc-linux-gnu -ffreestanding -verify 
%s
-// RUN: %clang_cc1 -std=c++11 -triple avr-unknown-unknown -ffreestanding 
-verify %s
 
 // expected-no-diagnostics
 
Index: clang/lib/Basic/Targets/AVR.cpp
===
--- clang/lib/Basic/Targets/AVR.cpp
+++ clang/lib/Basic/Targets/AVR.cpp
@@ -309,6 +309,8 @@
   Builder.defineMacro("__AVR__");
   Builder.defineMacro("__ELF__");
   Builder.defineMacro("__flash", "__attribute__((address_space(1)))");
+  Builder.defineMacro("__UINT16_TYPE__", "unsigned int");
+  Builder.defineMacro("__INT16_TYPE__", "int");
 
   if (!this->CPU.empty()) {
 auto It = llvm::find_if(


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -1941,7 +1941,7 @@
 // AVR:#define __GXX_ABI_VERSION 1002
 // AVR:#define __INT16_C_SUFFIX__
 // AVR:#define __INT16_MAX__ 32767
-// AVR:#define __INT16_TYPE__ short
+// AVR:#define __INT16_TYPE__ int
 // AVR:#define __INT32_C_SUFFIX__ L
 // AVR:#define __INT32_MAX__ 2147483647L
 // AVR:#define __INT32_TYPE__ long int
@@ -2016,7 +2016,7 @@
 // AVR:#define __SIZE_TYPE__ unsigned int
 // AVR:#define __STDC__ 1
 // AVR:#define __UINT16_MAX__ 65535U
-// AVR:#define __UINT16_TYPE__ unsigned short
+// AVR:#define __UINT16_TYPE__ unsigned int
 // AVR:#define __UINT32_C_SUFFIX__ UL
 // AVR:#define __UINT32_MAX__ 4294967295UL
 // AVR:#define __UINT32_TYPE__ long unsigned int
Index: clang/test/CodeGen/builtins.cpp
===
--- clang/test/CodeGen/builtins.cpp
+++ clang/test/CodeGen/builtins.cpp
@@ -1,6 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-linux-gnu -ffreestanding -verify %s
 // RUN: %clang_cc1 -std=c++11 -triple i686-pc-linux-gnu -ffreestanding -verify %s
-// RUN: %clang_cc1 -std=c++11 -triple avr-unknown-unknown -ffreestanding -verify %s
 
 // expected-no-diagnostics
 
Index: clang/lib/Basic/Targets/AVR.cpp
===
--- clang/lib/Basic/Targets/AVR.cpp
+++ clang/lib/Basic/Targets/AVR.cpp
@@ -309,6 +309,8 @@
   Builder.defineMacro("__AVR__");
   Builder.defineMacro("__ELF__");
   Builder.defineMacro("__flash", "__attribute__((address_space(1)))");
+  Builder.defineMacro("__UINT16_TYPE__", "unsigned int");
+  Builder.defineMacro("__INT16_TYPE__", "int");
 
   if (!this->CPU.empty()) {
 auto It = llvm::find_if(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D100516: [AST] Add TypeLoc support to node introspection

2021-04-17 Thread Nathan James via Phabricator via cfe-commits
njames93 accepted this revision.
njames93 added a comment.
This revision is now accepted and ready to land.

LGTM, just a few nits before landing please.




Comment at: clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp:172-176
+  if (TypeLocBase && Node->getName() == "getLocalSourceRange")
+continue;
+  if ((ASTClass->getName() == "PointerLikeTypeLoc" ||
+   ASTClass->getName() == "TypeofLikeTypeLoc") &&
+  Node->getName() == "getLocalSourceRange")

njames93 wrote:
> Can we have a comment explaining why we are discarding these?
nit: can this be addressed?



Comment at: clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp:25
   Finder->addMatcher(
-  cxxRecordDecl(
-  isDefinition(),
-  isSameOrDerivedFrom(
-  // TODO: Extend this with other clades
-  namedDecl(hasAnyName("clang::Stmt", "clang::Decl",
-   "clang::CXXCtorInitializer",
-   "clang::NestedNameSpecifierLoc",
-   "clang::TemplateArgumentLoc",
-   "clang::CXXBaseSpecifier"))
-  .bind("nodeClade")),
-  optionally(isDerivedFrom(cxxRecordDecl().bind("derivedFrom"
-  .bind("className"),
+  traverse(
+  TK_IgnoreUnlessSpelledInSource,

nit: Is it not easier to just override `getCheckTraversalKind` for the class?



Comment at: clang/unittests/Introspection/IntrospectionTest.cpp:209-210
+  EXPECT_EQ(
+  ExpectedLocations,
+  (std::vector>{
+STRING_LOCATION_STDPAIR(MethodDecl, getBeginLoc()),

nit: Don't create a vector here unnecessarily, same below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100516

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


[PATCH] D100696: Fixed typos

2021-04-17 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added inline comments.



Comment at: polly/docs/ReleaseNotes.rst:9
 
-  These release notes are for the next release of Polly and it describes
+  These release notes are for the next release of Polly and describe
   the new features that have recently been committed to our development

This diff seems to be based on D100588 which changes "These releaes notes [...] 
and describe" to "These release notes [...] and it describes". IMHO the second 
part is incorrect (and reverted by this patch), or at least unnecessary, 
because 1) "release notes" is plural and 2) "describe" is a compound predicate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100696

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


[PATCH] D100696: Fixed typos

2021-04-17 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

@jnyfah If you are missing something I am just telling you the steps -

1. First fork the llvm github repository
2. git clone https://github.com/jynfah/llvm-project
3. git checkout -b type-fix
4. make changes to files.
5. git diff  > mypatch.patch
6. git commit -m "fix typo"
7. go to reviews.llvm.org and login and click on differential then create diff 
and update the diff (mypatch.patch)
8. complete remaining entries.

Then there is an arc tool way, install it from 
https://secure.phabricator.com/book/phabricator/article/arcanist_quick_start/.
after the 4th step, skip 5 and complete 6, and then do `arc diff` to create a 
revision from the terminal. You will be asked to verify credentials.
If reviewers asks you to make changes, checkout your local branch, make changes 
and then again do `arc diff`.

Don't forget to rebase by `git pull --rebase 
https://github.com/llvm/llvm-project.git main`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100696

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


[PATCH] D100696: Fixed typos

2021-04-17 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

Actually, I am not able to apply this patch with `arc patch D100696`.

Created and checked out branch arcpatch-D100696.
Checking patch polly/docs/ReleaseNotes.rst...
error: while searching for:

.. warning::

  These release notes are for the next release of Polly and it describes
  the new features that have recently been committed to our development
  branch.

error: patch failed: polly/docs/ReleaseNotes.rst:6
Checking patch libcxx/docs/UsingLibcxx.rst...
Checking patch clang/docs/UsersManual.rst...
Applying patch polly/docs/ReleaseNotes.rst with 1 reject...
Rejected hunk #1.

@curdeius could you help here to understand why this message comes?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100696

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


[PATCH] D100696: Fixed typos

2021-04-17 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta accepted this revision.
xgupta added a comment.
This revision now requires review to proceed.

Oh sorry, Your patch is correct. I misunderstand something :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100696

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


[PATCH] D100696: Fixed typos

2021-04-17 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta requested changes to this revision.
xgupta added a comment.
This revision now requires changes to proceed.

Thanks @jnyfah for the patch!

It looks you need to rebase your branch to llvm upstream main branch. Because 
polly/docs/ReleaseNotes.rst is recently change. Now its contain nothing see - 
https://polly.llvm.org/docs/ReleaseNotes.html.

Release note for the previous branch is now published and we can't change them. 
So now your patch should contain only the changes in clang/docs/UsersManual.rst 
and libcxx/docs/UsingLibcxx.rst.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100696

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


[PATCH] D100696: Fixed typos

2021-04-17 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision as: curdeius.
curdeius added a comment.

LGTM. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100696

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


[PATCH] D100696: Fixed typos

2021-04-17 Thread Jennifer Chukwu via Phabricator via cfe-commits
jnyfah created this revision.
Herald added a reviewer: bollu.
jnyfah requested review of this revision.
Herald added projects: clang, libc++.
Herald added subscribers: libcxx-commits, cfe-commits.
Herald added a reviewer: libc++.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100696

Files:
  clang/docs/UsersManual.rst
  libcxx/docs/UsingLibcxx.rst
  polly/docs/ReleaseNotes.rst


Index: polly/docs/ReleaseNotes.rst
===
--- polly/docs/ReleaseNotes.rst
+++ polly/docs/ReleaseNotes.rst
@@ -6,7 +6,7 @@
 
 .. warning::
 
-  These release notes are for the next release of Polly and it describes
+  These release notes are for the next release of Polly and describe
   the new features that have recently been committed to our development
   branch.
 
Index: libcxx/docs/UsingLibcxx.rst
===
--- libcxx/docs/UsingLibcxx.rst
+++ libcxx/docs/UsingLibcxx.rst
@@ -114,10 +114,10 @@
 GCC does not provide a way to switch from libstdc++ to libc++. You must 
manually
 configure the compile and link commands.
 
-In particular you must tell GCC to remove the libstdc++ include directories
+In particular, you must tell GCC to remove the libstdc++ include directories
 using ``-nostdinc++`` and to not link libstdc++.so using ``-nodefaultlibs``.
 
-Note that ``-nodefaultlibs`` removes all of the standard system libraries and
+Note that ``-nodefaultlibs`` removes all the standard system libraries and
 not just libstdc++ so they must be manually linked. For example:
 
 .. code-block:: bash
@@ -151,7 +151,7 @@
 
 **_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS**:
   This macro is used to enable -Wthread-safety annotations on libc++'s
-  ``std::mutex`` and ``std::lock_guard``. By default these annotations are
+  ``std::mutex`` and ``std::lock_guard``. By default, these annotations are
   disabled and must be manually enabled by the user.
 
 **_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS**:
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -686,7 +686,7 @@
 .. option:: -gen-reproducer
 
   Generates preprocessed source files, a reproducer script and if relevant, a
-  cache containing: built module pcm's and all headers needed to rebuilt the
+  cache containing: built module pcm's and all headers needed to rebuild the
   same modules.
 
 .. _rpass:


Index: polly/docs/ReleaseNotes.rst
===
--- polly/docs/ReleaseNotes.rst
+++ polly/docs/ReleaseNotes.rst
@@ -6,7 +6,7 @@
 
 .. warning::
 
-  These release notes are for the next release of Polly and it describes
+  These release notes are for the next release of Polly and describe
   the new features that have recently been committed to our development
   branch.
 
Index: libcxx/docs/UsingLibcxx.rst
===
--- libcxx/docs/UsingLibcxx.rst
+++ libcxx/docs/UsingLibcxx.rst
@@ -114,10 +114,10 @@
 GCC does not provide a way to switch from libstdc++ to libc++. You must manually
 configure the compile and link commands.
 
-In particular you must tell GCC to remove the libstdc++ include directories
+In particular, you must tell GCC to remove the libstdc++ include directories
 using ``-nostdinc++`` and to not link libstdc++.so using ``-nodefaultlibs``.
 
-Note that ``-nodefaultlibs`` removes all of the standard system libraries and
+Note that ``-nodefaultlibs`` removes all the standard system libraries and
 not just libstdc++ so they must be manually linked. For example:
 
 .. code-block:: bash
@@ -151,7 +151,7 @@
 
 **_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS**:
   This macro is used to enable -Wthread-safety annotations on libc++'s
-  ``std::mutex`` and ``std::lock_guard``. By default these annotations are
+  ``std::mutex`` and ``std::lock_guard``. By default, these annotations are
   disabled and must be manually enabled by the user.
 
 **_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS**:
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -686,7 +686,7 @@
 .. option:: -gen-reproducer
 
   Generates preprocessed source files, a reproducer script and if relevant, a
-  cache containing: built module pcm's and all headers needed to rebuilt the
+  cache containing: built module pcm's and all headers needed to rebuild the
   same modules.
 
 .. _rpass:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99299: Normalize interaction with boolean attributes

2021-04-17 Thread serge via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
serge-sans-paille marked an inline comment as done.
Closed by commit rGd6de1e1a7140: Normalize interaction with boolean attributes 
(authored by serge-sans-paille).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99299

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/include/llvm/IR/Attributes.h
  llvm/lib/Analysis/IVDescriptors.cpp
  llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
  llvm/lib/IR/AttributeImpl.h
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
  llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
  llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
  llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp
  llvm/lib/Target/ARM/ARMTargetMachine.cpp
  llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp
  llvm/lib/Target/M68k/M68kISelLowering.cpp
  llvm/lib/Target/Mips/MipsTargetMachine.cpp
  llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
  llvm/lib/Target/Sparc/SparcTargetMachine.cpp
  llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp
  llvm/lib/Target/TargetMachine.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Verifier/invalid-strbool-attr.ll

Index: llvm/test/Verifier/invalid-strbool-attr.ll
===
--- /dev/null
+++ llvm/test/Verifier/invalid-strbool-attr.ll
@@ -0,0 +1,9 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: invalid value for 'no-jump-tables' attribute: yes
+
+define void @func() #0 {
+  ret void
+}
+
+attributes #0 = { "no-jump-tables"="yes" }
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -5793,7 +5793,7 @@
   // Only build lookup table when we have a target that supports it or the
   // attribute is not set.
   if (!TTI.shouldBuildLookupTables() ||
-  (Fn->getFnAttribute("no-jump-tables").getValueAsString() == "true"))
+  (Fn->getFnAttribute("no-jump-tables").getValueAsBool()))
 return false;
 
   // FIXME: If the switch is too sparse for a lookup table, perhaps we could
Index: llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
===
--- llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
+++ llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
@@ -799,7 +799,7 @@
 AliasAnalysis *AA,
 OptimizationRemarkEmitter *ORE,
 DomTreeUpdater ) {
-  if (F.getFnAttribute("disable-tail-calls").getValueAsString() == "true")
+  if (F.getFnAttribute("disable-tail-calls").getValueAsBool())
 return false;
 
   bool MadeChange = false;
Index: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -5028,7 +5028,7 @@
   void visitCallBase(CallBase , IRBuilder<> ) override {
 bool IsSoftFloatABI = CB.getCalledFunction()
   ->getFnAttribute("use-soft-float")
-  .getValueAsString() == "true";
+  .getValueAsBool();
 unsigned GpOffset = SystemZGpOffset;
 unsigned FpOffset = SystemZFpOffset;
 unsigned VrIndex = 0;
Index: llvm/lib/Target/X86/X86TargetMachine.cpp
===
--- llvm/lib/Target/X86/X86TargetMachine.cpp
+++ llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -294,8 +294,7 @@
   // function before we can generate a subtarget. We also need to use
   // it as a key for the subtarget since that can be the only difference
   // between two functions.
-  bool SoftFloat =
-  F.getFnAttribute("use-soft-float").getValueAsString() == "true";
+  bool SoftFloat = F.getFnAttribute("use-soft-float").getValueAsBool();
   // If the soft float attribute is set on the function turn on the soft float
   // subtarget feature.
   if (SoftFloat)
Index: llvm/lib/Target/TargetMachine.cpp
===
--- llvm/lib/Target/TargetMachine.cpp
+++ llvm/lib/Target/TargetMachine.cpp
@@ -56,7 +56,7 @@
 void TargetMachine::resetTargetOptions(const 

[clang] d6de1e1 - Normalize interaction with boolean attributes

2021-04-17 Thread via cfe-commits

Author: Serge Guelton
Date: 2021-04-17T08:17:33+02:00
New Revision: d6de1e1a71406c75a4ea4d5a2fe84289f07ea3a1

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

LOG: Normalize interaction with boolean attributes

Such attributes can either be unset, or set to "true" or "false" (as string).
throughout the codebase, this led to inelegant checks ranging from

if (Fn->getFnAttribute("no-jump-tables").getValueAsString() == "true")

to

if (Fn->hasAttribute("no-jump-tables") && 
Fn->getFnAttribute("no-jump-tables").getValueAsString() == "true")

Introduce a getValueAsBool that normalize the check, with the following
behavior:

no attributes or attribute set to "false" => return false
attribute set to "true" => return true

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

Added: 
llvm/test/Verifier/invalid-strbool-attr.ll

Modified: 
clang/lib/CodeGen/CodeGenFunction.cpp
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/include/llvm/IR/Attributes.h
llvm/lib/Analysis/IVDescriptors.cpp
llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/lib/IR/AttributeImpl.h
llvm/lib/IR/Attributes.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp
llvm/lib/Target/ARM/ARMTargetMachine.cpp
llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp
llvm/lib/Target/M68k/M68kISelLowering.cpp
llvm/lib/Target/Mips/MipsTargetMachine.cpp
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
llvm/lib/Target/Sparc/SparcTargetMachine.cpp
llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp
llvm/lib/Target/TargetMachine.cpp
llvm/lib/Target/X86/X86TargetMachine.cpp
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index ca59dc4a2b61c..09d49c9aa0180 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -174,7 +174,7 @@ void 
CodeGenFunction::CGFPOptionsRAII::ConstructorHelper(FPOptions FPFeatures) {
 
   auto mergeFnAttrValue = [&](StringRef Name, bool Value) {
 auto OldValue =
-CGF.CurFn->getFnAttribute(Name).getValueAsString() == "true";
+CGF.CurFn->getFnAttribute(Name).getValueAsBool();
 auto NewValue = OldValue & Value;
 if (OldValue != NewValue)
   CGF.CurFn->addFnAttr(Name, llvm::toStringRef(NewValue));

diff  --git a/llvm/include/llvm/CodeGen/TargetLowering.h 
b/llvm/include/llvm/CodeGen/TargetLowering.h
index 4b964dc262189..7c7778728f48b 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -1144,7 +1144,7 @@ class TargetLoweringBase {
 
   /// Return true if lowering to a jump table is allowed.
   virtual bool areJTsAllowed(const Function *Fn) const {
-if (Fn->getFnAttribute("no-jump-tables").getValueAsString() == "true")
+if (Fn->getFnAttribute("no-jump-tables").getValueAsBool())
   return false;
 
 return isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) ||

diff  --git a/llvm/include/llvm/IR/Attributes.h 
b/llvm/include/llvm/IR/Attributes.h
index 8a87a56099e27..50047e25f69d2 100644
--- a/llvm/include/llvm/IR/Attributes.h
+++ b/llvm/include/llvm/IR/Attributes.h
@@ -168,6 +168,10 @@ class Attribute {
   /// attribute be an integer attribute.
   uint64_t getValueAsInt() const;
 
+  /// Return the attribute's value as a boolean. This requires that the
+  /// attribute be a string attribute.
+  bool getValueAsBool() const;
+
   /// Return the attribute's kind as a string. This requires the
   /// attribute to be a string attribute.
   StringRef getKindAsString() const;

diff  --git a/llvm/lib/Analysis/IVDescriptors.cpp 
b/llvm/lib/Analysis/IVDescriptors.cpp
index 3427150288b86..945d0d30685e7 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -653,9 +653,9 @@ bool RecurrenceDescriptor::isReductionPHI(PHINode *Phi, 
Loop *TheLoop,
   Function  = *Header->getParent();
   FastMathFlags FMF;
   FMF.setNoNaNs(
-  F.getFnAttribute("no-nans-fp-math").getValueAsString() == "true");
+  F.getFnAttribute("no-nans-fp-math").getValueAsBool());
   FMF.setNoSignedZeros(
-  F.getFnAttribute("no-signed-zeros-fp-math").getValueAsString() == 
"true");
+  F.getFnAttribute("no-signed-zeros-fp-math").getValueAsBool());
 
   if (AddReductionVar(Phi, RecurKind::Add, TheLoop,