[PATCH] D146490: [Support] On Windows, ensure that UniqueID is really stable

2023-04-28 Thread Faisal Al-Humaimidi via Phabricator via cfe-commits
falhumai96 added a comment.

Hello devs,

I would like to follow up on this issue whether or not there has been an update 
on it.

Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146490

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


[PATCH] D148457: [clangd] Support macro evaluation on hover

2023-04-28 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added a comment.

Haha. My bad for misunderstanding.

> I think rather if the common ancestor isn't completely selected, evaluation 
> shouldn't happen.

I don't think it is a feasible approach to simply opt out of partial selection. 
Please consider this snippet:

  #define SizeOf sizeof
  void check() {
Siz^eOf(int);
  }

And associative selection tree:

  Built selection tree
   TranslationUnitDecl 
 FunctionDecl void check()
   CompoundStmt { …
.UnaryExprOrTypeTraitExpr sizeof(int)  # Partial selected. Exclude it?

Obviously we're expecting evaluation on such macro (which is just what the 
original issue addresses). And it's worth noting that if we define the macro a 
whole expression e.g., `sizeof(int)`, rather than a token `sizeof`, the common 
ancestor will be seen as completely selected.

OTOH, it doesn't seem so trivial to me to tell if an expression or token is 
appropriate (or to say, full enough?) to evaluate. Take Nathan's case for 
example. The macros `#define PLUS_TWO +2` and the `#define PLUS_TWO 2` are both 
transformed into the same AST. The mapped selection tree is,

  .BinaryOperator 40 + 2
 *IntegerLiteral 2  # For either '40 PLU^S_TWO' or '40 + PLU^S_TWO'

...or even more extreme,

  #define PLUS_TWO +2
  40 + PL^US_TWO;  // it should be seen as '+2', right?

As of now I didn't come up with a better idea to split the cases. Any 
suggestion? :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148457

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


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-04-28 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 518118.
chaitanyav added a comment.

Rebase with upstream


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto deterministic_v = deterministic();
   

[PATCH] D149389: [clang] Fix default initializers being ignored when initializing templated aggregate types

2023-04-28 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149389

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


[PATCH] D148639: [NFC][clang] Fix static analyzer concerns about AUTO_CAUSES_COPY

2023-04-28 Thread Soumi Manna via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe52a8b89adda: [NFC][clang] Fix static analyzer concerns 
about AUTO_CAUSES_COPY (authored by Manna).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148639

Files:
  clang/lib/AST/ODRHash.cpp
  clang/lib/Basic/TargetID.cpp
  clang/lib/Tooling/Syntax/Tokens.cpp


Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -986,7 +986,7 @@
   OS << "\n";
 
   std::vector Keys;
-  for (auto F : Files)
+  for (const auto  : Files)
 Keys.push_back(F.first);
   llvm::sort(Keys);
 
Index: clang/lib/Basic/TargetID.cpp
===
--- clang/lib/Basic/TargetID.cpp
+++ clang/lib/Basic/TargetID.cpp
@@ -133,7 +133,7 @@
   std::map OrderedMap;
   for (const auto  : Features)
 OrderedMap[F.first()] = F.second;
-  for (auto F : OrderedMap)
+  for (const auto  : OrderedMap)
 TargetID = TargetID + ':' + F.first.str() + (F.second ? "+" : "-");
   return TargetID;
 }
Index: clang/lib/AST/ODRHash.cpp
===
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -594,7 +594,7 @@
 
   ID.AddInteger(Record->getNumBases());
   auto Bases = Record->bases();
-  for (auto Base : Bases) {
+  for (const auto  : Bases) {
 AddQualType(Base.getType());
 ID.AddInteger(Base.isVirtual());
 ID.AddInteger(Base.getAccessSpecifierAsWritten());


Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -986,7 +986,7 @@
   OS << "\n";
 
   std::vector Keys;
-  for (auto F : Files)
+  for (const auto  : Files)
 Keys.push_back(F.first);
   llvm::sort(Keys);
 
Index: clang/lib/Basic/TargetID.cpp
===
--- clang/lib/Basic/TargetID.cpp
+++ clang/lib/Basic/TargetID.cpp
@@ -133,7 +133,7 @@
   std::map OrderedMap;
   for (const auto  : Features)
 OrderedMap[F.first()] = F.second;
-  for (auto F : OrderedMap)
+  for (const auto  : OrderedMap)
 TargetID = TargetID + ':' + F.first.str() + (F.second ? "+" : "-");
   return TargetID;
 }
Index: clang/lib/AST/ODRHash.cpp
===
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -594,7 +594,7 @@
 
   ID.AddInteger(Record->getNumBases());
   auto Bases = Record->bases();
-  for (auto Base : Bases) {
+  for (const auto  : Bases) {
 AddQualType(Base.getType());
 ID.AddInteger(Base.isVirtual());
 ID.AddInteger(Base.getAccessSpecifierAsWritten());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e52a8b8 - [NFC][clang] Fix static analyzer concerns about AUTO_CAUSES_COPY

2023-04-28 Thread via cfe-commits

Author: Manna, Soumi
Date: 2023-04-28T18:58:55-07:00
New Revision: e52a8b89addaec496fd726a3a90bcf82d42065c9

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

LOG: [NFC][clang] Fix static analyzer concerns about AUTO_CAUSES_COPY

Reported by Coverity:

AUTO_CAUSES_COPY
Unnecessary object copies can affect performance

1. Inside "ODRHash.cpp" file, in 
clang::ODRHash::AddCXXRecordDecl(clang::CXXRecordDecl const *): Using the auto 
keyword without an & causes the copy of an object of type CXXBaseSpecifier.

2. Inside "Tokens.cpp" file, in 
clang::syntax::TokenBuffer::dumpForTests[abi:cxx11](): Using the auto keyword 
without an & causes the copy of an object of type DenseMapPair.

3. Inside "TargetID.cpp" file, in 
clang::getCanonicalTargetID[abi:cxx11](llvm::StringRef, llvm::StringMap const &): Using the auto keyword without an & causes the 
copy of an object of type pair.

Reviewed By: tahonermann, aaron.ballman

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

Added: 


Modified: 
clang/lib/AST/ODRHash.cpp
clang/lib/Basic/TargetID.cpp
clang/lib/Tooling/Syntax/Tokens.cpp

Removed: 




diff  --git a/clang/lib/AST/ODRHash.cpp b/clang/lib/AST/ODRHash.cpp
index 3374b49f5d8e2..0ead0940479d8 100644
--- a/clang/lib/AST/ODRHash.cpp
+++ b/clang/lib/AST/ODRHash.cpp
@@ -594,7 +594,7 @@ void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) 
{
 
   ID.AddInteger(Record->getNumBases());
   auto Bases = Record->bases();
-  for (auto Base : Bases) {
+  for (const auto  : Bases) {
 AddQualType(Base.getType());
 ID.AddInteger(Base.isVirtual());
 ID.AddInteger(Base.getAccessSpecifierAsWritten());

diff  --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp
index 5d5708d274a09..3c06d9bad1dc0 100644
--- a/clang/lib/Basic/TargetID.cpp
+++ b/clang/lib/Basic/TargetID.cpp
@@ -133,7 +133,7 @@ std::string getCanonicalTargetID(llvm::StringRef Processor,
   std::map OrderedMap;
   for (const auto  : Features)
 OrderedMap[F.first()] = F.second;
-  for (auto F : OrderedMap)
+  for (const auto  : OrderedMap)
 TargetID = TargetID + ':' + F.first.str() + (F.second ? "+" : "-");
   return TargetID;
 }

diff  --git a/clang/lib/Tooling/Syntax/Tokens.cpp 
b/clang/lib/Tooling/Syntax/Tokens.cpp
index b13dc9ef4aeed..64e6eee6b62f2 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -986,7 +986,7 @@ std::string TokenBuffer::dumpForTests() const {
   OS << "\n";
 
   std::vector Keys;
-  for (auto F : Files)
+  for (const auto  : Files)
 Keys.push_back(F.first);
   llvm::sort(Keys);
 



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


[PATCH] D149389: [clang] Fix default initializers being ignored when initializing templated aggregate types

2023-04-28 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

In D149389#4306605 , @ayzhao wrote:

> In D149389#4303966 , @shafik wrote:
>
>> So the change makes sense but the original issue: 
>> https://github.com/llvm/llvm-project/issues/62266 it worked for the first 
>> once but not the second, it also worked for the non-paren aggregate init. So 
>> I feel like the explanation is missing some details.
>
> Patch description has been updated with an explanation.
>
>> It seems like the codegen test should be mimicing the test from the bug 
>> report more closely w/ two paren inits.
>
> The bug was that Clang wasn't calling the default-member intializer in the 
> first initializer, which the CodeGen test asserts. The second initializer is 
> irrelevant - it's only function is to provide the expected value of the 
> initialized field. In fact, changing the test assertion to be the same as 
> that in the bug report (asserting that the values of the fields in the two 
> objects are equal) is worse because that test would pass if we 
> value-initialize the fields instead of calling the default initialization 
> expression for both objects.

Apologies, I was not alluding to the comparing of the results of the two 
initializations but ensuring that it does the right thing for not just the 
first but also the second. So we did not change the bug in some strange way 
where the first now succeeds but now the second fails.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149389

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


[PATCH] D149504: [clang][CodeGenPGO] Don't use an invalid index when region counts disagree

2023-04-28 Thread Nathan Lanza via Phabricator via cfe-commits
lanza added a comment.

Actually, this still is consumed even without that flag being passed. Anybody 
know the rational for not having at least an llvm major version check here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149504

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


[PATCH] D148274: [clang] Fix overly aggressive lifetime checks for parenthesized aggregate initialization

2023-04-28 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148274

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


[PATCH] D149504: [clang][CodeGenPGO] Don't use an invalid index when region counts disagree

2023-04-28 Thread Nathan Lanza via Phabricator via cfe-commits
lanza created this revision.
lanza added a reviewer: bruno.
Herald added subscribers: wlei, wenlei, arphaman.
Herald added a project: All.
lanza requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If we're using an old instrprof profile and the user passes
`-Wno-profile-instr-out-of-date` then we can get Decls with children
decl counts not matching the what the profile was written against. In
a particular case I was debugging we have 24 decls in the AST and 22
decls in the profile.

There probably isn't a "right" thing to do other than override the users
wish to force using the profiles, but that't the point of that flag in
the first place.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149504

Files:
  clang/lib/CodeGen/CodeGenPGO.h


Index: clang/lib/CodeGen/CodeGenPGO.h
===
--- clang/lib/CodeGen/CodeGenPGO.h
+++ clang/lib/CodeGen/CodeGenPGO.h
@@ -114,7 +114,10 @@
   return 0;
 if (!haveRegionCounts())
   return 0;
-return RegionCounts[(*RegionCounterMap)[S]];
+auto Index = (*RegionCounterMap)[S];
+if (Index >= RegionCounts.size())
+  return 0;
+return RegionCounts[Index];
   }
 };
 


Index: clang/lib/CodeGen/CodeGenPGO.h
===
--- clang/lib/CodeGen/CodeGenPGO.h
+++ clang/lib/CodeGen/CodeGenPGO.h
@@ -114,7 +114,10 @@
   return 0;
 if (!haveRegionCounts())
   return 0;
-return RegionCounts[(*RegionCounterMap)[S]];
+auto Index = (*RegionCounterMap)[S];
+if (Index >= RegionCounts.size())
+  return 0;
+return RegionCounts[Index];
   }
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148381: [WIP][Clang] Add element_count attribute

2023-04-28 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 518106.
void added a comment.

Change sanitizer scope because instructions may be created.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ASTImporter.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test

Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -61,6 +61,7 @@
 // CHECK-NEXT: DiagnoseAsBuiltin (SubjectMatchRule_function)
 // CHECK-NEXT: DisableSanitizerInstrumentation (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: DisableTailCalls (SubjectMatchRule_function, SubjectMatchRule_objc_method)
+// CHECK-NEXT: ElementCount (SubjectMatchRule_field)
 // CHECK-NEXT: EnableIf (SubjectMatchRule_function)
 // CHECK-NEXT: EnforceTCB (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: EnforceTCBLeaf (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8238,6 +8238,29 @@
   D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL));
 }
 
+static void handleElementCountAttr(Sema , Decl *D, const ParsedAttr ) {
+  // TODO: Probably needs more processing here. See Sema::AddAlignValueAttr.
+  SmallVector Names;
+  SmallVector Ranges;
+  for (unsigned ArgNo = 0; ArgNo < getNumAttributeArgs(AL); ++ArgNo) {
+if (!AL.isArgIdent(ArgNo)) {
+  S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+  << AL << AANT_ArgumentIdentifier;
+  return;
+}
+
+IdentifierLoc *IL = AL.getArgAsIdent(ArgNo);
+Names.push_back(IL->Ident);
+Ranges.push_back(IL->Loc);
+  }
+
+  ElementCountAttr *ECA = ::new (S.Context) ElementCountAttr(S.Context, AL,
+ Names.data(),
+ Names.size());
+  ECA->addCountFieldSourceRange(Ranges);
+  D->addAttr(ECA);
+}
+
 static void handleFunctionReturnThunksAttr(Sema , Decl *D,
const ParsedAttr ) {
   StringRef KindStr;
@@ -9136,6 +9159,9 @@
   case ParsedAttr::AT_FunctionReturnThunks:
 handleFunctionReturnThunksAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_ElementCount:
+handleElementCountAttr(S, D, AL);
+break;
 
   // Microsoft attributes:
   case ParsedAttr::AT_LayoutVersion:
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -17692,6 +17692,43 @@
  "Broken injected-class-name");
 }
 
+static const FieldDecl *FindFieldWithElementCountAttr(const RecordDecl *RD) {
+  for (const Decl *D : RD->decls()) {
+if (const auto *FD = dyn_cast(D))
+  if (FD->hasAttr())
+return FD;
+
+if (const auto *SubRD = dyn_cast(D))
+  if (const FieldDecl *FD = FindFieldWithElementCountAttr(SubRD))
+return FD;
+  }
+
+  return nullptr;
+}
+
+static bool CheckElementCountAttr(const RecordDecl *RD, const FieldDecl *FD,
+  SourceRange ) {
+  const ElementCountAttr *ECA = FD->getAttr();
+  unsigned Idx = 0;
+
+  for (const IdentifierInfo *II : ECA->elementCountFields()) {
+Loc = ECA->getCountFieldSourceRange(Idx++);
+
+auto DeclIter = llvm::find_if(
+RD->fields(), [&](const FieldDecl *FD){
+  return II->getName() == FD->getName();
+});
+
+if (DeclIter == RD->field_end())
+  return false;
+
+if (auto *SubRD = DeclIter->getType()->getAsRecordDecl())
+  RD = SubRD;
+  }
+
+  return true;
+}
+
 void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD,
 SourceRange BraceRange) {
   AdjustDeclIfTemplate(TagD);
@@ -17749,6 +17786,17 @@
  [](const FieldDecl *FD) { return FD->isBitField(); }))
   Diag(BraceRange.getBegin(), diag::warn_pragma_align_not_xl_compatible);
   }
+
+  // Check the "element_count" attribute to ensure that the count field exists
+  // in the struct.
+  if (const RecordDecl *RD = dyn_cast(Tag)) {
+if (const FieldDecl *FD = FindFieldWithElementCountAttr(RD)) {
+  SourceRange SR;
+  if (!CheckElementCountAttr(RD, FD, SR))
+Diag(SR.getBegin(), diag::warn_element_count_placeholder)
+<< FD->getName() << SR;
+

[PATCH] D149498: [RISCV] Add Scheduling information for Zfh to SiFive7 model

2023-04-28 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149498

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


[PATCH] D149497: [RISCV] Add scheduling information for Zba and Zbb to RISCVSchedSiFive7.td

2023-04-28 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149497

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


[PATCH] D149498: [RISCV] Add Scheduling information for Zfh to SiFive7 model

2023-04-28 Thread Michael Maitland via Phabricator via cfe-commits
michaelmaitland added inline comments.



Comment at: clang/test/Driver/riscv-cpus.c:176
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+zicsr" "-target-feature" 
"+zifencei"
+// MCPU-SIFIVE-X280-SAME: "-target-feature" "+zfh"
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+zba" "-target-feature" "+zbb"

craig.topper wrote:
> This means the patch is dependent on the patch that adds sifive-x280?
> This means the patch is dependent on the patch that adds sifive-x280?

Added parent revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149498

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


[PATCH] D149497: [RISCV] Add scheduling information for Zba and Zbb to RISCVSchedSiFive7.td

2023-04-28 Thread Michael Maitland via Phabricator via cfe-commits
michaelmaitland marked an inline comment as done.
michaelmaitland added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVProcessors.td:181
+   FeatureStdExtZvfh,
+   FeatureStdExtZba,
+   FeatureStdExtZbb],

craig.topper wrote:
> This makes the patch dependent on adding sifive-x280
Added parent revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149497

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


[PATCH] D149497: [RISCV] Add scheduling information for Zba and Zbb to RISCVSchedSiFive7.td

2023-04-28 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVProcessors.td:181
+   FeatureStdExtZvfh,
+   FeatureStdExtZba,
+   FeatureStdExtZbb],

This makes the patch dependent on adding sifive-x280


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149497

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


[PATCH] D149498: [RISCV] Add Scheduling information for Zfh to SiFive7 model

2023-04-28 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/test/Driver/riscv-cpus.c:176
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+zicsr" "-target-feature" 
"+zifencei"
+// MCPU-SIFIVE-X280-SAME: "-target-feature" "+zfh"
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+zba" "-target-feature" "+zbb"

This means the patch is dependent on the patch that adds sifive-x280?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149498

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


[PATCH] D147847: [clangd] Hover: Add CalleeArgInfo for constructor expressions

2023-04-28 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147847

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


[PATCH] D149498: [RISCV] Add Scheduling information for Zfh to SiFive7 model

2023-04-28 Thread Michael Maitland via Phabricator via cfe-commits
michaelmaitland updated this revision to Diff 518089.
michaelmaitland added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add zfh to `clang/test/Driver/riscv-cpus.c`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149498

Files:
  clang/test/Driver/riscv-cpus.c
  llvm/lib/Target/RISCV/RISCVSchedSiFive7.td

Index: llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
===
--- llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
+++ llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
@@ -239,6 +239,7 @@
 def : WriteRes;
 def : WriteRes;
 def : WriteRes;
+def : WriteRes;
 def : WriteRes;
 def : WriteRes;
 
@@ -250,6 +251,7 @@
 }
 
 let Latency = 2 in {
+def : WriteRes;
 def : WriteRes;
 def : WriteRes;
 }
@@ -265,6 +267,22 @@
 def : WriteRes;
 }
 
+// Half precision.
+let Latency = 5 in {
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+}
+let Latency = 3 in {
+def : WriteRes;
+def : WriteRes;
+}
+
+let Latency = 14, ResourceCycles = [1, 13] in {
+def :  WriteRes;
+def :  WriteRes;
+}
+
 // Single precision.
 let Latency = 5 in {
 def : WriteRes;
@@ -299,21 +317,33 @@
 
 // Conversions
 let Latency = 3 in {
+def : WriteRes;
 def : WriteRes;
 def : WriteRes;
+def : WriteRes;
 def : WriteRes;
 def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
 def : WriteRes;
 def : WriteRes;
+def : WriteRes;
 def : WriteRes;
 def : WriteRes;
 def : WriteRes;
+def : WriteRes;
 def : WriteRes;
 
+def : WriteRes;
 def : WriteRes;
 def : WriteRes;
+def : WriteRes;
 def : WriteRes;
 def : WriteRes;
+def : WriteRes;
+def : WriteRes;
 def : WriteRes;
 def : WriteRes;
 def : WriteRes;
@@ -690,36 +720,55 @@
 def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
+def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
+def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
+def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
+def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
+def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
+def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
+def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
+def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
+def : ReadAdvance;
 def : ReadAdvance;
 def : ReadAdvance;
 
@@ -911,5 +960,4 @@
 defm : UnsupportedSchedZbkb;
 defm : UnsupportedSchedZbkx;
 defm : UnsupportedSchedZfa;
-defm : UnsupportedSchedZfh;
 }
Index: clang/test/Driver/riscv-cpus.c
===
--- clang/test/Driver/riscv-cpus.c
+++ clang/test/Driver/riscv-cpus.c
@@ -173,6 +173,7 @@
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d"
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+c" "-target-feature" "+v"
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+zicsr" "-target-feature" "+zifencei"
+// MCPU-SIFIVE-X280-SAME: "-target-feature" "+zfh"
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+zba" "-target-feature" "+zbb"
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+experimental-zvfh"
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+zvl128b"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149495: [RISCV] Add sifive-x280 processor and support V extenstion in SiFive7

2023-04-28 Thread Michael Maitland via Phabricator via cfe-commits
michaelmaitland updated this revision to Diff 518086.
michaelmaitland added a comment.

Remove zfh from x280 check in `clang/test/Driver/riscv-cpus.c`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149495

Files:
  clang/test/Driver/riscv-cpus.c
  llvm/lib/Target/RISCV/RISCVProcessors.td
  llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
  llvm/lib/Target/RISCV/RISCVScheduleV.td

Index: llvm/lib/Target/RISCV/RISCVScheduleV.td
===
--- llvm/lib/Target/RISCV/RISCVScheduleV.td
+++ llvm/lib/Target/RISCV/RISCVScheduleV.td
@@ -9,7 +9,7 @@
 //===--===//
 /// Define scheduler resources associated with def operands.
 
-defvar SchedMxList = ["M1", "M2", "M4", "M8", "MF2", "MF4", "MF8"];
+defvar SchedMxList = ["MF8", "MF4", "MF2", "M1", "M2", "M4", "M8"];
 // Used for widening and narrowing instructions as it doesn't contain M8.
 defvar SchedMxListW = !listremove(SchedMxList, ["M8"]);
 defvar SchedMxListFW = !listremove(SchedMxList, ["M8", "MF8"]);
@@ -38,6 +38,32 @@
 !eq(mx, "MF4"): [16]);
 }
 
+// Helper function to get the largest LMUL from MxList
+// Precondition: MxList is sorted in ascending LMUL order.
+class LargestLMUL MxList> {
+  // MX list is sorted from smallest to largest
+  string r = !foldl(!head(MxList), MxList, last, curr, curr);
+}
+// Helper function to get the smallest SEW that can be used with LMUL mx
+// Precondition: MxList is sorted in ascending LMUL order and SchedSEWSet
+class SmallestSEW {
+  int r = !head(!if(isF, SchedSEWSetF.val, SchedSEWSet.val));
+}
+
+// Creates WriteRes for (name, mx, resources) tuple
+multiclass LMULWriteResMX resources,
+  string mx, bit IsWorstCase> {
+  def : WriteRes(name # "_" # mx), resources>;
+  if IsWorstCase then
+def : WriteRes(name # "_WorstCase"), resources>;
+}
+multiclass LMULSEWWriteResMXSEW resources,
+ string mx, int sew,  bit IsWorstCase> {
+  def : WriteRes(name # "_" # mx # "_E" # sew), resources>;
+  if IsWorstCase then
+def : WriteRes(name # "_WorstCase"), resources>;
+}
+
 // Define multiclasses to define SchedWrite, SchedRead,  WriteRes, and
 // ReadAdvance for each (name, LMUL) pair and for each LMUL in each of the
 // SchedMxList variants above. Each multiclass is responsible for defining
Index: llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
===
--- llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
+++ llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
@@ -8,6 +8,131 @@
 
 //===--===//
 
+/// c is true if mx has the worst case behavior compared to LMULs in MxList.
+/// On the SiFive7, the worst case LMUL is the Largest LMUL
+/// and the worst case sew is the smallest SEW for that LMUL.
+class SiFive7IsWorstCaseMX MxList> {
+  string LLMUL = LargestLMUL.r;
+  bit c = !eq(mx, LLMUL);
+}
+
+/// c is true if mx and sew have the worst case behavior compared to LMULs in
+/// MxList. On the SiFive7, the worst case LMUL is the Largest LMUL
+/// and the worst case sew is the smallest SEW for that LMUL.
+class SiFive7IsWorstCaseMXSEW MxList,
+   bit isF = 0> {
+  string LLMUL = LargestLMUL.r;
+  int SSEW = SmallestSEW.r;
+  bit c = !and(!eq(mx, LLMUL), !eq(sew, SSEW));
+}
+
+class SiFive7GetCyclesDefault {
+  int c = !cond(
+!eq(mx, "M1") : 2,
+!eq(mx, "M2") : 4,
+!eq(mx, "M4") : 8,
+!eq(mx, "M8") : 16,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesWidening {
+  int c = !cond(
+!eq(mx, "M1") : 2,
+!eq(mx, "M2") : 4,
+!eq(mx, "M4") : 8,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesNarrowing {
+  int c = !cond(
+!eq(mx, "M1") : 4,
+!eq(mx, "M2") : 8,
+!eq(mx, "M4") : 16,
+!eq(mx, "MF2") : 2,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesOutputLMUL {
+  int c = !cond(
+!eq(mx, "M1") : 1,
+!eq(mx, "M2") : 2,
+!eq(mx, "M4") : 4,
+!eq(mx, "M8") : 8,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesVMask {
+  int c = !cond(
+!eq(mx, "M1") : 1,
+!eq(mx, "M2") : 1,
+!eq(mx, "M4") : 1,
+!eq(mx, "M8") : 2,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+// Cycles for segmented loads and stores are calculated using the
+// formula ceil(2 * nf * lmul).
+class SiFive7GetCyclesSegmented {
+  int c = !cond(
+!eq(mx, "M1") : !mul(!mul(2, nf), 1),
+!eq(mx, "M2") : !mul(!mul(2, nf), 2),
+!eq(mx, "M4") : !mul(!mul(2, nf), 4),
+!eq(mx, "M8") : !mul(!mul(2, nf), 8),
+// We can calculate 

[PATCH] D149497: [RISCV] Add scheduling information for Zba and Zbb to RISCVSchedSiFive7.td

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

Based on the following description from Andrew W.

- Instructions not mentioned here behave the same as integer ALU ops
- rev8 only executes in the late-A and late-B ALUs
- shNadd[.uw] only execute on the early-B and late-B ALUs
- clz[w], ctz[w], and orc.b and all rotates only execute in the late-B ALU
- pcnt[w] looks exactly like integer multiply

This patch does not account for early/late ALU in the model. It is coded based
on the pipes only.

Co-Authored-By: topperc 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149497

Files:
  clang/test/Driver/riscv-cpus.c
  llvm/lib/Target/RISCV/RISCVProcessors.td
  llvm/lib/Target/RISCV/RISCVSchedSiFive7.td


Index: llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
===
--- llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
+++ llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
@@ -205,6 +205,35 @@
   let ResourceCycles = [1, 15];
 }
 
+// Bitmanip
+let Latency = 3 in {
+// Rotates are in the late-B ALU.
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+
+// clz[w]/ctz[w] are in the late-B ALU.
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+
+// cpop[w] look exactly like multiply.
+def : WriteRes;
+def : WriteRes;
+
+// orc.b is in the late-B ALU.
+def : WriteRes;
+
+// rev8 is in the late-A and late-B ALUs.
+def : WriteRes;
+
+// shNadd[.uw] is on the early-B and late-B ALUs.
+def : WriteRes;
+def : WriteRes;
+}
+
 // Memory
 def : WriteRes;
 def : WriteRes;
@@ -859,10 +888,24 @@
 // Others
 def : ReadAdvance;
 
+// Bitmanip
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+
 
//===--===//
 // Unsupported extensions
-defm : UnsupportedSchedZba;
-defm : UnsupportedSchedZbb;
 defm : UnsupportedSchedZbc;
 defm : UnsupportedSchedZbs;
 defm : UnsupportedSchedZbkb;
Index: llvm/lib/Target/RISCV/RISCVProcessors.td
===
--- llvm/lib/Target/RISCV/RISCVProcessors.td
+++ llvm/lib/Target/RISCV/RISCVProcessors.td
@@ -177,7 +177,9 @@
FeatureStdExtV,
FeatureStdExtZvl512b,
FeatureStdExtZfh,
-   FeatureStdExtZvfh],
+   FeatureStdExtZvfh,
+   FeatureStdExtZba,
+   FeatureStdExtZbb],
   [TuneSiFive7]>;
 
 def SYNTACORE_SCR1_BASE : RISCVProcessorModel<"syntacore-scr1-base",
Index: clang/test/Driver/riscv-cpus.c
===
--- clang/test/Driver/riscv-cpus.c
+++ clang/test/Driver/riscv-cpus.c
@@ -174,6 +174,7 @@
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+c" "-target-feature" "+v"
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+zicsr" "-target-feature" 
"+zifencei"
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+zfh"
+// MCPU-SIFIVE-X280-SAME: "-target-feature" "+zba" "-target-feature" "+zbb"
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+experimental-zvfh"
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+zvl128b"
 // MCPU-SIFIVE-X280-SAME: "-target-feature" "+zvl256b" "-target-feature" 
"+zvl32b"


Index: llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
===
--- llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
+++ llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
@@ -205,6 +205,35 @@
   let ResourceCycles = [1, 15];
 }
 
+// Bitmanip
+let Latency = 3 in {
+// Rotates are in the late-B ALU.
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+
+// clz[w]/ctz[w] are in the late-B ALU.
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+
+// cpop[w] look exactly like multiply.
+def : WriteRes;
+def : WriteRes;
+
+// orc.b is in the late-B ALU.
+def : WriteRes;
+
+// rev8 is in the late-A and late-B ALUs.
+def : WriteRes;
+
+// shNadd[.uw] is on the early-B and late-B ALUs.
+def : 

[PATCH] D149495: Add sifive-x280 processor and support V extenstion in SiFive7

2023-04-28 Thread Michael Maitland via Phabricator via cfe-commits
michaelmaitland created this revision.
michaelmaitland added reviewers: craig.topper, kito-cheng, reames, pcwang-thead.
Herald added subscribers: luke, frasercrmck, luismarques, apazos, 
sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, 
MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, 
simoncook, johnrusso, rbar, asb, hiraditya, arichardson.
Herald added a project: All.
michaelmaitland requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

Add x280 processor that uses SiFive7 with vector extension.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149495

Files:
  clang/test/Driver/riscv-cpus.c
  llvm/lib/Target/RISCV/RISCVProcessors.td
  llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
  llvm/lib/Target/RISCV/RISCVScheduleV.td

Index: llvm/lib/Target/RISCV/RISCVScheduleV.td
===
--- llvm/lib/Target/RISCV/RISCVScheduleV.td
+++ llvm/lib/Target/RISCV/RISCVScheduleV.td
@@ -9,7 +9,7 @@
 //===--===//
 /// Define scheduler resources associated with def operands.
 
-defvar SchedMxList = ["M1", "M2", "M4", "M8", "MF2", "MF4", "MF8"];
+defvar SchedMxList = ["MF8", "MF4", "MF2", "M1", "M2", "M4", "M8"];
 // Used for widening and narrowing instructions as it doesn't contain M8.
 defvar SchedMxListW = !listremove(SchedMxList, ["M8"]);
 defvar SchedMxListFW = !listremove(SchedMxList, ["M8", "MF8"]);
@@ -38,6 +38,32 @@
 !eq(mx, "MF4"): [16]);
 }
 
+// Helper function to get the largest LMUL from MxList
+// Precondition: MxList is sorted in ascending LMUL order.
+class LargestLMUL MxList> {
+  // MX list is sorted from smallest to largest
+  string r = !foldl(!head(MxList), MxList, last, curr, curr);
+}
+// Helper function to get the smallest SEW that can be used with LMUL mx
+// Precondition: MxList is sorted in ascending LMUL order and SchedSEWSet
+class SmallestSEW {
+  int r = !head(!if(isF, SchedSEWSetF.val, SchedSEWSet.val));
+}
+
+// Creates WriteRes for (name, mx, resources) tuple
+multiclass LMULWriteResMX resources,
+  string mx, bit IsWorstCase> {
+  def : WriteRes(name # "_" # mx), resources>;
+  if IsWorstCase then
+def : WriteRes(name # "_WorstCase"), resources>;
+}
+multiclass LMULSEWWriteResMXSEW resources,
+ string mx, int sew,  bit IsWorstCase> {
+  def : WriteRes(name # "_" # mx # "_E" # sew), resources>;
+  if IsWorstCase then
+def : WriteRes(name # "_WorstCase"), resources>;
+}
+
 // Define multiclasses to define SchedWrite, SchedRead,  WriteRes, and
 // ReadAdvance for each (name, LMUL) pair and for each LMUL in each of the
 // SchedMxList variants above. Each multiclass is responsible for defining
Index: llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
===
--- llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
+++ llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
@@ -8,6 +8,131 @@
 
 //===--===//
 
+/// c is true if mx has the worst case behavior compared to LMULs in MxList.
+/// On the SiFive7, the worst case LMUL is the Largest LMUL
+/// and the worst case sew is the smallest SEW for that LMUL.
+class SiFive7IsWorstCaseMX MxList> {
+  string LLMUL = LargestLMUL.r;
+  bit c = !eq(mx, LLMUL);
+}
+
+/// c is true if mx and sew have the worst case behavior compared to LMULs in
+/// MxList. On the SiFive7, the worst case LMUL is the Largest LMUL
+/// and the worst case sew is the smallest SEW for that LMUL.
+class SiFive7IsWorstCaseMXSEW MxList,
+   bit isF = 0> {
+  string LLMUL = LargestLMUL.r;
+  int SSEW = SmallestSEW.r;
+  bit c = !and(!eq(mx, LLMUL), !eq(sew, SSEW));
+}
+
+class SiFive7GetCyclesDefault {
+  int c = !cond(
+!eq(mx, "M1") : 2,
+!eq(mx, "M2") : 4,
+!eq(mx, "M4") : 8,
+!eq(mx, "M8") : 16,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesWidening {
+  int c = !cond(
+!eq(mx, "M1") : 2,
+!eq(mx, "M2") : 4,
+!eq(mx, "M4") : 8,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesNarrowing {
+  int c = !cond(
+!eq(mx, "M1") : 4,
+!eq(mx, "M2") : 8,
+!eq(mx, "M4") : 16,
+!eq(mx, "MF2") : 2,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesOutputLMUL {
+  int c = !cond(
+!eq(mx, "M1") : 1,
+!eq(mx, "M2") : 2,
+!eq(mx, "M4") : 4,
+!eq(mx, "M8") : 8,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesVMask {
+  int c = !cond(
+!eq(mx, "M1") : 1,
+!eq(mx, "M2") : 1,
+!eq(mx, "M4") : 1,
+!eq(mx, "M8") : 2,
+!eq(mx, "MF2") : 1,
+

[PATCH] D148601: [Clang] Handle Error message to output proper Prefix

2023-04-28 Thread Usman Akinyemi via Phabricator via cfe-commits
Unique_Usman added a comment.

In D148601#4301977 , @aaron.ballman 
wrote:

> Thank you for working on this! These changes should come with test coverage 
> (we have a handful of verifier tests in `clang/test/Frontend` -- you can add 
> a new test file there), but I don't think a release note is required because 
> this is a fix for internal functionality. The test should cover the simple 
> case of `-verify=something` as well as a more complex test with 
> `-verify=something, something_else`.

Hello, I have been going through the other verfiier test, so basicallhy the new 
test file will test if the error output generated by -verify=something and 
`-verify=something, something_else` is the expected output right?




Comment at: clang/include/clang/Basic/DiagnosticFrontendKinds.td:175-176
 def err_verify_invalid_no_diags : Error<
 "%select{expected|'expected-no-diagnostics'}0 directive cannot follow "
 "%select{'expected-no-diagnostics' directive|other expected directives}0">;
 def err_verify_no_directives : Error<

aaron.ballman wrote:
> Should we be handling this situation at the same time, as it's effectively 
> the same concern? e.g., https://godbolt.org/z/4Mn1rW9oa
Hello, do you meant if we should handle when value is passed to -verify and 
when it is not together?
 
I will say yes, the solution handle the situation whenever the value is passed 
to verify and at the same time was able to handle whenever value is not 
passed(it output the default which is 'expected-no-diagnostics',). 

Do you think otherwise? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148601

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


[PATCH] D149492: [clang] makes built-in traits match their stdlib counterparts' names

2023-04-28 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb created this revision.
cjdb added reviewers: rsmith, aaron.ballman.
Herald added a project: All.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The original names apparently broke convention by not making them the
same as the C++ type trait names, so we're creating aliases for them.
It's unclear whether or not the existing names can be deprecated and
removed in the future.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149492

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -1073,6 +1073,38 @@
   static_assert(!__is_nullptr(StructWithMembers), "");
   static_assert(!__is_nullptr(int StructWithMembers::*), "");
   static_assert(!__is_nullptr(void(StructWithMembers::*)()), "");
+
+  static_assert(__is_null_pointer(decltype(nullptr)), "");
+  static_assert(!__is_null_pointer(void *), "");
+  static_assert(!__is_null_pointer(cvoid *), "");
+  static_assert(!__is_null_pointer(cvoid *), "");
+  static_assert(!__is_null_pointer(char *), "");
+  static_assert(!__is_null_pointer(int *), "");
+  static_assert(!__is_null_pointer(int **), "");
+  static_assert(!__is_null_pointer(ClassType *), "");
+  static_assert(!__is_null_pointer(Derives *), "");
+  static_assert(!__is_null_pointer(Enum *), "");
+  static_assert(!__is_null_pointer(IntArNB *), "");
+  static_assert(!__is_null_pointer(Union *), "");
+  static_assert(!__is_null_pointer(UnionAr *), "");
+  static_assert(!__is_null_pointer(StructWithMembers *), "");
+  static_assert(!__is_null_pointer(void (*)()), "");
+
+  static_assert(!__is_null_pointer(void), "");
+  static_assert(!__is_null_pointer(cvoid), "");
+  static_assert(!__is_null_pointer(cvoid), "");
+  static_assert(!__is_null_pointer(char), "");
+  static_assert(!__is_null_pointer(int), "");
+  static_assert(!__is_null_pointer(int), "");
+  static_assert(!__is_null_pointer(ClassType), "");
+  static_assert(!__is_null_pointer(Derives), "");
+  static_assert(!__is_null_pointer(Enum), "");
+  static_assert(!__is_null_pointer(IntArNB), "");
+  static_assert(!__is_null_pointer(Union), "");
+  static_assert(!__is_null_pointer(UnionAr), "");
+  static_assert(!__is_null_pointer(StructWithMembers), "");
+  static_assert(!__is_null_pointer(int StructWithMembers::*), "");
+  static_assert(!__is_null_pointer(void(StructWithMembers::*)()), "");
 }
 
 void is_member_object_pointer()
@@ -3534,6 +3566,7 @@
 }
 
 template  using remove_reference_t = __remove_reference_t(T);
+template  using remove_reference = __remove_reference(T);
 
 void check_remove_reference() {
   static_assert(__is_same(remove_reference_t, void), "");
@@ -3568,6 +3601,39 @@
   static_assert(__is_same(remove_reference_t, int S::*const volatile), "");
   static_assert(__is_same(remove_reference_t, int(S::*const volatile)()), "");
   static_assert(__is_same(remove_reference_t, int(S::*const volatile)() &), "");
+
+  static_assert(__is_same(remove_reference, void), "");
+  static_assert(__is_same(remove_reference, const volatile void), "");
+  static_assert(__is_same(remove_reference, int), "");
+  static_assert(__is_same(remove_reference, const int), "");
+  static_assert(__is_same(remove_reference, volatile int), "");
+  static_assert(__is_same(remove_reference, const volatile int), "");
+  static_assert(__is_same(remove_reference, int *), "");
+  static_assert(__is_same(remove_reference, int *const volatile), "");
+  static_assert(__is_same(remove_reference, int const *const volatile), "");
+  static_assert(__is_same(remove_reference, int), "");
+  static_assert(__is_same(remove_reference, int const volatile), "");
+  static_assert(__is_same(remove_reference, int), "");
+  static_assert(__is_same(remove_reference, int const volatile), "");
+  static_assert(__is_same(remove_reference, int()), "");
+  static_assert(__is_same(remove_reference, int (*const volatile)()), "");
+  static_assert(__is_same(remove_reference, int()), "");
+
+  static_assert(__is_same(remove_reference, S), "");
+  static_assert(__is_same(remove_reference, S), "");
+  static_assert(__is_same(remove_reference, S), "");
+  static_assert(__is_same(remove_reference, const S), "");
+  static_assert(__is_same(remove_reference, const S), "");
+  static_assert(__is_same(remove_reference, const S), "");
+  static_assert(__is_same(remove_reference, volatile S), "");
+  static_assert(__is_same(remove_reference, volatile S), "");
+  static_assert(__is_same(remove_reference, volatile S), "");
+  static_assert(__is_same(remove_reference, const volatile S), "");
+  static_assert(__is_same(remove_reference, const volatile S), "");
+  static_assert(__is_same(remove_reference, const volatile S), "");
+  static_assert(__is_same(remove_reference, int S::*const volatile), "");
+  

[PATCH] D149389: [clang] Fix default initializers being ignored when initializing templated aggregate types

2023-04-28 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao added a comment.

In D149389#4303966 , @shafik wrote:

> So the change makes sense but the original issue: 
> https://github.com/llvm/llvm-project/issues/62266 it worked for the first 
> once but not the second, it also worked for the non-paren aggregate init. So 
> I feel like the explanation is missing some details.

Patch description has been updated with an explanation.

> It seems like the codegen test should be mimicing the test from the bug 
> report more closely w/ two paren inits.

The bug was that Clang wasn't calling the default-member intializer in the 
first initializer, which the CodeGen test asserts. The second initializer is 
irrelevant - it's only function is to provide the expected value of the 
initialized field. In fact, changing the test assertion to be the same as that 
in the bug report (asserting that the values of the fields in the two objects 
are equal) is worse because that test would pass if we value-initialize the 
fields instead of calling the default initialization expression for both 
objects.

In D149389#4304092 , @shafik wrote:

> Please also add a release note.

Done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149389

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


[PATCH] D146386: [MS ABI] Fix mangling references to declarations.

2023-04-28 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:1250
+  for (unsigned I = 1, IE = ID->getChainingSize(); I < IE; ++I)
+mangleSourceName("");
+

bolshakov-a wrote:
> bolshakov-a wrote:
> > efriedma wrote:
> > > bolshakov-a wrote:
> > > > efriedma wrote:
> > > > > bolshakov-a wrote:
> > > > > > efriedma wrote:
> > > > > > > Weird indentation
> > > > > > I agree. Don't know why clang-format does so. Should I put 
> > > > > > `clang-format off` here?
> > > > > If clang-format won't cooperate, you can probably make it figure out 
> > > > > what you're doing with something like
> > > > > 
> > > > >   if (const auto *ID = dyn_cast(ND)) {
> > > > > for (unsigned I = 1, IE = ID->getChainingSize(); I < IE; ++I)
> > > > >   mangleSourceName("");
> > > > >   }
> > > > It doesn't help. Moreover, clang-format corrupts formatting in this 
> > > > function even without my changes. You can check it by yourself.
> > > I just tried "clang-format -i" on the file with your patch, and it seems 
> > > to compute the correct indentation here.  This with a source tree and 
> > > clang-format binary from feb 28 because that's what I had handy... but I 
> > > don't think anything relevant has changed here?
> > Running clang-format on the whole file really seems to produce correct 
> > formatting... But it is a lot of unrelated changes. Running clang-format 
> > only on the `mangleNestedName` function (`--lines=1185:1287` without my 
> > changes, `--lines=1242:1349` with my changes) produces bad formatting.
> I could make a separate PR with formatting this file and fix this PR after 
> landing that one.
If `clang-format --lines` is broken, just fix the formatting by hand (and file 
a bug against clang-format).



Comment at: clang/lib/AST/MicrosoftMangle.cpp:1816
 
-  QualType T = Base.getType();
+  std::stack EntryTypeStack;
+  SmallVector, 2> EntryManglers;

bolshakov-a wrote:
> efriedma wrote:
> > Please just use SmallVector instead of std::stack.
> `std::stack` can be parameterized with container type (`std::stack SmallVector>`). Or it should not be used for some other reason?
Using std::stack as a wrapper around SmallVector is sort of pointless; you can 
just explicitly push_back/pop_back.


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

https://reviews.llvm.org/D146386

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


[PATCH] D149389: [clang] Fix default initializers being ignored when initializing templated aggregate types

2023-04-28 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 518054.
ayzhao added a comment.

rebase + add release notes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149389

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/CodeGen/paren-list-agg-init.cpp


Index: clang/test/CodeGen/paren-list-agg-init.cpp
===
--- clang/test/CodeGen/paren-list-agg-init.cpp
+++ clang/test/CodeGen/paren-list-agg-init.cpp
@@ -90,6 +90,15 @@
   };
 }
 
+namespace gh62266 {
+  // CHECK-DAG: [[STRUCT_H:%.*H.*]] = type { i32, i32 }
+  template 
+  struct H {
+int i;
+int j = J;
+  };
+}
+
 // CHECK-DAG: [[A1:@.*a1.*]] = internal constant [[STRUCT_A]] { i8 3, double 
2.00e+00 }, align 8
 constexpr A a1(3.1, 2.0);
 // CHECK-DAG: [[A2:@.*a2.*]] = internal constant [[STRUCT_A]] { i8 99, double 
0.00e+00 }, align 8
@@ -421,3 +430,17 @@
 make2<0>();
   }
 }
+
+namespace gh62266 {
+  // CHECK: define {{.*}} void {{.*foo20.*}}
+  // CHECK-NEXT: entry:
+  // CHECK-NEXT: [[H:%.*h.*]] = alloca [[STRUCT_H]], align 4
+  // CHECK-NEXT: [[I:%.*i.*]] = getelementptr inbounds [[STRUCT_H]], ptr 
[[H]], i32 0, i32 0
+  // CHECK-NEXT: store i32 1, ptr [[I]], align 4
+  // CHECK-NEXT: [[J:%.*j.*]] = getelementptr inbounds [[STRUCT_H]], ptr 
[[H]], i32 0, i32 1
+  // CHECK-NEXT: store i32 2, ptr [[J]], align 4
+  // CHECK-NEXT: ret void
+  void foo20() {
+H<2> h(1);
+  }
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5377,14 +5377,16 @@
   //   The remaining elements are initialized with their default member
   //   initializers, if any
   auto *FD = cast(SubEntity.getDecl());
-  if (Expr *ICE = FD->getInClassInitializer(); ICE && !VerifyOnly) {
-ExprResult DIE = S.BuildCXXDefaultInitExpr(FD->getLocation(), FD);
-if (DIE.isInvalid())
-  return false;
-S.checkInitializerLifetime(SubEntity, DIE.get());
-InitExprs.push_back(DIE.get());
+  if (FD->hasInClassInitializer()) {
+if (!VerifyOnly) {
+  ExprResult DIE = S.BuildCXXDefaultInitExpr(FD->getLocation(), 
FD);
+  if (DIE.isInvalid())
+return false;
+  S.checkInitializerLifetime(SubEntity, DIE.get());
+  InitExprs.push_back(DIE.get());
+}
 continue;
-  };
+  }
 }
 // Remaining class elements without default member initializers and
 // array elements are value initialized:
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -376,6 +376,9 @@
 - Fix bug in the computation of the ``__has_unique_object_representations``
   builtin for types with unnamed bitfields.
   (`#61336 `_)
+- Fix default member initializers sometimes being ignored when performing
+  parenthesized aggregate initialization of templated types.
+  (`#62266 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/CodeGen/paren-list-agg-init.cpp
===
--- clang/test/CodeGen/paren-list-agg-init.cpp
+++ clang/test/CodeGen/paren-list-agg-init.cpp
@@ -90,6 +90,15 @@
   };
 }
 
+namespace gh62266 {
+  // CHECK-DAG: [[STRUCT_H:%.*H.*]] = type { i32, i32 }
+  template 
+  struct H {
+int i;
+int j = J;
+  };
+}
+
 // CHECK-DAG: [[A1:@.*a1.*]] = internal constant [[STRUCT_A]] { i8 3, double 2.00e+00 }, align 8
 constexpr A a1(3.1, 2.0);
 // CHECK-DAG: [[A2:@.*a2.*]] = internal constant [[STRUCT_A]] { i8 99, double 0.00e+00 }, align 8
@@ -421,3 +430,17 @@
 make2<0>();
   }
 }
+
+namespace gh62266 {
+  // CHECK: define {{.*}} void {{.*foo20.*}}
+  // CHECK-NEXT: entry:
+  // CHECK-NEXT: [[H:%.*h.*]] = alloca [[STRUCT_H]], align 4
+  // CHECK-NEXT: [[I:%.*i.*]] = getelementptr inbounds [[STRUCT_H]], ptr [[H]], i32 0, i32 0
+  // CHECK-NEXT: store i32 1, ptr [[I]], align 4
+  // CHECK-NEXT: [[J:%.*j.*]] = getelementptr inbounds [[STRUCT_H]], ptr [[H]], i32 0, i32 1
+  // CHECK-NEXT: store i32 2, ptr [[J]], align 4
+  // CHECK-NEXT: ret void
+  void foo20() {
+H<2> h(1);
+  }
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5377,14 +5377,16 @@
   //   The remaining elements are initialized with their default member
   //   initializers, if any
   auto *FD = cast(SubEntity.getDecl());
-  if (Expr *ICE = FD->getInClassInitializer(); ICE 

[PATCH] D146386: [MS ABI] Fix mangling references to declarations.

2023-04-28 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:1250
+  for (unsigned I = 1, IE = ID->getChainingSize(); I < IE; ++I)
+mangleSourceName("");
+

bolshakov-a wrote:
> efriedma wrote:
> > bolshakov-a wrote:
> > > efriedma wrote:
> > > > bolshakov-a wrote:
> > > > > efriedma wrote:
> > > > > > Weird indentation
> > > > > I agree. Don't know why clang-format does so. Should I put 
> > > > > `clang-format off` here?
> > > > If clang-format won't cooperate, you can probably make it figure out 
> > > > what you're doing with something like
> > > > 
> > > >   if (const auto *ID = dyn_cast(ND)) {
> > > > for (unsigned I = 1, IE = ID->getChainingSize(); I < IE; ++I)
> > > >   mangleSourceName("");
> > > >   }
> > > It doesn't help. Moreover, clang-format corrupts formatting in this 
> > > function even without my changes. You can check it by yourself.
> > I just tried "clang-format -i" on the file with your patch, and it seems to 
> > compute the correct indentation here.  This with a source tree and 
> > clang-format binary from feb 28 because that's what I had handy... but I 
> > don't think anything relevant has changed here?
> Running clang-format on the whole file really seems to produce correct 
> formatting... But it is a lot of unrelated changes. Running clang-format only 
> on the `mangleNestedName` function (`--lines=1185:1287` without my changes, 
> `--lines=1242:1349` with my changes) produces bad formatting.
I could make a separate PR with formatting this file and fix this PR after 
landing that one.


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

https://reviews.llvm.org/D146386

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


[PATCH] D146386: [MS ABI] Fix mangling references to declarations.

2023-04-28 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:1250
+  for (unsigned I = 1, IE = ID->getChainingSize(); I < IE; ++I)
+mangleSourceName("");
+

efriedma wrote:
> bolshakov-a wrote:
> > efriedma wrote:
> > > bolshakov-a wrote:
> > > > efriedma wrote:
> > > > > Weird indentation
> > > > I agree. Don't know why clang-format does so. Should I put 
> > > > `clang-format off` here?
> > > If clang-format won't cooperate, you can probably make it figure out what 
> > > you're doing with something like
> > > 
> > >   if (const auto *ID = dyn_cast(ND)) {
> > > for (unsigned I = 1, IE = ID->getChainingSize(); I < IE; ++I)
> > >   mangleSourceName("");
> > >   }
> > It doesn't help. Moreover, clang-format corrupts formatting in this 
> > function even without my changes. You can check it by yourself.
> I just tried "clang-format -i" on the file with your patch, and it seems to 
> compute the correct indentation here.  This with a source tree and 
> clang-format binary from feb 28 because that's what I had handy... but I 
> don't think anything relevant has changed here?
Running clang-format on the whole file really seems to produce correct 
formatting... But it is a lot of unrelated changes. Running clang-format only 
on the `mangleNestedName` function (`--lines=1185:1287` without my changes, 
`--lines=1242:1349` with my changes) produces bad formatting.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:1816
 
-  QualType T = Base.getType();
+  std::stack EntryTypeStack;
+  SmallVector, 2> EntryManglers;

efriedma wrote:
> Please just use SmallVector instead of std::stack.
`std::stack` can be parameterized with container type (`std::stack>`). Or it should not be used for some other reason?


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

https://reviews.llvm.org/D146386

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


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-28 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

In D149272#4306103 , @aaron.ballman 
wrote:

> LGTM, but please add a release note when landing.

Thanks, I do not have permission to land, are you able to?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149272

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


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-28 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 518050.
dankm added a comment.

Rebase & add add release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149272

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclarationName.cpp
  clang/test/CodeGen/debug-prefix-map.cpp


Index: clang/test/CodeGen/debug-prefix-map.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-prefix-map.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+struct alignas(64) an {
+  struct {
+unsigned char x{0};
+  } arr[64];
+};
+
+struct an *pan = new an;
+
+// CHECK: !DISubprogram(name: "(unnamed struct at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}",
Index: clang/lib/AST/DeclarationName.cpp
===
--- clang/lib/AST/DeclarationName.cpp
+++ clang/lib/AST/DeclarationName.cpp
@@ -117,12 +117,12 @@
   Policy.adjustForCPlusPlus();
 
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
-  OS << *InjTy->getDecl();
+  InjTy->getDecl()->printName(OS, Policy);
   return;
 }
   }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1635,8 +1635,8 @@
   llvm_unreachable("unknown module kind");
 }
 
-void NamedDecl::printName(raw_ostream , const PrintingPolicy&) const {
-  OS << Name;
+void NamedDecl::printName(raw_ostream , const PrintingPolicy ) const 
{
+  Name.print(OS, Policy);
 }
 
 void NamedDecl::printName(raw_ostream ) const {
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -338,6 +338,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix lambdas and other anonymous function names not respecting 
``-fdebug-prefix-map``
+  (`#62192 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CodeGen/debug-prefix-map.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-prefix-map.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+struct alignas(64) an {
+  struct {
+unsigned char x{0};
+  } arr[64];
+};
+
+struct an *pan = new an;
+
+// CHECK: !DISubprogram(name: "(unnamed struct at ./UNLIKELY_PATH/empty{{/|}}{{.*}}",
Index: clang/lib/AST/DeclarationName.cpp
===
--- clang/lib/AST/DeclarationName.cpp
+++ clang/lib/AST/DeclarationName.cpp
@@ -117,12 +117,12 @@
   Policy.adjustForCPlusPlus();
 
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
-  OS << *InjTy->getDecl();
+  InjTy->getDecl()->printName(OS, Policy);
   return;
 }
   }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1635,8 +1635,8 @@
   llvm_unreachable("unknown module kind");
 }
 
-void NamedDecl::printName(raw_ostream , const PrintingPolicy&) const {
-  OS << Name;
+void NamedDecl::printName(raw_ostream , const PrintingPolicy ) const {
+  Name.print(OS, Policy);
 }
 
 void NamedDecl::printName(raw_ostream ) const {
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -338,6 +338,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix lambdas and other anonymous function names not respecting ``-fdebug-prefix-map``
+  (`#62192 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148274: [clang] Fix overly aggressive lifetime checks for parenthesized aggregate initialization

2023-04-28 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 518044.
ayzhao added a comment.

add release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148274

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Initialization.h
  clang/lib/Sema/SemaAccess.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/CodeGen/paren-list-agg-init.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp

Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -9,7 +9,7 @@
 struct B {
   A a;
   int b[20];
-  int & // expected-note {{reference member declared here}}
+  int &
 };
 
 struct C { // expected-note 5{{candidate constructor}}
@@ -21,9 +21,9 @@
   int a;
 };
 
-struct E { // expected-note 3{{candidate constructor}}
-  struct F {
-F(int, int);
+struct E {
+  struct F { // expected-note 2{{candidate constructor}}
+F(int, int); // expected-note {{candidate constructor}}
   };
   int a;
   F f;
@@ -56,6 +56,22 @@
   int b[]; // expected-note {{initialized flexible array member 'b' is here}}
 };
 
+enum K { K0, K1, K2 };
+
+struct L {
+  K k : 1;
+};
+
+struct M {
+  struct N {
+private:
+N(int);
+// expected-note@-1 {{declared private here}}
+  };
+  int i;
+  N n;
+};
+
 union U {
   int a;
   char* b;
@@ -74,7 +90,7 @@
   // beforecxx20-warning@-1 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
 }
 
-void foo() {
+void foo(int n) {
   A a1(1954, 9, 21);
   // expected-error@-1 {{excess elements in struct initializer}}
   A a2(2.1);
@@ -96,9 +112,8 @@
   B b1(2022, {7, 8});
   // expected-error@-1 {{no viable conversion from 'int' to 'A'}}
   B b2(A(1), {}, 1);
-  // expected-error@-1 {{reference member 'c' binds to a temporary object whose lifetime would be shorter than the lifetime of the constructed object}}
-  // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
-  // beforecxx20-warning@-3 {{aggregate initialization of type 'B' from a parenthesized list of values is a C++20 extension}}
+  // beforecxx20-warning@-1 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
+  // beforecxx20-warning@-2 {{aggregate initialization of type 'B' from a parenthesized list of values is a C++20 extension}}
 
   C c(A(1), 1, 2, 3, 4);
   // expected-error@-1 {{array initializer must be an initializer list}}
@@ -130,7 +145,7 @@
   // expected-error@-1 {{excess elements in union initializer}}
 
   E e1(1);
-  // expected-error@-1 {{no matching constructor for initialization of 'E'}}
+  // expected-error@-1 {{no matching constructor for initialization of 'F'}}
 
   constexpr F f1(1);
   // expected-error@-1 {{constexpr variable 'f1' must be initialized by a constant expression}}
@@ -148,18 +163,29 @@
   A a7 = Construct('i', 2.2);
   // beforecxx20-note@-1 {{in instantiation of function template specialization 'Construct' requested here}}
 
+  L l(K::K2);
+  // expected-warning@-1 {{implicit truncation}}
+  // beforecxx20-warning@-2 {{aggregate initialization of type 'L' from a parenthesized list of values is a C++20 extension}}
+
   int arr4[](1, 2);
   // beforecxx20-warning@-1 {{aggregate initialization of type 'int[2]' from a parenthesized list of values is a C++20 extension}}
 
   int arr5[2](1, 2);
   // beforecxx20-warning@-1 {{aggregate initialization of type 'int[2]' from a parenthesized list of values is a C++20 extension}}
 
+  int arr6[n](1, 2, 3);
+  // expected-error@-1 {{variable-sized object may not be initialized}}
+
   I i(1, 2);
   // expected-error@-1 {{no matching constructor for initialization of 'I'}}
 
   J j(1, {2, 3});
   // expected-error@-1 {{initialization of flexible array member is not allowed}}
 
+  M m(1, 1);
+  // expected-error@-1 {{field of type 'N' has private constructor}}
+  // beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a parenthesized list of values is a C++20 extension}}
+
   static_assert(__is_trivially_constructible(A, char, double));
   static_assert(__is_trivially_constructible(A, char, int));
   static_assert(__is_trivially_constructible(A, char));
@@ -221,5 +247,22 @@
 N n(43);
 // expected-error@-1 {{field of type 'L' has protected constructor}}
 // beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a parenthesized list of values is a C++20 extension}}
+}
+
+namespace gh61567 {
+struct O {
+  int i;
+  int &
+  // expected-note@-1 {{uninitialized reference member is here}}
+  int & = 1;
+};
+
+O o1(0, 0, 0); // no-error
+// beforecxx20-warning@-1 {{aggregate initialization of type 'O' from a parenthesized list of values is a C++20 extension}}
+
+O o2(0, 0); // no-error
+// 

[PATCH] D149436: [clang] Do not attempt to zero-extend _BitInt(1) when not required

2023-04-28 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.

LGTM




Comment at: clang/test/CodeGen/ext-int.c:8
+unsigned _BitInt(1) GlobSize1 = 0;
+// CHECK: @GlobSize1 = {{.*}}global i1 false
+

Interesting, it looks like `true` and `false` are valid for `i1` all the time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149436

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


[PATCH] D146386: [MS ABI] Fix mangling references to declarations.

2023-04-28 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:1250
+  for (unsigned I = 1, IE = ID->getChainingSize(); I < IE; ++I)
+mangleSourceName("");
+

bolshakov-a wrote:
> efriedma wrote:
> > bolshakov-a wrote:
> > > efriedma wrote:
> > > > Weird indentation
> > > I agree. Don't know why clang-format does so. Should I put `clang-format 
> > > off` here?
> > If clang-format won't cooperate, you can probably make it figure out what 
> > you're doing with something like
> > 
> >   if (const auto *ID = dyn_cast(ND)) {
> > for (unsigned I = 1, IE = ID->getChainingSize(); I < IE; ++I)
> >   mangleSourceName("");
> >   }
> It doesn't help. Moreover, clang-format corrupts formatting in this function 
> even without my changes. You can check it by yourself.
I just tried "clang-format -i" on the file with your patch, and it seems to 
compute the correct indentation here.  This with a source tree and clang-format 
binary from feb 28 because that's what I had handy... but I don't think 
anything relevant has changed here?


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

https://reviews.llvm.org/D146386

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


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Thanks, a couple very minor fixes / requests, but feel free to commit 
afterwards.




Comment at: clang/include/clang/Basic/AttrDocs.td:2323
+  let Content = [{
+The ``riscv_rvv_vector_bits(N)`` attribute is used to define fixed-length
+variants of sizeless types.

Maybe this is obvious from the attribute name, but it's better to be clear.



Comment at: clang/include/clang/Basic/AttrDocs.td:2332
+
+  #if define(__riscv_v_fixed_vlen)
+  typedef vint8m1_t fixed_vint8m1_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen)));




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D146386: [MS ABI] Fix mangling references to declarations.

2023-04-28 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:1250
+  for (unsigned I = 1, IE = ID->getChainingSize(); I < IE; ++I)
+mangleSourceName("");
+

efriedma wrote:
> bolshakov-a wrote:
> > efriedma wrote:
> > > Weird indentation
> > I agree. Don't know why clang-format does so. Should I put `clang-format 
> > off` here?
> If clang-format won't cooperate, you can probably make it figure out what 
> you're doing with something like
> 
>   if (const auto *ID = dyn_cast(ND)) {
> for (unsigned I = 1, IE = ID->getChainingSize(); I < IE; ++I)
>   mangleSourceName("");
>   }
It doesn't help. Moreover, clang-format corrupts formatting in this function 
even without my changes. You can check it by yourself.


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

https://reviews.llvm.org/D146386

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


[PATCH] D146386: [MS ABI] Fix mangling references to declarations.

2023-04-28 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:1250
+  for (unsigned I = 1, IE = ID->getChainingSize(); I < IE; ++I)
+mangleSourceName("");
+

bolshakov-a wrote:
> efriedma wrote:
> > Weird indentation
> I agree. Don't know why clang-format does so. Should I put `clang-format off` 
> here?
If clang-format won't cooperate, you can probably make it figure out what 
you're doing with something like

  if (const auto *ID = dyn_cast(ND)) {
for (unsigned I = 1, IE = ID->getChainingSize(); I < IE; ++I)
  mangleSourceName("");
  }


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

https://reviews.llvm.org/D146386

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


[PATCH] D146386: [MS ABI] Fix mangling references to declarations.

2023-04-28 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:1250
+  for (unsigned I = 1, IE = ID->getChainingSize(); I < IE; ++I)
+mangleSourceName("");
+

efriedma wrote:
> Weird indentation
I agree. Don't know why clang-format does so. Should I put `clang-format off` 
here?


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

https://reviews.llvm.org/D146386

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


[PATCH] D149380: [clang] Add -Wunused-result-always warning

2023-04-28 Thread Gregory Anders via Phabricator via cfe-commits
gpanders updated this revision to Diff 518024.
gpanders added a comment.

Remove cast to (void) in unused-expr.c

This cast is not necessary for this test, because foo does not have a
"warn_unused_result" attribute and is not marked const or pure. Removing the
cast improves the usefuless of the test as it verifies that there is no warning
issued in such a case (but a warning *would* be issued with
-Wunused-result-always, so this also acts as a "negative case" to ensure no
warning is issued when that flag is not present).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149380

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Expr.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/Sema/unused-expr.c
  clang/test/Sema/unused-result-always.c

Index: clang/test/Sema/unused-result-always.c
===
--- /dev/null
+++ clang/test/Sema/unused-result-always.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unreachable-code -Wno-strict-prototypes -Wunused-result-always
+
+int t1(int X, int Y);
+void t2();
+void *t3();
+
+#define M1(a, b) t1(a, b)
+
+void bar() {
+  t1(1, 2);   // expected-warning {{ignoring return value of function}}
+
+  t2();   // no warning.
+
+  (void)t1(1, 2); // no warning;
+
+  t3();   // expected-warning {{ignoring return value of function}}
+
+  M1(1, 2);   // expected-warning {{ignoring return value of function}}
+}
Index: clang/test/Sema/unused-expr.c
===
--- clang/test/Sema/unused-expr.c
+++ clang/test/Sema/unused-expr.c
@@ -9,7 +9,7 @@
   
   VP < P;  // expected-warning {{relational comparison result unused}}
   (void)A;
-  (void)foo(1,2);  // no warning.
+  foo(1,2);// no warning.
   
   A < foo(1, 2);   // expected-warning {{relational comparison result unused}}
 
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -200,8 +200,13 @@
 static bool DiagnoseNoDiscard(Sema , const WarnUnusedResultAttr *A,
   SourceLocation Loc, SourceRange R1,
   SourceRange R2, bool IsCtor) {
-  if (!A)
+  if (!A && S.Diags.isIgnored(diag::warn_unused_result_always, Loc))
 return false;
+
+  if (!A) {
+return S.Diag(Loc, diag::warn_unused_result_always) << R1 << R2;
+  }
+
   StringRef Msg = A->getMessage();
 
   if (Msg.empty()) {
@@ -242,7 +247,10 @@
   const Expr *WarnExpr;
   SourceLocation Loc;
   SourceRange R1, R2;
-  if (!E->isUnusedResultAWarning(WarnExpr, Loc, R1, R2, Context))
+  bool WarnUnusedResultAlways =
+  !Diags.isIgnored(diag::warn_unused_result_always, ExprLoc);
+  if (!E->isUnusedResultAWarning(WarnExpr, Loc, R1, R2, Context,
+ WarnUnusedResultAlways))
 return;
 
   // If this is a GNU statement expression expanded from a macro, it is probably
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -2578,7 +2578,7 @@
 /// warning.
 bool Expr::isUnusedResultAWarning(const Expr *, SourceLocation ,
   SourceRange , SourceRange ,
-  ASTContext ) const {
+  ASTContext , bool Always) const {
   // Don't warn if the expr is type dependent. The type could end up
   // instantiating to void.
   if (isTypeDependent())
@@ -2593,18 +2593,20 @@
 R1 = getSourceRange();
 return true;
   case ParenExprClass:
-return cast(this)->getSubExpr()->
-  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+return cast(this)->getSubExpr()->isUnusedResultAWarning(
+WarnE, Loc, R1, R2, Ctx, Always);
   case GenericSelectionExprClass:
-return cast(this)->getResultExpr()->
-  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+return cast(this)
+->getResultExpr()
+->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx, Always);
   case CoawaitExprClass:
   case CoyieldExprClass:
-return cast(this)->getResumeExpr()->
-  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+return cast(this)
+->getResumeExpr()
+->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx, Always);
   case ChooseExprClass:
-return cast(this)->getChosenSubExpr()->
-  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+return cast(this)->getChosenSubExpr()->isUnusedResultAWarning(
+WarnE, Loc, R1, R2, Ctx, Always);
   case UnaryOperatorClass: {
 const UnaryOperator *UO = cast(this);
 
@@ -2632,7 +2634,8 @@
 return false;
   break;
 case UO_Extension:
-

[PATCH] D149163: [NFC][CLANG] Fix coverity remarks about large copy by values

2023-04-28 Thread Soumi Manna via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Manna marked 3 inline comments as done.
Closed by commit rG4faf3fcf3fb2: [NFC][CLANG] Fix coverity remarks about large 
copy by values (authored by Manna).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149163

Files:
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  clang/lib/CodeGen/CGNonTrivialStruct.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -4553,7 +4553,7 @@
   return false;
 }
 
-static bool IsNoDerefableChunk(DeclaratorChunk Chunk) {
+static bool IsNoDerefableChunk(const DeclaratorChunk ) {
   return (Chunk.Kind == DeclaratorChunk::Pointer ||
   Chunk.Kind == DeclaratorChunk::Array);
 }
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1711,7 +1711,7 @@
 
   /// Emit the module flag metadata used to pass options controlling the
   /// the backend to LLVM.
-  void EmitBackendOptionsMetadata(const CodeGenOptions CodeGenOpts);
+  void EmitBackendOptionsMetadata(const CodeGenOptions );
 
   /// Emits OpenCL specific Metadata e.g. OpenCL version.
   void EmitOpenCLMetadata();
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -990,7 +990,7 @@
 }
 
 void CodeGenModule::EmitBackendOptionsMetadata(
-const CodeGenOptions CodeGenOpts) {
+const CodeGenOptions ) {
   if (getTriple().isRISCV()) {
 getModule().addModuleFlag(llvm::Module::Min, "SmallDataLimit",
   CodeGenOpts.SmallDataLimit);
Index: clang/lib/CodeGen/CGNonTrivialStruct.cpp
===
--- clang/lib/CodeGen/CGNonTrivialStruct.cpp
+++ clang/lib/CodeGen/CGNonTrivialStruct.cpp
@@ -323,7 +323,7 @@
 template 
 static std::array getParamAddrs(std::index_sequence 
IntSeq,
 std::array 
Alignments,
-FunctionArgList Args,
+const FunctionArgList ,
 CodeGenFunction *CGF) {
   return std::array{
   {Address(CGF->Builder.CreateLoad(CGF->GetAddrOfLocalVar(Args[Ints])),
Index: clang/lib/CodeGen/CGGPUBuiltin.cpp
===
--- clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -125,7 +125,7 @@
   }
 }
 
-bool containsNonScalarVarargs(CodeGenFunction *CGF, CallArgList Args) {
+bool containsNonScalarVarargs(CodeGenFunction *CGF, const CallArgList ) {
   return llvm::any_of(llvm::drop_begin(Args), [&](const CallArg ) {
 return !A.getRValue(*CGF).isScalar();
   });


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -4553,7 +4553,7 @@
   return false;
 }
 
-static bool IsNoDerefableChunk(DeclaratorChunk Chunk) {
+static bool IsNoDerefableChunk(const DeclaratorChunk ) {
   return (Chunk.Kind == DeclaratorChunk::Pointer ||
   Chunk.Kind == DeclaratorChunk::Array);
 }
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1711,7 +1711,7 @@
 
   /// Emit the module flag metadata used to pass options controlling the
   /// the backend to LLVM.
-  void EmitBackendOptionsMetadata(const CodeGenOptions CodeGenOpts);
+  void EmitBackendOptionsMetadata(const CodeGenOptions );
 
   /// Emits OpenCL specific Metadata e.g. OpenCL version.
   void EmitOpenCLMetadata();
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -990,7 +990,7 @@
 }
 
 void CodeGenModule::EmitBackendOptionsMetadata(
-const CodeGenOptions CodeGenOpts) {
+const CodeGenOptions ) {
   if (getTriple().isRISCV()) {
 getModule().addModuleFlag(llvm::Module::Min, "SmallDataLimit",
   CodeGenOpts.SmallDataLimit);
Index: clang/lib/CodeGen/CGNonTrivialStruct.cpp
===
--- clang/lib/CodeGen/CGNonTrivialStruct.cpp
+++ clang/lib/CodeGen/CGNonTrivialStruct.cpp
@@ -323,7 +323,7 @@
 template 
 static std::array getParamAddrs(std::index_sequence IntSeq,
 std::array 

[clang] 4faf3fc - [NFC][CLANG] Fix coverity remarks about large copy by values

2023-04-28 Thread via cfe-commits

Author: Manna, Soumi
Date: 2023-04-28T12:17:10-07:00
New Revision: 4faf3fcf3fb253cb3e68d6ae7b124e7a39f9ccff

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

LOG: [NFC][CLANG] Fix coverity remarks about large copy by values

Reported By Static Analyzer Tool, Coverity:

Big parameter passed by value
Copying large values is inefficient, consider passing by reference; Low, 
medium, and high size thresholds for detection can be adjusted.

1. Inside "CodeGenModule.cpp" file, in 
clang::CodeGen::CodeGenModule::EmitBackendOptionsMetadata(clang::CodeGenOptions):
 A very large function call parameter exceeding the high threshold is passed by 
value.

pass_by_value: Passing parameter CodeGenOpts of type clang::CodeGenOptions 
const (size 2168 bytes) by value, which exceeds the high threshold of 512 bytes.

2. Inside "SemaType.cpp" file, in IsNoDerefableChunk(clang::DeclaratorChunk): A 
large function call parameter exceeding the low threshold is passed by value.

pass_by_value: Passing parameter Chunk of type clang::DeclaratorChunk (size 176 
bytes) by value, which exceeds the low threshold of 128 bytes.

3. Inside "CGNonTrivialStruct.cpp" file, in ::getParamAddrs<1ull, 
<0ull...>>(std::integer_sequence, 
std::array, clang::CodeGen::FunctionArgList, 
clang::CodeGen::CodeGenFunction *): A large function call parameter exceeding 
the low threshold is passed by value.

.i. pass_by_value: Passing parameter Args of type 
clang::CodeGen::FunctionArgList (size 144 bytes) by value, which exceeds the 
low threshold of 128 bytes.

4. Inside "CGGPUBuiltin.cpp" file, in 
::containsNonScalarVarargs(clang::CodeGen::CodeGenFunction *, 
clang::CodeGen::CallArgList): A very large function call parameter exceeding 
the high threshold is passed by value.

i. pass_by_value: Passing parameter Args of type clang::CodeGen::CallArgList 
(size 1176 bytes) by value, which exceeds the high threshold of 512 bytes.

Reviewed By: tahonermann

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

Added: 


Modified: 
clang/lib/CodeGen/CGGPUBuiltin.cpp
clang/lib/CodeGen/CGNonTrivialStruct.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index 1183c2d7b5437..8451ebebfc0b7 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -125,7 +125,7 @@ packArgsIntoNVPTXFormatBuffer(CodeGenFunction *CGF, const 
CallArgList ) {
   }
 }
 
-bool containsNonScalarVarargs(CodeGenFunction *CGF, CallArgList Args) {
+bool containsNonScalarVarargs(CodeGenFunction *CGF, const CallArgList ) {
   return llvm::any_of(llvm::drop_begin(Args), [&](const CallArg ) {
 return !A.getRValue(*CGF).isScalar();
   });

diff  --git a/clang/lib/CodeGen/CGNonTrivialStruct.cpp 
b/clang/lib/CodeGen/CGNonTrivialStruct.cpp
index a10e51b8cb441..98378e1386414 100644
--- a/clang/lib/CodeGen/CGNonTrivialStruct.cpp
+++ b/clang/lib/CodeGen/CGNonTrivialStruct.cpp
@@ -323,7 +323,7 @@ static const CGFunctionInfo (CodeGenModule 
,
 template 
 static std::array getParamAddrs(std::index_sequence 
IntSeq,
 std::array 
Alignments,
-FunctionArgList Args,
+const FunctionArgList ,
 CodeGenFunction *CGF) {
   return std::array{
   {Address(CGF->Builder.CreateLoad(CGF->GetAddrOfLocalVar(Args[Ints])),

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index b8c45bc226ee1..367f802253e01 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -990,7 +990,7 @@ void CodeGenModule::EmitOpenCLMetadata() {
 }
 
 void CodeGenModule::EmitBackendOptionsMetadata(
-const CodeGenOptions CodeGenOpts) {
+const CodeGenOptions ) {
   if (getTriple().isRISCV()) {
 getModule().addModuleFlag(llvm::Module::Min, "SmallDataLimit",
   CodeGenOpts.SmallDataLimit);

diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index 64c2902572376..0a0fdc89202f1 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1711,7 +1711,7 @@ class CodeGenModule : public CodeGenTypeCache {
 
   /// Emit the module flag metadata used to pass options controlling the
   /// the backend to LLVM.
-  void EmitBackendOptionsMetadata(const CodeGenOptions CodeGenOpts);
+  void EmitBackendOptionsMetadata(const CodeGenOptions );
 
   /// Emits OpenCL specific Metadata e.g. OpenCL version.
   void EmitOpenCLMetadata();

diff  --git a/clang/lib/Sema/SemaType.cpp 

[PATCH] D148381: [WIP][Clang] Add element_count attribute

2023-04-28 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 518013.
void marked an inline comment as done.
void added a comment.

Fix the way the source ranges are imported via the ASTImporter.
Do other minor fixes according to feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ASTImporter.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test

Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -61,6 +61,7 @@
 // CHECK-NEXT: DiagnoseAsBuiltin (SubjectMatchRule_function)
 // CHECK-NEXT: DisableSanitizerInstrumentation (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: DisableTailCalls (SubjectMatchRule_function, SubjectMatchRule_objc_method)
+// CHECK-NEXT: ElementCount (SubjectMatchRule_field)
 // CHECK-NEXT: EnableIf (SubjectMatchRule_function)
 // CHECK-NEXT: EnforceTCB (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: EnforceTCBLeaf (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8238,6 +8238,29 @@
   D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL));
 }
 
+static void handleElementCountAttr(Sema , Decl *D, const ParsedAttr ) {
+  // TODO: Probably needs more processing here. See Sema::AddAlignValueAttr.
+  SmallVector Names;
+  SmallVector Ranges;
+  for (unsigned ArgNo = 0; ArgNo < getNumAttributeArgs(AL); ++ArgNo) {
+if (!AL.isArgIdent(ArgNo)) {
+  S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+  << AL << AANT_ArgumentIdentifier;
+  return;
+}
+
+IdentifierLoc *IL = AL.getArgAsIdent(ArgNo);
+Names.push_back(IL->Ident);
+Ranges.push_back(IL->Loc);
+  }
+
+  ElementCountAttr *ECA = ::new (S.Context) ElementCountAttr(S.Context, AL,
+ Names.data(),
+ Names.size());
+  ECA->addCountFieldSourceRange(Ranges);
+  D->addAttr(ECA);
+}
+
 static void handleFunctionReturnThunksAttr(Sema , Decl *D,
const ParsedAttr ) {
   StringRef KindStr;
@@ -9142,6 +9165,9 @@
   case ParsedAttr::AT_FunctionReturnThunks:
 handleFunctionReturnThunksAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_ElementCount:
+handleElementCountAttr(S, D, AL);
+break;
 
   // Microsoft attributes:
   case ParsedAttr::AT_LayoutVersion:
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -17686,6 +17686,43 @@
  "Broken injected-class-name");
 }
 
+static const FieldDecl *FindFieldWithElementCountAttr(const RecordDecl *RD) {
+  for (const Decl *D : RD->decls()) {
+if (const auto *FD = dyn_cast(D))
+  if (FD->hasAttr())
+return FD;
+
+if (const auto *SubRD = dyn_cast(D))
+  if (const FieldDecl *FD = FindFieldWithElementCountAttr(SubRD))
+return FD;
+  }
+
+  return nullptr;
+}
+
+static bool CheckElementCountAttr(const RecordDecl *RD, const FieldDecl *FD,
+  SourceRange ) {
+  const ElementCountAttr *ECA = FD->getAttr();
+  unsigned Idx = 0;
+
+  for (const IdentifierInfo *II : ECA->elementCountFields()) {
+Loc = ECA->getCountFieldSourceRange(Idx++);
+
+auto DeclIter = llvm::find_if(
+RD->fields(), [&](const FieldDecl *FD){
+  return II->getName() == FD->getName();
+});
+
+if (DeclIter == RD->field_end())
+  return false;
+
+if (auto *SubRD = DeclIter->getType()->getAsRecordDecl())
+  RD = SubRD;
+  }
+
+  return true;
+}
+
 void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD,
 SourceRange BraceRange) {
   AdjustDeclIfTemplate(TagD);
@@ -17743,6 +17780,17 @@
  [](const FieldDecl *FD) { return FD->isBitField(); }))
   Diag(BraceRange.getBegin(), diag::warn_pragma_align_not_xl_compatible);
   }
+
+  // Check the "element_count" attribute to ensure that the count field exists
+  // in the struct.
+  if (const RecordDecl *RD = dyn_cast(Tag)) {
+if (const FieldDecl *FD = FindFieldWithElementCountAttr(RD)) {
+  SourceRange SR;
+  if (!CheckElementCountAttr(RD, FD, SR))
+

[PATCH] D148381: [WIP][Clang] Add element_count attribute

2023-04-28 Thread Bill Wendling via Phabricator via cfe-commits
void marked an inline comment as done.
void added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:4170
+private:
+  mutable SmallVector CountFieldRanges;
+public:

nickdesaulniers wrote:
> `mutable`...my least favorite keyword in C++.  If you drop `const` from 
> `addCountFieldSourceRange` then you don't need `mutable`.
Hmm...I needed it at one point, but it no longer looks like I do.



Comment at: clang/include/clang/Basic/AttrDocs.td:7010
+/* ... */
+struct bar *fam[] __attribute__((element_count(bork, num_fam_elements)));
+  };

nickdesaulniers wrote:
> Question: does `bork` need to occur before `fam` for this substructure 
> reference to work?
> 
> Does that mean that `element_count` is essentially variadic with this syntax?
It doesn't need to be before the FAM, but I think a flexible array member needs 
to be at the end of a structure (I think anyway).

And yes, it's variadic. I'll need to expand that in the documentation, but 
really the documentation should be reworked a lot.



Comment at: clang/lib/AST/ASTImporter.cpp:8768
 class AttrImporter {
+  friend ASTImporter;
+

balazske wrote:
> This line is not necessary.
I need access to the `ToAttr` member. I can add an accesser though.



Comment at: clang/lib/AST/ASTImporter.cpp:8987
+cast(FromAttr)->copyCountFieldSourceRanges(
+cast(AI.ToAttr));
+break;

balazske wrote:
> From `ASTImporter` point of view this looks not correct: The `ToAttr` has a 
> different AST context than the `FromAttr`, simple copy of a source location 
> is not enough. There is a `ASTImporter::Import(SourceRange)` function that 
> can be used.
Ah! Thanks.



Comment at: clang/lib/CodeGen/CGExpr.cpp:954
+if (const auto *MD = dyn_cast(ME->getMemberDecl())) {
+  if (const auto ECA = MD->getAttr()) {
+const RecordDecl *RD = MD->getParent();

nickdesaulniers wrote:
> `const auto *ECA = ...`
Doh!



Comment at: clang/lib/CodeGen/CGExpr.cpp:961-963
+  for (FieldDecl *FD : RD->fields()) {
+if (FD->getName() != CountField->getName())
+  continue;

nickdesaulniers wrote:
> What happens if we never find the field? I guess that's checked below in 
> `CheckElementCountAttr`? Do we need a diagnostic though?
In that case, a diagnostic is emitted during SEMA.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

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


[PATCH] D149464: [clang][dataflow] Expose DataflowAnalysisContext from DataflowEnvironment.

2023-04-28 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:189
 
+  /// Deprecated. Use *getDataflowAnalysisContext().getOptions().Log instead.
   Logger () const { return *DACtx->getOptions().Log; }

Any reason for a comment as opposed to the deprecated attribute? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149464

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


[PATCH] D149464: [clang][dataflow] Expose DataflowAnalysisContext from DataflowEnvironment.

2023-04-28 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D149464#4306226 , @bazuzi wrote:

> Thanks! Seems like you have commit access, Yitzie; could you commit this for 
> me as "Samira Bazuzi "?

Sure. Let's wait til Gabor approves, but then I'll go ahead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149464

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


[PATCH] D149464: [clang][dataflow] Expose DataflowAnalysisContext from DataflowEnvironment.

2023-04-28 Thread Samira Bazuzi via Phabricator via cfe-commits
bazuzi added a comment.

Thanks! Seems like you have commit access, Yitzie; could you commit this for me 
as "Samira Bazuzi "?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149464

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


[PATCH] D146654: [clang] replaces numeric SARIF ids with heirarchical names

2023-04-28 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added inline comments.



Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:51-52
+  Diag->getDiags()->getDiagnosticIDs()->getStableName(Diag->getID()).str();
+  std::replace(StableName.begin(), StableName.end(), '_', '.');
+  SarifRule Rule = SarifRule::create().setRuleId(StableName);
 

Endill wrote:
> vaibhav.y wrote:
> > cjdb wrote:
> > > denik wrote:
> > > > §3.5.4 says that the hierarchical strings are separated by "/".
> > > > 
> > > > But more generally, are diagnostic names really fall under 
> > > > "hierarchical" definition?
> > > > Words between underscores should be treated as components. And $3.27.5 
> > > > says that the leading components have to be the identifier of the rule.
> > > > In some cases they look like valid components, e.g. `err_access`, 
> > > > `err_access_dtor`, `err_access_dtor_exception`.
> > > > But in cases like `err_cannot_open_file` neither of the leading 
> > > > components exists.
> > > > 
> > > > Theoretically we could use groups as the leading component for warnings 
> > > > for example. For errors the leading components are probably not even 
> > > > necessary, since if I understood correctly they are needed to suppress 
> > > > subsets of violations on the SARIF consumer side.
> > > > Or we just could keep the names with underscores as is. WDYT?
> > > I think in light of what you've said, changing back to underscores is 
> > > probably best.
> > > But more generally, are diagnostic names really fall under "hierarchical" 
> > > definition?
> > 
> > I have the same concern, but this is okay for a first pass as a "flat 
> > hierarchy" :)
> > 
> > If we want a deeper structure, we'll need some extra metadata in 
> > `DiagnosticSemaKinds.td`'s `Error<...>`  to add cluster names as a follow 
> > up to this.
> > 
> > WDYT about something like `clang/visibility/err_access` or 
> > `clang/syntax/err_stmtexpr_file_scope`.
> > 
> > Alternatively: we could draw from the c++ standard structure: 
> > https://eel.is/c++draft/basic.def.odr#term.odr.use and say the error code 
> > for an ODR violation could be `clang/basic/def/odr`, again I'm unsure how 
> > well this meshes with clang's diagnostic model.
> > Alternatively: we could draw from the c++ standard structure: 
> > https://eel.is/c++draft/basic.def.odr#term.odr.use and say the error code 
> > for an ODR violation could be clang/basic/def/odr, again I'm unsure how 
> > well this meshes with clang's diagnostic model.
> 
> The only reliable thing there are stable clause names like 
> `[namespace.udecl]`, because there are precedents of them being rearranged in 
> the table of contents ([[ 
> https://github.com/cplusplus/draft/commit/982a456f176ca00409c6e514af932051dce2485f
>  | 1 ]], [[ 
> https://github.com/cplusplus/draft/commit/3c580cd204fde95a21de1830ace75d14d429f845
>  | 2 ]]). We've got bitten by that in C++ conformance tests, which use table 
> of contents for directory hierarchy.
> WDYT about something like `clang/visibility/err_access` or 
> `clang/syntax/err_stmtexpr_file_scope`.

I think this might work!

> > Alternatively: we could draw from the c++ standard structure: 
> > https://eel.is/c++draft/basic.def.odr#term.odr.use and say the error code 
> > for an ODR violation could be clang/basic/def/odr, again I'm unsure how 
> > well this meshes with clang's diagnostic model.
> 
> The only reliable thing there are stable clause names like 
> `[namespace.udecl]`, because there are precedents of them being rearranged in 
> the table of contents ([[ 
> https://github.com/cplusplus/draft/commit/982a456f176ca00409c6e514af932051dce2485f
>  | 1 ]], [[ 
> https://github.com/cplusplus/draft/commit/3c580cd204fde95a21de1830ace75d14d429f845
>  | 2 ]]). We've got bitten by that in C++ conformance tests, which use table 
> of contents for directory hierarchy.

Right. Given that section names aren't actually stable, relying on those would 
be brittle at best.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146654

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


[PATCH] D146654: [clang] replaces numeric SARIF ids with heirarchical names

2023-04-28 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added inline comments.



Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:51-52
+  Diag->getDiags()->getDiagnosticIDs()->getStableName(Diag->getID()).str();
+  std::replace(StableName.begin(), StableName.end(), '_', '.');
+  SarifRule Rule = SarifRule::create().setRuleId(StableName);
 

vaibhav.y wrote:
> cjdb wrote:
> > denik wrote:
> > > §3.5.4 says that the hierarchical strings are separated by "/".
> > > 
> > > But more generally, are diagnostic names really fall under "hierarchical" 
> > > definition?
> > > Words between underscores should be treated as components. And $3.27.5 
> > > says that the leading components have to be the identifier of the rule.
> > > In some cases they look like valid components, e.g. `err_access`, 
> > > `err_access_dtor`, `err_access_dtor_exception`.
> > > But in cases like `err_cannot_open_file` neither of the leading 
> > > components exists.
> > > 
> > > Theoretically we could use groups as the leading component for warnings 
> > > for example. For errors the leading components are probably not even 
> > > necessary, since if I understood correctly they are needed to suppress 
> > > subsets of violations on the SARIF consumer side.
> > > Or we just could keep the names with underscores as is. WDYT?
> > I think in light of what you've said, changing back to underscores is 
> > probably best.
> > But more generally, are diagnostic names really fall under "hierarchical" 
> > definition?
> 
> I have the same concern, but this is okay for a first pass as a "flat 
> hierarchy" :)
> 
> If we want a deeper structure, we'll need some extra metadata in 
> `DiagnosticSemaKinds.td`'s `Error<...>`  to add cluster names as a follow up 
> to this.
> 
> WDYT about something like `clang/visibility/err_access` or 
> `clang/syntax/err_stmtexpr_file_scope`.
> 
> Alternatively: we could draw from the c++ standard structure: 
> https://eel.is/c++draft/basic.def.odr#term.odr.use and say the error code for 
> an ODR violation could be `clang/basic/def/odr`, again I'm unsure how well 
> this meshes with clang's diagnostic model.
> Alternatively: we could draw from the c++ standard structure: 
> https://eel.is/c++draft/basic.def.odr#term.odr.use and say the error code for 
> an ODR violation could be clang/basic/def/odr, again I'm unsure how well this 
> meshes with clang's diagnostic model.

The only reliable thing there are stable clause names like `[namespace.udecl]`, 
because there are precedents of them being rearranged in the table of contents 
([[ 
https://github.com/cplusplus/draft/commit/982a456f176ca00409c6e514af932051dce2485f
 | 1 ]], [[ 
https://github.com/cplusplus/draft/commit/3c580cd204fde95a21de1830ace75d14d429f845
 | 2 ]]). We've got bitten by that in C++ conformance tests, which use table of 
contents for directory hierarchy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146654

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


[PATCH] D149405: [Clang][Doc] Added an open project for improving command line docs

2023-04-28 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

In D149405#4305856 , @aaron.ballman 
wrote:

> Thank you, this is a great suggestion! Just some minor wording changes, but 
> otherwise LGTM.

Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149405

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


[PATCH] D149405: [Clang][Doc] Added an open project for improving command line docs

2023-04-28 Thread Shivam Gupta via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
xgupta marked an inline comment as done.
Closed by commit rGa70485493803: [Clang][Doc] Added an open project for 
improving command line docs (authored by xgupta).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149405

Files:
  clang/www/OpenProjects.html


Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -38,6 +38,8 @@
   documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticDocs.td;>
   diagnostic group flags (adding code examples of what is diagnosed, or
   other relevant information), or
+  documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td;>
+  command line options, or
   help with completing other missing documentation.
 
 These projects are independent of each other.


Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -38,6 +38,8 @@
   documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticDocs.td;>
   diagnostic group flags (adding code examples of what is diagnosed, or
   other relevant information), or
+  documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td;>
+  command line options, or
   help with completing other missing documentation.
 
 These projects are independent of each other.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a704854 - [Clang][Doc] Added an open project for improving command line docs

2023-04-28 Thread Shivam Gupta via cfe-commits

Author: Shivam Gupta
Date: 2023-04-28T23:32:37+05:30
New Revision: a70485493803d2e22cbc79184b78861b098ba416

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

LOG: [Clang][Doc] Added an open project for improving command line docs

There seems to be a lot of documentation is missing
for different command line flags uses.
This create confusion with same looking options, better to
document clearly their uses.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/www/OpenProjects.html

Removed: 




diff  --git a/clang/www/OpenProjects.html b/clang/www/OpenProjects.html
index 4b6b0283767c0..77f04160700fc 100755
--- a/clang/www/OpenProjects.html
+++ b/clang/www/OpenProjects.html
@@ -38,6 +38,8 @@ Open Clang Projects
   documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticDocs.td;>
   diagnostic group flags (adding code examples of what is diagnosed, or
   other relevant information), or
+  documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td;>
+  command line options, or
   help with completing other missing documentation.
 
 These projects are independent of each other.



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


[PATCH] D149405: [Clang][Doc] Added an open project for improving command line docs

2023-04-28 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 517996.
xgupta added a comment.

address comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149405

Files:
  clang/www/OpenProjects.html


Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -38,6 +38,8 @@
   documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticDocs.td;>
   diagnostic group flags (adding code examples of what is diagnosed, or
   other relevant information), or
+  documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td;>
+  command line options, or
   help with completing other missing documentation.
 
 These projects are independent of each other.


Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -38,6 +38,8 @@
   documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticDocs.td;>
   diagnostic group flags (adding code examples of what is diagnosed, or
   other relevant information), or
+  documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td;>
+  command line options, or
   help with completing other missing documentation.
 
 These projects are independent of each other.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143112: [clang] Support parsing comments without ASTContext

2023-04-28 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added a comment.

(ping) Does this make sense or are more adjustments needed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143112

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


[PATCH] D147847: [clangd] Hover: Add CalleeArgInfo for constructor expressions

2023-04-28 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:986
+  const FunctionDecl *FD = nullptr;
+  llvm::SmallVector Args;
+

nridge wrote:
> tom-anders wrote:
> > Unfortunately, while CallExpr and CXXConstructExpr basically have the same 
> > API for getting Args, they're not related by a common base class.
> > 
> > Is there a more elegant solution than temporarily storing the Args in a 
> > SmallVector here?
> You can use `ArrayRef` instead of `SmallVector` and avoid copying the 
> arguments (compare 
> [process_call](https://searchfox.org/llvm/rev/b34ca0851a5209a10c0ca285c000a18073677891/clang-tools-extra/clangd/InlayHints.cpp#239,265)
>  in `InlayHintVisitor`).
Ah perfect, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147847

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


[PATCH] D147626: [clang] Reject flexible array member in a union in C++

2023-04-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6241-6244
 def ext_flexible_array_empty_aggregate_ms : Extension<
   "flexible array member %0 in otherwise empty "
   "%select{struct|interface|union|class|enum}1 is a Microsoft extension">,
   InGroup;

Fznamznon wrote:
> aaron.ballman wrote:
> > Should this be updated to remove the union case?
> Sounds reasonable, but what is unfortunate is that this diagnostic exactly 
> matches TagTypeKind enum, so now it can be emitted with `Diag(...) << ... << 
> SomeTagDecl->getTagKind().` Once I remove `union` from there, this neat thing 
> fails.
Oh, that might be worth leaving alone then, but put a comment next to the 
diagnostic definition to explain the relationship to `TagTypeKind`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147626

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


[PATCH] D147847: [clangd] Hover: Add CalleeArgInfo for constructor expressions

2023-04-28 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders updated this revision to Diff 517994.
tom-anders marked an inline comment as done.
tom-anders added a comment.

Use ArrayRef instead of SmallVector to avoid copy (also fix 2 typos in the 
comment below)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147847

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


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -956,6 +956,29 @@
 HI.CalleeArgInfo->Type = "const float &";
 HI.CallPassType = HoverInfo::PassType{PassMode::Value, true};
   }},
+  {
+  R"cpp(
+  struct Foo {
+explicit Foo(const float& arg) {}
+  };
+  int main() {
+int a = 0;
+Foo foo([[^a]]);
+  }
+  )cpp",
+  [](HoverInfo ) {
+HI.Name = "a";
+HI.Kind = index::SymbolKind::Variable;
+HI.NamespaceScope = "";
+HI.Definition = "int a = 0";
+HI.LocalScope = "main::";
+HI.Value = "0";
+HI.Type = "int";
+HI.CalleeArgInfo.emplace();
+HI.CalleeArgInfo->Name = "arg";
+HI.CalleeArgInfo->Type = "const float &";
+HI.CallPassType = HoverInfo::PassType{PassMode::Value, true};
+  }},
   {// Literal passed to function call
R"cpp(
   void fun(int arg_a, const int _b) {};
@@ -1342,6 +1365,7 @@
   CustomClass(const Base ) {}
   CustomClass(int ) {}
   CustomClass(float x) {}
+  CustomClass(int x, int y) {}
 };
 
 void int_by_ref(int ) {}
@@ -1388,6 +1412,11 @@
   {"base_by_ref([[^derived]]);", PassMode::Ref, false},
   {"base_by_const_ref([[^derived]]);", PassMode::ConstRef, false},
   {"base_by_value([[^derived]]);", PassMode::Value, false},
+  // Custom class constructor tests
+  {"CustomClass c1([[^base]]);", PassMode::ConstRef, false},
+  {"auto c2 = new CustomClass([[^base]]);", PassMode::ConstRef, false},
+  {"CustomClass c3([[^int_x]]);", PassMode::Ref, false},
+  {"CustomClass c3(int_x, [[^int_x]]);", PassMode::Value, false},
   // Converted tests
   {"float_by_value([[^int_x]]);", PassMode::Value, true},
   {"float_by_value([[^int_ref]]);", PassMode::Value, true},
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -981,12 +981,23 @@
   const auto  = N->outerImplicit();
   if (!OuterNode.Parent)
 return;
-  const auto *CE = OuterNode.Parent->ASTNode.get();
-  if (!CE)
+
+  const FunctionDecl *FD = nullptr;
+  llvm::ArrayRef Args;
+
+  if (const auto *CE = OuterNode.Parent->ASTNode.get()) {
+FD = CE->getDirectCallee();
+Args = {CE->getArgs(), CE->getNumArgs()};
+  } else if (const auto *CE =
+ OuterNode.Parent->ASTNode.get()) {
+FD = CE->getConstructor();
+Args = {CE->getArgs(), CE->getNumArgs()};
+  }
+  if (!FD)
 return;
-  const FunctionDecl *FD = CE->getDirectCallee();
-  // For non-function-call-like operatators (e.g. operator+, operator<<) it's
-  // not immediattely obvious what the "passed as" would refer to and, given
+
+  // For non-function-call-like operators (e.g. operator+, operator<<) it's
+  // not immediately obvious what the "passed as" would refer to and, given
   // fixed function signature, the value would be very low anyway, so we choose
   // to not support that.
   // Both variadic functions and operator() (especially relevant for lambdas)
@@ -999,8 +1010,8 @@
   auto Parameters = resolveForwardingParameters(FD);
 
   // Find argument index for N.
-  for (unsigned I = 0; I < CE->getNumArgs() && I < Parameters.size(); ++I) {
-if (CE->getArg(I) != OuterNode.ASTNode.get())
+  for (unsigned I = 0; I < Args.size() && I < Parameters.size(); ++I) {
+if (Args[I] != OuterNode.ASTNode.get())
   continue;
 
 // Extract matching argument from function declaration.


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -956,6 +956,29 @@
 HI.CalleeArgInfo->Type = "const float &";
 HI.CallPassType = HoverInfo::PassType{PassMode::Value, true};
   }},
+  {
+  R"cpp(
+  struct Foo {
+explicit Foo(const float& arg) {}
+  };
+  int main() {
+int a = 0;
+Foo foo([[^a]]);
+  }
+  )cpp",
+  [](HoverInfo ) {
+HI.Name = "a";
+HI.Kind = 

[PATCH] D149272: [clang] Call printName to get name of Decl

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

LGTM, but please add a release note when landing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149272

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


[PATCH] D147846: [clangd] Hover: resolve forwarding parameters for CalleeArgInfo

2023-04-28 Thread Tom Praschan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa7b4fd953f44: [clangd] Hover: resolve forwarding parameters 
for CalleeArgInfo (authored by tom-anders).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147846

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


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -906,6 +906,35 @@
  HI.CalleeArgInfo->Type = "int &";
  HI.CallPassType = HoverInfo::PassType{PassMode::Ref, false};
}},
+  {// make_unique-like function call
+   R"cpp(
+  struct Foo {
+explicit Foo(int arg_a) {}
+  };
+  template
+  T make(Args&&... args)
+  {
+  return T(args...);
+  }
+
+  void code() {
+int a = 1;
+auto foo = make([[^a]]);
+  }
+  )cpp",
+   [](HoverInfo ) {
+ HI.Name = "a";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.NamespaceScope = "";
+ HI.Definition = "int a = 1";
+ HI.LocalScope = "code::";
+ HI.Value = "1";
+ HI.Type = "int";
+ HI.CalleeArgInfo.emplace();
+ HI.CalleeArgInfo->Name = "arg_a";
+ HI.CalleeArgInfo->Type = "int";
+ HI.CallPassType = HoverInfo::PassType{PassMode::Value, false};
+   }},
   {
   R"cpp(
   void foobar(const float );
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -996,13 +996,15 @@
 
   HoverInfo::PassType PassType;
 
+  auto Parameters = resolveForwardingParameters(FD);
+
   // Find argument index for N.
-  for (unsigned I = 0; I < CE->getNumArgs() && I < FD->getNumParams(); ++I) {
+  for (unsigned I = 0; I < CE->getNumArgs() && I < Parameters.size(); ++I) {
 if (CE->getArg(I) != OuterNode.ASTNode.get())
   continue;
 
 // Extract matching argument from function declaration.
-if (const ParmVarDecl *PVD = FD->getParamDecl(I)) {
+if (const ParmVarDecl *PVD = Parameters[I]) {
   HI.CalleeArgInfo.emplace(toHoverInfoParam(PVD, PP));
   if (N == )
 PassType.PassBy = getPassMode(PVD->getType());


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -906,6 +906,35 @@
  HI.CalleeArgInfo->Type = "int &";
  HI.CallPassType = HoverInfo::PassType{PassMode::Ref, false};
}},
+  {// make_unique-like function call
+   R"cpp(
+  struct Foo {
+explicit Foo(int arg_a) {}
+  };
+  template
+  T make(Args&&... args)
+  {
+  return T(args...);
+  }
+
+  void code() {
+int a = 1;
+auto foo = make([[^a]]);
+  }
+  )cpp",
+   [](HoverInfo ) {
+ HI.Name = "a";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.NamespaceScope = "";
+ HI.Definition = "int a = 1";
+ HI.LocalScope = "code::";
+ HI.Value = "1";
+ HI.Type = "int";
+ HI.CalleeArgInfo.emplace();
+ HI.CalleeArgInfo->Name = "arg_a";
+ HI.CalleeArgInfo->Type = "int";
+ HI.CallPassType = HoverInfo::PassType{PassMode::Value, false};
+   }},
   {
   R"cpp(
   void foobar(const float );
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -996,13 +996,15 @@
 
   HoverInfo::PassType PassType;
 
+  auto Parameters = resolveForwardingParameters(FD);
+
   // Find argument index for N.
-  for (unsigned I = 0; I < CE->getNumArgs() && I < FD->getNumParams(); ++I) {
+  for (unsigned I = 0; I < CE->getNumArgs() && I < Parameters.size(); ++I) {
 if (CE->getArg(I) != OuterNode.ASTNode.get())
   continue;
 
 // Extract matching argument from function declaration.
-if (const ParmVarDecl *PVD = FD->getParamDecl(I)) {
+if (const ParmVarDecl *PVD = Parameters[I]) {
   HI.CalleeArgInfo.emplace(toHoverInfoParam(PVD, PP));
   if (N == )
 PassType.PassBy = getPassMode(PVD->getType());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] a7b4fd9 - [clangd] Hover: resolve forwarding parameters for CalleeArgInfo

2023-04-28 Thread Tom Praschan via cfe-commits

Author: Tom Praschan
Date: 2023-04-28T21:46:32+02:00
New Revision: a7b4fd953f44b790f8832a5b57d7598bd12adfb2

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

LOG: [clangd] Hover: resolve forwarding parameters for CalleeArgInfo

This uses the logic added in D124690

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 3eb0900715744..f59642dbf721d 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -996,13 +996,15 @@ void maybeAddCalleeArgInfo(const SelectionTree::Node *N, 
HoverInfo ,
 
   HoverInfo::PassType PassType;
 
+  auto Parameters = resolveForwardingParameters(FD);
+
   // Find argument index for N.
-  for (unsigned I = 0; I < CE->getNumArgs() && I < FD->getNumParams(); ++I) {
+  for (unsigned I = 0; I < CE->getNumArgs() && I < Parameters.size(); ++I) {
 if (CE->getArg(I) != OuterNode.ASTNode.get())
   continue;
 
 // Extract matching argument from function declaration.
-if (const ParmVarDecl *PVD = FD->getParamDecl(I)) {
+if (const ParmVarDecl *PVD = Parameters[I]) {
   HI.CalleeArgInfo.emplace(toHoverInfoParam(PVD, PP));
   if (N == )
 PassType.PassBy = getPassMode(PVD->getType());

diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 5ad9d69cb0dc2..5bf089fbbfeca 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -906,6 +906,35 @@ class Foo final {})cpp";
  HI.CalleeArgInfo->Type = "int &";
  HI.CallPassType = HoverInfo::PassType{PassMode::Ref, false};
}},
+  {// make_unique-like function call
+   R"cpp(
+  struct Foo {
+explicit Foo(int arg_a) {}
+  };
+  template
+  T make(Args&&... args)
+  {
+  return T(args...);
+  }
+
+  void code() {
+int a = 1;
+auto foo = make([[^a]]);
+  }
+  )cpp",
+   [](HoverInfo ) {
+ HI.Name = "a";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.NamespaceScope = "";
+ HI.Definition = "int a = 1";
+ HI.LocalScope = "code::";
+ HI.Value = "1";
+ HI.Type = "int";
+ HI.CalleeArgInfo.emplace();
+ HI.CalleeArgInfo->Name = "arg_a";
+ HI.CalleeArgInfo->Type = "int";
+ HI.CallPassType = HoverInfo::PassType{PassMode::Value, false};
+   }},
   {
   R"cpp(
   void foobar(const float );



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


[PATCH] D147626: [clang] Reject flexible array member in a union in C++

2023-04-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 517985.
Fznamznon edited the summary of this revision.
Fznamznon added a comment.

Apply some of the comments, rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147626

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/Layout/aix-power-alignment-typedef.cpp
  clang/test/Sema/MicrosoftExtensions.c
  clang/test/Sema/init.c
  clang/test/SemaCXX/flexible-array-test.cpp
  clang/test/SemaCXX/gnu-flags.cpp
  clang/test/SemaObjCXX/flexible-array.mm

Index: clang/test/SemaObjCXX/flexible-array.mm
===
--- clang/test/SemaObjCXX/flexible-array.mm
+++ clang/test/SemaObjCXX/flexible-array.mm
@@ -4,7 +4,7 @@
 
 union VariableSizeUnion {
   int s;
-  char c[];
+  char c[]; //expected-error {{flexible array member 'c' in a union is not allowed}}
 };
 
 @interface LastUnionIvar {
Index: clang/test/SemaCXX/gnu-flags.cpp
===
--- clang/test/SemaCXX/gnu-flags.cpp
+++ clang/test/SemaCXX/gnu-flags.cpp
@@ -8,34 +8,27 @@
 
 // RUN: %clang_cc1 -fsyntax-only -verify %s -DALL -Wno-gnu \
 // RUN:   -Wgnu-anonymous-struct -Wredeclared-class-member \
-// RUN:   -Wgnu-flexible-array-union-member -Wgnu-folding-constant \
-// RUN:   -Wgnu-empty-struct
+// RUN:   -Wgnu-folding-constant -Wgnu-empty-struct
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s -DALL -Wno-gnu \
 // RUN:   -Wgnu-anonymous-struct -Wredeclared-class-member \
-// RUN:   -Wgnu-flexible-array-union-member -Wgnu-folding-constant \
-// RUN:   -Wgnu-empty-struct
+// RUN:   -Wgnu-folding-constant -Wgnu-empty-struct
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s -DALL -Wno-gnu \
 // RUN:   -Wgnu-anonymous-struct -Wredeclared-class-member \
-// RUN:   -Wgnu-flexible-array-union-member -Wgnu-folding-constant \
-// RUN:   -Wgnu-empty-struct
+// RUN:   -Wgnu-folding-constant -Wgnu-empty-struct
 
 // RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wgnu \
 // RUN:   -Wno-gnu-anonymous-struct -Wno-redeclared-class-member \
-// RUN:   -Wno-gnu-flexible-array-union-member -Wno-gnu-folding-constant \
-// RUN:   -Wno-gnu-empty-struct
+// RUN:   -Wno-gnu-folding-constant -Wno-gnu-empty-struct
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s -DNONE -Wgnu \
 // RUN:   -Wno-gnu-anonymous-struct -Wno-redeclared-class-member \
-// RUN:   -Wno-gnu-flexible-array-union-member -Wno-gnu-folding-constant \
-// RUN:   -Wno-gnu-empty-struct
+// RUN:   -Wno-gnu-folding-constant -Wno-gnu-empty-struct
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s -DNONE -Wgnu \
 // RUN:   -Wno-gnu-anonymous-struct -Wno-redeclared-class-member \
-// RUN:   -Wno-gnu-flexible-array-union-member -Wno-gnu-folding-constant \
-// RUN:   -Wno-gnu-empty-struct
+// RUN:   -Wno-gnu-folding-constant -Wno-gnu-empty-struct
 
 // Additional disabled tests:
 // %clang_cc1 -fsyntax-only -verify %s -DANONYMOUSSTRUCT -Wno-gnu -Wgnu-anonymous-struct
 // %clang_cc1 -fsyntax-only -verify %s -DREDECLAREDCLASSMEMBER -Wno-gnu -Wredeclared-class-member
-// %clang_cc1 -fsyntax-only -verify %s -DFLEXIBLEARRAYUNIONMEMBER -Wno-gnu -Wgnu-flexible-array-union-member
 // %clang_cc1 -fsyntax-only -verify %s -DFOLDINGCONSTANT -Wno-gnu -Wgnu-folding-constant
 // %clang_cc1 -fsyntax-only -verify %s -DEMPTYSTRUCT -Wno-gnu -Wgnu-empty-struct
 
@@ -70,19 +63,6 @@
   };
 }
 
-
-#if ALL || FLEXIBLEARRAYUNIONMEMBER
-// expected-warning@+6 {{flexible array member 'c1' in a union is a GNU extension}}
-#endif
-
-struct faum {
-   int l;
-   union {
-   int c1[];
-   };
-};
-
-
 #if (ALL || FOLDINGCONSTANT) && (__cplusplus <= 199711L) // C++03 or earlier modes
 // expected-warning@+4 {{in-class initializer for static data member is not a constant expression; folding it to a constant is a GNU extension}}
 #endif
Index: clang/test/SemaCXX/flexible-array-test.cpp
===
--- clang/test/SemaCXX/flexible-array-test.cpp
+++ clang/test/SemaCXX/flexible-array-test.cpp
@@ -16,7 +16,7 @@
 
 struct Rec {
   union { // expected-warning-re {{variable sized type '{{.*}}' not at the end of a struct or class is a GNU extension}}
-int u0[];
+int u0[]; // expected-error {{flexible array member 'u0' in a union is not allowed}}
   };
   int x;
 } rec;
@@ -63,7 +63,7 @@
 
 union B {
   int s;
-  char c[];
+  char c[]; // expected-error {{flexible array member 'c' in a union is not allowed}}
 };
 
 class C {
Index: clang/test/Sema/init.c
===
--- clang/test/Sema/init.c
+++ clang/test/Sema/init.c
@@ -164,3 +164,6 @@
 
 typedef struct { uintptr_t x : 2; } StructWithBitfield;
 StructWithBitfield bitfieldvar = { 

[PATCH] D149461: [NFC] ][CLANG] Fix static code analyzer concerns

2023-04-28 Thread Soumi Manna via Phabricator via cfe-commits
Manna added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:7696
   if (isa(DC)) {
-for (auto Lexical : TULexicalDecls)
+for (const auto  : TULexicalDecls)
   Visit(Lexical.first, Lexical.second);

This returns `std::vector` in 
'ASTReader.h` file


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

https://reviews.llvm.org/D149461

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


[clang] 024bb62 - [Driver] Pass --target2= to linker from baremetal toolchain

2023-04-28 Thread Mikhail Maltsev via cfe-commits

Author: Mikhail Maltsev
Date: 2023-04-28T18:30:49+01:00
New Revision: 024bb62ffd072e9a90343e88c92e40b5849c2632

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

LOG: [Driver] Pass --target2= to linker from baremetal toolchain

According to the GNU ld manual
https://sourceware.org/binutils/docs/ld/ARM.html#ARM the R_ARM_TARGET2
relocation (used in exception handling tables) is treated differently
depending on the target. By default, LLD treats R_ARM_TARGET2 as
R_ARM_GOT_PREL (--target2=got-rel), which is correct for Linux but not
for embedded targets.

This patch adds --target2=rel to linker options in the baremetal
toolchain driver so that on baremetal targets, R_ARM_TARGET2 is
treated as R_ARM_REL32. Such behavior is compatible with GNU ld and
unwinding libraries (e.g., libuwind).

Reviewed By: peter.smith, phosek

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/test/Driver/baremetal.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 38f26d0176471..3232394007bc3 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -342,6 +342,12 @@ void baremetal::Linker::ConstructJob(Compilation , const 
JobAction ,
   if (TC.getTriple().isRISCV())
 CmdArgs.push_back("-X");
 
+  // The R_ARM_TARGET2 relocation must be treated as R_ARM_REL32 on arm*-*-elf
+  // and arm*-*-eabi (the default is R_ARM_GOT_PREL, used on arm*-*-linux and
+  // arm*-*-*bsd).
+  if (isARMBareMetal(TC.getTriple()))
+CmdArgs.push_back("--target2=rel");
+
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 

diff  --git a/clang/test/Driver/baremetal.cpp b/clang/test/Driver/baremetal.cpp
index 7f2334493c529..c00713a5d30fb 100644
--- a/clang/test/Driver/baremetal.cpp
+++ b/clang/test/Driver/baremetal.cpp
@@ -15,7 +15,7 @@
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" 
"-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
-// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"{{.*}}.tmp.out"
+// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "--target2=rel" 
"-o" "{{.*}}.tmp.out"
 
 // RUN: %clang %s -### --target=armv6m-none-eabi -nostdlibinc -nobuiltininc 
2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-LIBINC %s
@@ -42,7 +42,7 @@
 // CHECK-V6M-DEFAULTCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-DEFAULTCXX-SAME: 
"-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
-// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"a.out"
+// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi -stdlib=libc++ 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-LIBCXX %s
@@ -53,7 +53,7 @@
 // CHECK-V6M-LIBCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
-// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" "a.out"
+// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
@@ -66,7 +66,7 @@
 // CHECK-V6M-LIBSTDCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBSTDCXX-SAME: 
"-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind"
-// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"a.out"
+// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \



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


[PATCH] D149458: [Driver] Pass --target2= to linker from baremetal toolchain

2023-04-28 Thread Mikhail Maltsev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG024bb62ffd07: [Driver] Pass --target2= to linker from 
baremetal toolchain (authored by miyuki).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149458

Files:
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal.cpp


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -15,7 +15,7 @@
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" 
"-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
-// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"{{.*}}.tmp.out"
+// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "--target2=rel" 
"-o" "{{.*}}.tmp.out"
 
 // RUN: %clang %s -### --target=armv6m-none-eabi -nostdlibinc -nobuiltininc 
2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-LIBINC %s
@@ -42,7 +42,7 @@
 // CHECK-V6M-DEFAULTCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-DEFAULTCXX-SAME: 
"-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
-// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"a.out"
+// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi -stdlib=libc++ 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-LIBCXX %s
@@ -53,7 +53,7 @@
 // CHECK-V6M-LIBCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
-// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" "a.out"
+// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
@@ -66,7 +66,7 @@
 // CHECK-V6M-LIBSTDCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBSTDCXX-SAME: 
"-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind"
-// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"a.out"
+// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -342,6 +342,12 @@
   if (TC.getTriple().isRISCV())
 CmdArgs.push_back("-X");
 
+  // The R_ARM_TARGET2 relocation must be treated as R_ARM_REL32 on arm*-*-elf
+  // and arm*-*-eabi (the default is R_ARM_GOT_PREL, used on arm*-*-linux and
+  // arm*-*-*bsd).
+  if (isARMBareMetal(TC.getTriple()))
+CmdArgs.push_back("--target2=rel");
+
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -15,7 +15,7 @@
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" "-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
-// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" "{{.*}}.tmp.out"
+// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "--target2=rel" "-o" "{{.*}}.tmp.out"
 
 // RUN: %clang %s -### --target=armv6m-none-eabi -nostdlibinc -nobuiltininc 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck --check-prefix=CHECK-V6M-LIBINC %s
@@ -42,7 +42,7 @@
 // CHECK-V6M-DEFAULTCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-DEFAULTCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
-// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" "a.out"
+// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi -stdlib=libc++ 2>&1 \
 // RUN: 

[PATCH] D149461: [NFC] ][CLANG] Fix static code analyzer concerns

2023-04-28 Thread Soumi Manna via Phabricator via cfe-commits
Manna added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:4428
   // Mark selectors as out of date.
-  for (auto Sel : SelectorGeneration)
+  for (const auto  : SelectorGeneration)
 SelectorOutOfDate[Sel.first] = true;

Here Object of type is `DenseMapPair`.  `SelectorGeneration`  returns 
`llvm::DenseMap' in `ASTReader.h' file.



Comment at: clang/lib/Serialization/ASTWriter.cpp:1781
   unsigned DataLen = 1 + 4 + 4;
-  for (auto ModInfo : Data.KnownHeaders)
+  for (const auto  : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))

Object of type `KnownHeader` returns ` ArrayRef` in 
`ASTWriter.cpp` file.



Comment at: clang/lib/Serialization/ASTWriter.cpp:1887
   // enough information in the module map.
-  for (auto U : M->MissingHeaders) {
+  for (const auto  : M->MissingHeaders) {
 // Check that we were given enough information to build a module

This returns ` SmallVector` in `Module.h' file





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

https://reviews.llvm.org/D149461

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


[PATCH] D147626: [clang] Reject flexible array member in a union in C++

2023-04-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6241-6244
 def ext_flexible_array_empty_aggregate_ms : Extension<
   "flexible array member %0 in otherwise empty "
   "%select{struct|interface|union|class|enum}1 is a Microsoft extension">,
   InGroup;

aaron.ballman wrote:
> Should this be updated to remove the union case?
Sounds reasonable, but what is unfortunate is that this diagnostic exactly 
matches TagTypeKind enum, so now it can be emitted with `Diag(...) << ... << 
SomeTagDecl->getTagKind().` Once I remove `union` from there, this neat thing 
fails.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147626

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


[PATCH] D149361: [profiling] Improve error message for raw profile header mismatches

2023-04-28 Thread Jessica Paquette via Phabricator via cfe-commits
paquette added a comment.

Sorry for the inconvenience and thanks for the fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149361

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


[clang] 15f0491 - [NFC] Fix a mem-sanitizer found issue in AutoType

2023-04-28 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2023-04-28T10:09:26-07:00
New Revision: 15f0491d3963d91202aef659acc20f59aa83fae7

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

LOG: [NFC] Fix a mem-sanitizer found issue in AutoType

We only need the list of constriant template arguments when we have a
valid constraint.  We give up on merging the auto-type constraints if
the template arguments don't match, but neglected to clear the
collection of template arguments.  The result was we had an AutoType
where we initialized the number of template arguments, but never
initialized the template arguments themselves.

This patch adds an assert to catch this in the future, plus ensures we
clear out the vector so we don't try to create the AutoType incorrectly.

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Type.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index e331df86235b2..6bc202ecd5b02 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -12982,8 +12982,10 @@ static QualType getCommonSugarTypeNode(ASTContext 
, const Type *X,
 SmallVector As;
 if (CD &&
 getCommonTemplateArguments(Ctx, As, AX->getTypeConstraintArguments(),
-   AY->getTypeConstraintArguments()))
+   AY->getTypeConstraintArguments())) {
   CD = nullptr; // The arguments 
diff er, so make it unconstrained.
+  As.clear();
+}
 
 // Both auto types can't be dependent, otherwise they wouldn't have been
 // sugar. This implies they can't contain unexpanded packs either.

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index e1686a7c69d52..c0d225034be89 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -4630,6 +4630,7 @@ AutoType::AutoType(QualType DeducedAsType, 
AutoTypeKeyword Keyword,
   AutoTypeBits.Keyword = (unsigned)Keyword;
   AutoTypeBits.NumArgs = TypeConstraintArgs.size();
   this->TypeConstraintConcept = TypeConstraintConcept;
+  assert(TypeConstraintConcept || AutoTypeBits.NumArgs == 0);
   if (TypeConstraintConcept) {
 auto *ArgBuffer =
 const_cast(getTypeConstraintArguments().data());



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


[PATCH] D149464: [clang][dataflow] Expose DataflowAnalysisContext from DataflowEnvironment.

2023-04-28 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.
This revision is now accepted and ready to land.

Thanks and welcome! :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149464

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


[PATCH] D148370: [Clang][Flang][OpenMP] Add loadOffloadInfoMetadata and createOffloadEntriesAndInfoMetadata into OMPIRBuilder's finalize and initialize

2023-04-28 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

rebase to see if it clears up the buildbot issue (currently the failing test 
appears to be unrelated and passes on my machine after a rebase)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148370

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


[PATCH] D149464: [clang][dataflow] Expose DataflowAnalysisContext from DataflowEnvironment.

2023-04-28 Thread Samira Bazuzi via Phabricator via cfe-commits
bazuzi created this revision.
bazuzi added reviewers: ymandel, gribozavr2.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
bazuzi requested review of this revision.
Herald added a project: clang.

This will eliminate the need for more pass-through APIs. Also replace 
pass-through usages with this exposure.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149464

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -53,9 +53,10 @@
   [UseBuiltinModel = Options.BuiltinOpts.has_value()](ASTContext ,
   Environment ) {
 return NoopAnalysis(
-C, DataflowAnalysisOptions{UseBuiltinModel
-   ? Env.getAnalysisOptions()
-   : std::optional()});
+C,
+DataflowAnalysisOptions{
+UseBuiltinModel ? Env.getDataflowAnalysisContext().getOptions()
+: std::optional()});
   });
   AI.ASTBuildArgs = ASTBuildArgs;
   if (Options.BuiltinOpts)
Index: clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
@@ -37,14 +37,16 @@
 
   static TestLattice initialElement() { return TestLattice{}; }
   void transfer(const CFGElement &, TestLattice , Environment ) {
-E.logger().log([](llvm::raw_ostream ) { OS << "transfer()"; });
+E.getDataflowAnalysisContext().getOptions().Log->log(
+[](llvm::raw_ostream ) { OS << "transfer()"; });
 ++L.Elements;
   }
   void transferBranch(bool Branch, const Stmt *S, TestLattice ,
   Environment ) {
-E.logger().log([&](llvm::raw_ostream ) {
-  OS << "transferBranch(" << Branch << ")";
-});
+E.getDataflowAnalysisContext().getOptions().Log->log(
+[&](llvm::raw_ostream ) {
+  OS << "transferBranch(" << Branch << ")";
+});
 ++L.Branches;
   }
 };
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -168,7 +168,8 @@
   llvm::ArrayRef>
   BlockStates)
   : CFCtx(CFCtx), Analysis(Analysis), InitEnv(InitEnv),
-Log(InitEnv.logger()), BlockStates(BlockStates) {
+Log(*InitEnv.getDataflowAnalysisContext().getOptions().Log),
+BlockStates(BlockStates) {
 Log.beginAnalysis(CFCtx, Analysis);
   }
   ~AnalysisContext() { Log.endAnalysis(); }
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -496,7 +496,7 @@
   }
 
   void VisitReturnStmt(const ReturnStmt *S) {
-if (!Env.getAnalysisOptions().ContextSensitiveOpts)
+if (!Env.getDataflowAnalysisContext().getOptions().ContextSensitiveOpts)
   return;
 
 auto *Ret = S->getRetValue();
@@ -863,12 +863,13 @@
   // `F` of `S`. The type `E` must be either `CallExpr` or `CXXConstructExpr`.
   template 
   void transferInlineCall(const E *S, const FunctionDecl *F) {
-const auto  = Env.getAnalysisOptions();
+const auto  = Env.getDataflowAnalysisContext().getOptions();
 if (!(Options.ContextSensitiveOpts &&
   Env.canDescend(Options.ContextSensitiveOpts->Depth, F)))
   return;
 
-const ControlFlowContext *CFCtx = Env.getControlFlowContext(F);
+const ControlFlowContext *CFCtx =
+Env.getDataflowAnalysisContext().getControlFlowContext(F);
 if (!CFCtx)
   return;
 
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -381,7 +381,7 @@
 
 QualType ParamType = Param->getType();
 if (ParamType->isReferenceType()) {
-  auto  = arena().create(*ArgLoc);
+  auto  = DACtx->arena().create(*ArgLoc);
   setValue(Loc, Val);
 } else if (auto 

[PATCH] D148370: [Clang][Flang][OpenMP] Add loadOffloadInfoMetadata and createOffloadEntriesAndInfoMetadata into OMPIRBuilder's finalize and initialize

2023-04-28 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon updated this revision to Diff 517968.
agozillon added a comment.

- Move hostIRFilePath initialize invocation to ModuleTranslation.cpp to respect 
TargetOp patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148370

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/CMakeLists.txt
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
  mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1259,19 +1259,23 @@
 llvm::OpenMPIRBuilder *ModuleTranslation::getOpenMPBuilder() {
   if (!ompBuilder) {
 ompBuilder = std::make_unique(*llvmModule);
-ompBuilder->initialize();
 
 bool isDevice = false;
+llvm::StringRef hostIRFilePath = "";
 if (auto offloadMod =
-dyn_cast(mlirModule))
+dyn_cast(mlirModule)) {
   isDevice = offloadMod.getIsDevice();
+  hostIRFilePath = offloadMod.getHostIRFilePath();
+}
+
+ompBuilder->initialize(hostIRFilePath);
 
 // TODO: set the flags when available
-llvm::OpenMPIRBuilderConfig Config(
+llvm::OpenMPIRBuilderConfig config(
 isDevice, /* IsTargetCodegen */ false,
 /* HasRequiresUnifiedSharedMemory */ false,
 /* OpenMPOffloadMandatory */ false);
-ompBuilder->setConfig(Config);
+ompBuilder->setConfig(config);
   }
   return ompBuilder.get();
 }
Index: mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
===
--- mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
+++ mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
@@ -15,6 +15,7 @@
 #define MLIR_TARGET_LLVMIR_MODULETRANSLATION_H
 
 #include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/IR/Operation.h"
 #include "mlir/IR/SymbolTable.h"
 #include "mlir/IR/Value.h"
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/Bitcode/BitcodeReader.h"
 #include "llvm/IR/CFG.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DebugInfoMetadata.h"
@@ -445,7 +446,28 @@
   return Fn;
 }
 
-void OpenMPIRBuilder::initialize() { initializeTypes(M); }
+void OpenMPIRBuilder::initialize(StringRef HostFilePath) {
+  initializeTypes(M);
+
+  if (!HostFilePath.empty()) {
+auto Buf = llvm::MemoryBuffer::getFile(HostFilePath);
+if (auto Err = Buf.getError())
+  assert(false && ("error opening host file from host file path inside of "
+   "OpenMPIRBuilder" +
+   Err.message())
+  .c_str());
+
+llvm::LLVMContext Ctx;
+auto M = llvm::expectedToErrorOrAndEmitErrors(
+Ctx, llvm::parseBitcodeFile(Buf.get()->getMemBufferRef(), Ctx));
+if (auto Err = M.getError())
+  assert(false && ("error parsing host file inside of OpenMPIRBuilder " +
+   Err.message())
+  .c_str());
+
+loadOffloadInfoMetadata(*M.get());
+  }
+}
 
 void OpenMPIRBuilder::finalize(Function *Fn) {
   SmallPtrSet ParallelRegionBlockSet;
@@ -534,6 +556,17 @@
 
   // Remove work items that have been completed.
   OutlineInfos = std::move(DeferredOutlines);
+
+  llvm::OpenMPIRBuilder::EmitMetadataErrorReportFunctionTy & =
+  [](llvm::OpenMPIRBuilder::EmitMetadataErrorKind kind,
+ const llvm::TargetRegionEntryInfo ) -> void {
+llvm::errs() << "Error of kind: " << kind
+ << " when emitting offload entries and metadata during "
+"OMPIRBuilder finalization \n";
+  };
+
+  if (!OffloadInfoManager.empty())
+createOffloadEntriesAndInfoMetadata(errorReportFn);
 }
 
 OpenMPIRBuilder::~OpenMPIRBuilder() {
Index: llvm/lib/Frontend/OpenMP/CMakeLists.txt
===
--- llvm/lib/Frontend/OpenMP/CMakeLists.txt
+++ llvm/lib/Frontend/OpenMP/CMakeLists.txt
@@ -19,4 +19,5 @@
   Analysis
   MC
   Scalar
+  BitReader
   )
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -419,7 +419,7 @@
   /// Initialize the internal state, this will put structures types and
   /// potentially other 

[PATCH] D149405: [Clang][Doc] Added an open project for improving command line docs

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

Thank you, this is a great suggestion! Just some minor wording changes, but 
otherwise LGTM.




Comment at: clang/www/OpenProjects.html:40-44
   other relevant information), or
+  improve existing and add missing documentation for
+  https://clang.llvm.org/docs/ClangCommandLineReference.html;>
+  clang command line flags, generated from https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td;>
+  clang/Driver/Options.td,




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149405

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


[PATCH] D149458: [Driver] Pass --target2= to linker from baremetal toolchain

2023-04-28 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149458

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


[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D149276#4305780 , @shafik wrote:

> I see that we do have an issue but so far the examples in the tests don't 
> feel very natural and so I would like to understand if there is a larger 
> motivation here.

The context is that a user realized we fail to implement P0849 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0849r8.html
and as a result we fail to compile simple range code 
https://godbolt.org/z/3ajj1c135 (this was observed by a user on the llvm 
discord and i don't think they made a github issue, unfortunately)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149276

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


[PATCH] D148381: [WIP][Clang] Add element_count attribute

2023-04-28 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:4170
+private:
+  mutable SmallVector CountFieldRanges;
+public:

`mutable`...my least favorite keyword in C++.  If you drop `const` from 
`addCountFieldSourceRange` then you don't need `mutable`.



Comment at: clang/include/clang/Basic/AttrDocs.td:7010
+/* ... */
+struct bar *fam[] __attribute__((element_count(bork, num_fam_elements)));
+  };

Question: does `bork` need to occur before `fam` for this substructure 
reference to work?

Does that mean that `element_count` is essentially variadic with this syntax?



Comment at: clang/lib/CodeGen/CGExpr.cpp:954
+if (const auto *MD = dyn_cast(ME->getMemberDecl())) {
+  if (const auto ECA = MD->getAttr()) {
+const RecordDecl *RD = MD->getParent();

`const auto *ECA = ...`



Comment at: clang/lib/CodeGen/CGExpr.cpp:961-963
+  for (FieldDecl *FD : RD->fields()) {
+if (FD->getName() != CountField->getName())
+  continue;

What happens if we never find the field? I guess that's checked below in 
`CheckElementCountAttr`? Do we need a diagnostic though?



Comment at: clang/lib/Sema/SemaDecl.cpp:17689-17701
+static const FieldDecl *FindFieldWithElementCountAttr(const RecordDecl *RD) {
+  for (const Decl *D : RD->decls()) {
+if (const auto *FD = dyn_cast(D))
+  if (FD->hasAttr())
+return FD;
+
+if (const auto *SubRD = dyn_cast(D))

I think if you made this static function instead be a method of RecordDecl, you 
could reuse it in clang/lib/CodeGen/CGExpr.cpp (in that for loop where you 
iterate `RD->fields`.

`FieldDecl *RecordDecl::getFieldWithName(StringRef Name);`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

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


[PATCH] D149461: [NFC] ][CLANG] Fix static code analyzer concerns

2023-04-28 Thread Soumi Manna via Phabricator via cfe-commits
Manna updated this revision to Diff 517964.

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

https://reviews.llvm.org/D149461

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp


Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1778,7 +1778,7 @@
 EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
   unsigned DataLen = 1 + 4 + 4;
-  for (auto ModInfo : Data.KnownHeaders)
+  for (const auto  : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
   if (Data.Unresolved.getPointer())
@@ -1839,7 +1839,7 @@
 }
   };
 
-  for (auto ModInfo : Data.KnownHeaders)
+  for (const auto  : Data.KnownHeaders)
 EmitModule(ModInfo.getModule(), ModInfo.getRole());
   if (Data.Unresolved.getPointer())
 EmitModule(Data.Unresolved.getPointer(), Data.Unresolved.getInt());
@@ -1884,7 +1884,7 @@
 
   // If the file didn't exist, we can still create a module if we were 
given
   // enough information in the module map.
-  for (auto U : M->MissingHeaders) {
+  for (const auto  : M->MissingHeaders) {
 // Check that we were given enough information to build a module
 // without this file existing on disk.
 if (!U.Size || (!U.ModTime && IncludeTimestamps)) {
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4425,7 +4425,7 @@
   Id->second->setOutOfDate(true);
   }
   // Mark selectors as out of date.
-  for (auto Sel : SelectorGeneration)
+  for (const auto  : SelectorGeneration)
 SelectorOutOfDate[Sel.first] = true;
 
   // Resolve any unresolved module exports.
@@ -7693,7 +7693,7 @@
   };
 
   if (isa(DC)) {
-for (auto Lexical : TULexicalDecls)
+for (const auto  : TULexicalDecls)
   Visit(Lexical.first, Lexical.second);
   } else {
 auto I = LexicalDecls.find(DC);
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1128,7 +1128,7 @@
   const auto I = FunctionGlobalizedDecls.find(CGF.CurFn);
   if (I != FunctionGlobalizedDecls.end()) {
 // Deallocate the memory for each globalized VLA object
-for (auto AddrSizePair :
+for (const auto  :
  llvm::reverse(I->getSecond().EscapedVariableLengthDeclsAddrs)) {
   CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
   CGM.getModule(), OMPRTL___kmpc_free_shared),


Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1778,7 +1778,7 @@
 EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
   unsigned DataLen = 1 + 4 + 4;
-  for (auto ModInfo : Data.KnownHeaders)
+  for (const auto  : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
   if (Data.Unresolved.getPointer())
@@ -1839,7 +1839,7 @@
 }
   };
 
-  for (auto ModInfo : Data.KnownHeaders)
+  for (const auto  : Data.KnownHeaders)
 EmitModule(ModInfo.getModule(), ModInfo.getRole());
   if (Data.Unresolved.getPointer())
 EmitModule(Data.Unresolved.getPointer(), Data.Unresolved.getInt());
@@ -1884,7 +1884,7 @@
 
   // If the file didn't exist, we can still create a module if we were given
   // enough information in the module map.
-  for (auto U : M->MissingHeaders) {
+  for (const auto  : M->MissingHeaders) {
 // Check that we were given enough information to build a module
 // without this file existing on disk.
 if (!U.Size || (!U.ModTime && IncludeTimestamps)) {
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4425,7 +4425,7 @@
   Id->second->setOutOfDate(true);
   }
   // Mark selectors as out of date.
-  for (auto Sel : SelectorGeneration)
+  for (const auto  : SelectorGeneration)
 SelectorOutOfDate[Sel.first] = true;
 
   // Resolve any unresolved module exports.
@@ -7693,7 +7693,7 @@
   };
 
   if (isa(DC)) {
-for (auto Lexical : TULexicalDecls)
+for (const auto  : TULexicalDecls)
   Visit(Lexical.first, 

[PATCH] D149461: [NFC] ][CLANG] Fix static code analyzer concerns

2023-04-28 Thread Soumi Manna via Phabricator via cfe-commits
Manna created this revision.
Manna added a reviewer: tahonermann.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Manna requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: jplehr, sstefan1.
Herald added a project: clang.

Reported by Coverity:

Inside "ASTReader.cpp" file,  in 
clang::​ASTReader::​FindExternalLexicalDecls(clang::​DeclContext const *, 
llvm::​function_ref, 
llvm::​SmallVectorImpl &): Using the auto keyword without an & 
causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an 
object of type pair.

2. Inside "ASTReader.cpp" file, in 
clang::​ASTReader::​ReadAST(llvm::​StringRef, 
clang::​serialization::​ModuleKind, clang::​SourceLocation, unsigned int, 
llvm::​SmallVectorImpl *): Using the 
auto keyword without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an 
object of type DenseMapPair.

3. Inside "CGOpenMPRuntimeGPU.cpp" file, in 
clang::​CodeGen::​CGOpenMPRuntimeGPU::​emitGenericVarsEpilog(clang::​CodeGen::​CodeGenFunction
 &, bool): Using the auto keyword without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an 
object of type pair.

4. In clang::​ASTWriter::​WriteHeaderSearch(clang::​HeaderSearch const &): 
Using the auto keyword without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an 
object of type UnresolvedHeaderDirective.

5. Inside "ASTWriter.cpp" file, in 
::​HeaderFileInfoTrait::​EmitData(llvm::​raw_ostream &, 
::​HeaderFileInfoTrait::​key_type const &, 
::​HeaderFileInfoTrait::​data_type const &, unsigned int): Using the 
auto keyword without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an 
object of type KnownHeader.

6. Inside "ASTWriter.cpp" file, In 
::​HeaderFileInfoTrait::​EmitKeyDataLength(llvm::​raw_ostream &, 
::​HeaderFileInfoTrait::​key_type const &, 
::​HeaderFileInfoTrait::​data_type const &): Using the auto keyword 
without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an 
object of type KnownHeader.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149461

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp


Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1778,7 +1778,7 @@
 EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
   unsigned DataLen = 1 + 4 + 4;
-  for (auto ModInfo : Data.KnownHeaders)
+  for (const auto  : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
   if (Data.Unresolved.getPointer())
@@ -1839,7 +1839,7 @@
 }
   };
 
-  for (auto ModInfo : Data.KnownHeaders)
+  for (const auto  : Data.KnownHeaders)
 EmitModule(ModInfo.getModule(), ModInfo.getRole());
   if (Data.Unresolved.getPointer())
 EmitModule(Data.Unresolved.getPointer(), Data.Unresolved.getInt());
@@ -1884,7 +1884,7 @@
 
   // If the file didn't exist, we can still create a module if we were 
given
   // enough information in the module map.
-  for (auto U : M->MissingHeaders) {
+  for (const auto  : M->MissingHeaders) {
 // Check that we were given enough information to build a module
 // without this file existing on disk.
 if (!U.Size || (!U.ModTime && IncludeTimestamps)) {
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4425,7 +4425,7 @@
   Id->second->setOutOfDate(true);
   }
   // Mark selectors as out of date.
-  for (auto Sel : SelectorGeneration)
+  for (const auto  : SelectorGeneration)
 SelectorOutOfDate[Sel.first] = true;
 
   // Resolve any unresolved module exports.
@@ -7693,7 +7693,7 @@
   };
 
   if (isa(DC)) {
-for (auto Lexical : TULexicalDecls)
+for (const auto  : TULexicalDecls)
   Visit(Lexical.first, Lexical.second);
   } else {
 auto I = LexicalDecls.find(DC);
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1128,7 +1128,7 @@
   const auto I = FunctionGlobalizedDecls.find(CGF.CurFn);
   if (I != FunctionGlobalizedDecls.end()) {
 // Deallocate the memory for each globalized VLA object
-for (auto AddrSizePair :
+for (const 

[PATCH] D149193: [Driver] Add -dumpdir and change -gsplit-dwarf .dwo names for linking

2023-04-28 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D149193#4302981 , @scott.linder 
wrote:

> I am OK to give LGTM, assuming the other reviewers don't still have 
> reservations?

Some - planning to get to this next week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149193

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


[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-28 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

I see that we do have an issue but so far the examples in the tests don't feel 
very natural and so I would like to understand if there is a larger motivation 
here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149276

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


[PATCH] D149460: [analyzer] ArrayBoundCheckerV2: suppress false positives from ctype macros

2023-04-28 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy created this revision.
donat.nagy added reviewers: gamesh411, Szelethus, steakhal, dkrupp.
Herald added subscribers: manas, ASDenysPetrov, martong, mikhail.ramalho, 
a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
donat.nagy requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The checker `alpha.security.ArrayBoundV2` created bug reports in situations 
when the (tainted) result of `fgetc()` or `getchar()` was passed to one of the 
`isX()` macros from ctype.h. This is a common input handling pattern 
(within the limited toolbox of the C language) and several open source projects 
contained code where it led to false positive reports; so this commit 
suppresses ArrayBoundV2 reports generated within the `isX()` macros. (Note 
that here even true positive reports would be difficult to understand, as 
they'd refer to the implementation details of these macros.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149460

Files:
  clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
  clang/test/Analysis/taint-generic.c


Index: clang/test/Analysis/taint-generic.c
===
--- clang/test/Analysis/taint-generic.c
+++ clang/test/Analysis/taint-generic.c
@@ -156,6 +156,28 @@
   Buffer[m] = 1;  //expected-warning {{Out of bound memory access (index is 
tainted)}}
 }
 
+extern const unsigned short int **__ctype_b_loc (void);
+enum { _ISdigit = 2048 };
+# define isdigit(c) ((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) 
_ISdigit)
+
+int isdigitImplFalsePositive(void) {
+  // If this code no longer produces a bug report, then consider removing the
+  // special case that disables buffer overflow reports coming from the isX
+  // macros in ctypes.h.
+  int c = getchar();
+  return ((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) _ISdigit);
+  //expected-warning@-1 {{Out of bound memory access (index is tainted)}}
+}
+
+int isdigitSuppressed(void) {
+  // Same code as above, but reports are suppressed based on macro name:
+  int c = getchar();
+  return isdigit(c); //no-warning
+}
+
+// Some later tests use isdigit as a function, so we need to undef it:
+#undef isdigit
+
 void testUncontrolledFormatString(char **p) {
   char s[80];
   fscanf(stdin, "%s", s);
Index: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
@@ -42,8 +42,10 @@
   void reportTaintOOB(CheckerContext , ProgramStateRef errorState,
   SVal TaintedSVal) const;
 
+  static bool isFromCtypeMacro(const Stmt *S, ASTContext );
+
 public:
-  void checkLocation(SVal l, bool isLoad, const Stmt*S,
+  void checkLocation(SVal l, bool isLoad, const Stmt *S,
  CheckerContext ) const;
 };
 
@@ -155,6 +157,15 @@
   // memory access is within the extent of the base region.  Since we
   // have some flexibility in defining the base region, we can achieve
   // various levels of conservatism in our buffer overflow checking.
+
+  // The header ctype.h (from e.g. glibc) implements the isX() macros as
+  //   #define isX(arg) (LOOKUP_TABLE[arg] & BITMASK_FOR_X)
+  // and incomplete analysis of these leads to false positives. As even
+  // accurate reports would be confusing for the users, just disable reports
+  // from these macros:
+  if (isFromCtypeMacro(LoadS, checkerContext.getASTContext()))
+return;
+
   ProgramStateRef state = checkerContext.getState();
 
   SValBuilder  = checkerContext.getSValBuilder();
@@ -267,6 +278,25 @@
   checkerContext.emitReport(std::move(BR));
 }
 
+bool ArrayBoundCheckerV2::isFromCtypeMacro(const Stmt *S, ASTContext ) {
+  SourceLocation Loc = S->getBeginLoc();
+  if (!Loc.isMacroID())
+return false;
+
+  StringRef MacroName = Lexer::getImmediateMacroName(
+  Loc, ACtx.getSourceManager(), ACtx.getLangOpts());
+
+  if (MacroName.size() < 7 || MacroName[0] != 'i' || MacroName[1] != 's')
+return false;
+
+  return ((MacroName == "isalnum") || (MacroName == "isalpha") ||
+  (MacroName == "isblank") || (MacroName == "isdigit") ||
+  (MacroName == "isgraph") || (MacroName == "islower") ||
+  (MacroName == "isnctrl") || (MacroName == "isprint") ||
+  (MacroName == "ispunct") || (MacroName == "isspace") ||
+  (MacroName == "isupper") || (MacroName == "isxdigit"));
+}
+
 #ifndef NDEBUG
 LLVM_DUMP_METHOD void RegionRawOffsetV2::dump() const {
   dumpToStream(llvm::errs());


Index: clang/test/Analysis/taint-generic.c
===
--- clang/test/Analysis/taint-generic.c
+++ clang/test/Analysis/taint-generic.c
@@ -156,6 +156,28 @@
   Buffer[m] = 1;  

[PATCH] D147626: [clang] Reject flexible array member in a union in C++

2023-04-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:58
   Clang will only search for std::coroutine_traits for coroutines then.
+- Clang doesn't accept flexible array members in unions in C++ anymore.
 





Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6241-6244
 def ext_flexible_array_empty_aggregate_ms : Extension<
   "flexible array member %0 in otherwise empty "
   "%select{struct|interface|union|class|enum}1 is a Microsoft extension">,
   InGroup;

Should this be updated to remove the union case?



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6252
   "flexible array member %0 in otherwise empty "
   "%select{struct|interface|union|class|enum}1 is a GNU extension">,
   InGroup;

Same question here



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6255
-def ext_flexible_array_union_gnu : Extension<
-  "flexible array member %0 in a union is a GNU extension">, 
InGroup;
 

This was the last use of this diagnostic group, so we can remove it from 
`DiagnosticGroups.td` as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147626

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


[PATCH] D149458: [Driver] Pass --target2= to linker from baremetal toolchain

2023-04-28 Thread Peter Smith via Phabricator via cfe-commits
peter.smith accepted this revision.
peter.smith added a comment.
This revision is now accepted and ready to land.

LGTM. This is consistent with the target2 support that I added to LLD several 
years ago in https://reviews.llvm.org/D25684 will be good to give some time for 
other reviewers to add any comments/objections before committing.

Other references:

- aaelf32 
https://github.com/ARM-software/abi-aa/blob/main/aaelf32/aaelf32.rst#5617static-miscellaneous-relocations
- ehabi32 
https://github.com/ARM-software/abi-aa/blob/main/ehabi32/ehabi32.rst#542relocations

The latter states that ABS is the right value for bare-metal, but I think it 
ended up being implemented as REL for the GNU bare-metal personality routines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149458

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


[PATCH] D149162: [Clang][OpenMP][IRBuilder] Move registerTargetGlobalVariable & getAddrOfDeclareTargetVar into the OMPIRBuilder

2023-04-28 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

rebased and clang-formatted the *hopefully* final file clang-format is angry at.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149162

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


[PATCH] D149162: [Clang][OpenMP][IRBuilder] Move registerTargetGlobalVariable & getAddrOfDeclareTargetVar into the OMPIRBuilder

2023-04-28 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon updated this revision to Diff 517958.
agozillon added a comment.

- [Clang][OpenMP][IRBuilder] Tidy up function calls with helpful reviewer advice
- [Clang][OpenMP][IRBuilder] Replace all getTargetEntryUniqueInfo with 
IRBuilder version
- [Clang][OpenMP][IRBuilder] Run clang-format and tidy up files
- Run clang-format on offending file breaking build process


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149162

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -32,6 +32,7 @@
 #include "llvm/IR/Value.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
@@ -5081,7 +5082,8 @@
   static_cast(
   CE->getFlags());
   switch (Flags) {
-  case OffloadEntriesInfoManager::OMPTargetGlobalVarEntryTo: {
+  case OffloadEntriesInfoManager::OMPTargetGlobalVarEntryEnter:
+  case OffloadEntriesInfoManager::OMPTargetGlobalVarEntryTo:
 if (Config.isEmbedded() && Config.hasRequiresUnifiedSharedMemory())
   continue;
 if (!CE->getAddress()) {
@@ -5092,7 +5094,6 @@
 if (CE->getVarSize() == 0)
   continue;
 break;
-  }
   case OffloadEntriesInfoManager::OMPTargetGlobalVarEntryLink:
 assert(((Config.isEmbedded() && !CE->getAddress()) ||
 (!Config.isEmbedded() && CE->getAddress())) &&
@@ -5104,6 +5105,8 @@
   continue;
 }
 break;
+  default:
+break;
   }
 
   // Hidden or internal symbols on the device are not externally visible.
@@ -5140,6 +5143,157 @@
   EntryInfo.Line, NewCount);
 }
 
+TargetRegionEntryInfo
+OpenMPIRBuilder::getTargetEntryUniqueInfo(StringRef FileName, uint64_t Line,
+  StringRef ParentName) {
+  llvm::sys::fs::UniqueID ID;
+  if (auto EC = llvm::sys::fs::getUniqueID(FileName, ID)) {
+assert(EC &&
+   "Unable to get unique ID for file, during getTargetEntryUniqueInfo");
+  }
+  return llvm::TargetRegionEntryInfo(ParentName, ID.getDevice(), ID.getFile(),
+ Line);
+}
+
+Constant *OpenMPIRBuilder::getAddrOfDeclareTargetVar(
+OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
+OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
+bool IsDeclaration, bool IsExternallyVisible,
+TargetRegionEntryInfo EntryInfo, StringRef MangledName, Module *LlvmModule,
+std::vector , bool OpenMPSIMD,
+std::vector TargetTriple, Type *LlvmPtrTy,
+std::function GlobalInitializer,
+std::function VariableLinkage) {
+  // TODO: convert this to utilise the IRBuilder Config rather than
+  // a passed down argument.
+  if (OpenMPSIMD)
+return nullptr;
+
+  if (CaptureClause == OffloadEntriesInfoManager::OMPTargetGlobalVarEntryLink ||
+  ((CaptureClause == OffloadEntriesInfoManager::OMPTargetGlobalVarEntryTo ||
+CaptureClause ==
+OffloadEntriesInfoManager::OMPTargetGlobalVarEntryEnter) &&
+   Config.hasRequiresUnifiedSharedMemory())) {
+SmallString<64> PtrName;
+{
+  llvm::raw_svector_ostream OS(PtrName);
+  OS << MangledName;
+  if (!IsExternallyVisible)
+OS << llvm::format("_%x", EntryInfo.FileID);
+  OS << "_decl_tgt_ref_ptr";
+}
+
+llvm::Value *Ptr = LlvmModule->getNamedValue(PtrName);
+
+if (!Ptr) {
+  llvm::GlobalValue *GlobalValue = LlvmModule->getNamedValue(MangledName);
+  Ptr = getOrCreateInternalVariable(LlvmPtrTy, PtrName);
+
+  auto *GV = cast(Ptr);
+  GV->setLinkage(llvm::GlobalValue::WeakAnyLinkage);
+
+  if (!Config.isEmbedded()) {
+if (GlobalInitializer)
+  GV->setInitializer(GlobalInitializer());
+else
+  GV->setInitializer(GlobalValue);
+  }
+
+  registerTargetGlobalVariable(
+  CaptureClause, DeviceClause, IsDeclaration, IsExternallyVisible,
+  EntryInfo, MangledName, LlvmModule, GeneratedRefs, OpenMPSIMD,
+  TargetTriple, GlobalInitializer, VariableLinkage, LlvmPtrTy,
+  cast(Ptr));
+}
+
+return cast(Ptr);
+  }
+
+  return nullptr;
+}
+
+void OpenMPIRBuilder::registerTargetGlobalVariable(
+OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
+OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
+bool IsDeclaration, bool IsExternallyVisible,
+TargetRegionEntryInfo EntryInfo, llvm::StringRef MangledName,
+   

[PATCH] D149458: [Driver] Pass --target2= to linker from baremetal toolchain

2023-04-28 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki created this revision.
miyuki added reviewers: peter.smith, phosek, michaelplatings.
Herald added subscribers: abidh, kristof.beyls.
Herald added a project: All.
miyuki requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

According to the GNU ld manual
https://sourceware.org/binutils/docs/ld/ARM.html#ARM the R_ARM_TARGET2
relocation (used in exception handling tables) is treated differently
depending on the target. By default, LLD treats R_ARM_TARGET2 as
R_ARM_GOT_PREL (--target2=got-rel), which is correct for Linux but not
for embedded targets.

This patch adds --target2=rel to linker options in the baremetal
toolchain driver so that on baremetal targets, R_ARM_TARGET2 is
treated as R_ARM_REL32. Such behavior is compatible with GNU ld and
unwinding libraries (e.g., libuwind).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149458

Files:
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal.cpp


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -15,7 +15,7 @@
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" 
"-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
-// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"{{.*}}.tmp.out"
+// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "--target2=rel" 
"-o" "{{.*}}.tmp.out"
 
 // RUN: %clang %s -### --target=armv6m-none-eabi -nostdlibinc -nobuiltininc 
2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-LIBINC %s
@@ -42,7 +42,7 @@
 // CHECK-V6M-DEFAULTCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-DEFAULTCXX-SAME: 
"-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
-// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"a.out"
+// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi -stdlib=libc++ 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-LIBCXX %s
@@ -53,7 +53,7 @@
 // CHECK-V6M-LIBCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
-// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" "a.out"
+// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
@@ -66,7 +66,7 @@
 // CHECK-V6M-LIBSTDCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBSTDCXX-SAME: 
"-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind"
-// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"a.out"
+// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" 
"--target2=rel" "-o" "a.out"
 
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -342,6 +342,12 @@
   if (TC.getTriple().isRISCV())
 CmdArgs.push_back("-X");
 
+  // The R_ARM_TARGET2 relocation must be treated as R_ARM_REL32 on arm*-*-elf
+  // and arm*-*-eabi (the default is R_ARM_GOT_PREL, used on arm*-*-linux and
+  // arm*-*-*bsd).
+  if (isARMBareMetal(TC.getTriple()))
+CmdArgs.push_back("--target2=rel");
+
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -15,7 +15,7 @@
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" "-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
-// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" "{{.*}}.tmp.out"
+// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "--target2=rel" "-o" "{{.*}}.tmp.out"
 
 // RUN: %clang %s -### --target=armv6m-none-eabi -nostdlibinc -nobuiltininc 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 

[PATCH] D149259: [analyzer][NFC] Use std::optional instead of custom "empty" state

2023-04-28 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy marked an inline comment as done.
donat.nagy added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149259

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


[PATCH] D142967: [clangd] Introduce source.organizeImports code action.

2023-04-28 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 517948.
hokein added a comment.

rebase and polish the implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142967

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

Index: clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
===
--- clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
+++ clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
@@ -112,7 +112,7 @@
 # CHECK-NEXT: "version": 0
 # CHECK-NEXT:   }
 ---
-{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///simple.cpp"},"range":{"start":{"line":2,"character":1},"end":{"line":2,"character":4}},"context":{"diagnostics":[{"range":{"start": {"line": 2, "character": 1}, "end": {"line": 2, "character": 4}},"severity":2,"message":"No header providing \"Foo\" is directly included (fixes available)", "code": "missing-includes", "source": "clangd"}]}}}
+{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///simple.cpp"},"range":{"start":{"line":2,"character":1},"end":{"line":2,"character":4}},"context":{"only":["quickfix"], "diagnostics":[{"range":{"start": {"line": 2, "character": 1}, "end": {"line": 2, "character": 4}},"severity":2,"message":"No header providing \"Foo\" is directly included (fixes available)", "code": "missing-includes", "source": "clangd"}]}}}
 #  CHECK:  "id": 2,
 # CHECK-NEXT:  "jsonrpc": "2.0",
 # CHECK-NEXT:  "result": [
@@ -297,7 +297,7 @@
 # CHECK-NEXT:}
 # CHECK-NEXT:  ]
 ---
-{"jsonrpc":"2.0","id":3,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///simple.cpp"},"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":17}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 17}},"severity":2,"message":"Included header all1.h is not used directly (fixes available)", "code": "unused-includes", "source": "clangd"}]}}}
+{"jsonrpc":"2.0","id":3,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///simple.cpp"},"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":17}},"context":{"only":["quickfix"], "diagnostics":[{"range":{"start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 17}},"severity":2,"message":"Included header all1.h is not used directly (fixes available)", "code": "unused-includes", "source": "clangd"}]}}}
 #  CHECK:  "id": 3,
 # CHECK-NEXT:  "jsonrpc": "2.0",
 # CHECK-NEXT:  "result": [
Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -1076,6 +1076,7 @@
   const static llvm::StringLiteral QUICKFIX_KIND;
   const static llvm::StringLiteral REFACTOR_KIND;
   const static llvm::StringLiteral INFO_KIND;
+  const static llvm::StringLiteral SOURCE_ORGANIZE_IMPORT;
 
   /// The diagnostics that this code action resolves.
   std::optional> diagnostics;
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -867,6 +867,7 @@
 const llvm::StringLiteral CodeAction::QUICKFIX_KIND = "quickfix";
 const llvm::StringLiteral CodeAction::REFACTOR_KIND = "refactor";
 const llvm::StringLiteral CodeAction::INFO_KIND = "info";
+const llvm::StringLiteral CodeAction::SOURCE_ORGANIZE_IMPORT = "source.organizeImports";
 
 llvm::json::Value toJSON(const CodeAction ) {
   auto CodeAction = llvm::json::Object{{"title", CA.title}};
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -23,6 +23,7 @@
 #include "clang-include-cleaner/Types.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
 #include 
 #include 
@@ -46,6 +47,11 @@
   std::vector UnusedIncludes;
   std::vector MissingIncludes;
 };
+inline constexpr llvm::StringLiteral RemoveAllUnusedMessage =
+"remove all unused includes";
+inline constexpr llvm::StringLiteral AddAllMissingIncludesMessage =
+"add all missing includes";
+inline constexpr llvm::StringLiteral FixAllIncludesMessage = "fix all includes";
 
 /// Retrieves headers that are referenced from the main file but not used.
 /// In unclear cases, headers are not marked as unused.
Index: 

[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a subscriber: rsmith.
cor3ntin added a comment.

@rsmith @hubert.reinterpretcast do you see any reason not to go ahead with this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149276

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


[PATCH] D149456: Basic documentation of -mrecip=... option

2023-04-28 Thread Tim Schmielau via Phabricator via cfe-commits
tim.schmielau created this revision.
Herald added a project: All.
tim.schmielau requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The documentation is still rather terse because it needs to fit
onto a single line of clang --help output.
But at least it lists what the user can specify and documents the
non-obvious syntax.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149456

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


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3957,8 +3957,12 @@
 def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group,
   HelpText<"Don't generate implicit floating point or vector instructions">;
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
-def mrecip : Flag<["-"], "mrecip">, Group;
+def mrecip : Flag<["-"], "mrecip">, Group,
+  HelpText<"Equivalent to '-mrecip=all'">;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Control use of approximate reciprocal and reciprocal square root 
instructions followed by  iterations of "
+   "Newton-Raphson refinement. "
+   " = ( ['!'] ['vec-'] ('rcp'|'sqrt') [('h'|'s'|'d')] [':'] 
) | 'all' | 'default' | 'none'">,
   MarshallingInfoStringVector>;
 def mprefer_vector_width_EQ : Joined<["-"], "mprefer-vector-width=">, 
Group, Flags<[CC1Option]>,
   HelpText<"Specifies preferred vector width for auto-vectorization. Defaults 
to 'none' which allows target specific decisions.">,


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3957,8 +3957,12 @@
 def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group,
   HelpText<"Don't generate implicit floating point or vector instructions">;
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
-def mrecip : Flag<["-"], "mrecip">, Group;
+def mrecip : Flag<["-"], "mrecip">, Group,
+  HelpText<"Equivalent to '-mrecip=all'">;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, Flags<[CC1Option]>,
+  HelpText<"Control use of approximate reciprocal and reciprocal square root instructions followed by  iterations of "
+   "Newton-Raphson refinement. "
+   " = ( ['!'] ['vec-'] ('rcp'|'sqrt') [('h'|'s'|'d')] [':'] ) | 'all' | 'default' | 'none'">,
   MarshallingInfoStringVector>;
 def mprefer_vector_width_EQ : Joined<["-"], "mprefer-vector-width=">, Group, Flags<[CC1Option]>,
   HelpText<"Specifies preferred vector width for auto-vectorization. Defaults to 'none' which allows target specific decisions.">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149259: [analyzer][NFC] Use std::optional instead of custom "empty" state

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

Sure, Ill look at this on Tuesday.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149259

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


[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Interpreter/Interpreter.h:96
+
+  size_t getEffectivePTUSize() const;
+

It looks like this can be private?

Also, just a note (not something you have to deal with in this review), the 
local naming convention seems to have decided that if the function starts with 
`get` then it's camel case and otherwise the name is pascal case.



Comment at: clang/include/clang/Interpreter/Value.h:104-108
+  void setKind(Kind K) { ValueKind = K; }
+  void setOpaqueType(void *Ty) { OpaqueType = Ty; }
+
+  void *getPtr() const;
+  void setPtr(void *Ptr) { Data.m_Ptr = Ptr; }

If we can't get type safety through construction, should we consider adding 
assertions here that a value's kind and opaque type agree, or that we're not 
changing the type or kind without also changing the pointer?



Comment at: clang/include/clang/Interpreter/Value.h:46
+
+#define REPL_BUILTIN_TYPES 
\
+  X(bool, Bool)
\

v.g.vassilev wrote:
> aaron.ballman wrote:
> > Is this expected to be a complete list of builtin types? e.g., should this 
> > have `char8_t` and `void` and `wchar_t`, etc? Should this be including 
> > `clang/include/clang/AST/BuiltinTypes.def` instead of manually maintaining 
> > the list?
> This is used for various things including storing the bits into a big-endian 
> agnostic way. For `void` we have a special case in the Value and we cannot 
> define a union of a `void` type. We can include the others that you suggest. 
> All the relevant ones are described in `clang::BuiltinType::getName`.
> 
> We cannot use `BuiltinTypes.def` because we want to have a mapping between 
> the type as written in the language (eg, `bool`, `unsigned`, etc) and its 
> underlying type name. That mapping is not available in `BuiltinTypes.def`. 
> Ideally we should extend `BuiltinTypes.def` somehow but I'd prefer outside of 
> this patch. One of the challenges is that some of the types depend on the 
> language options (eg. `_Bool` vs `bool`) and I am not sure this can be 
> resolved by tablegen.
> 
> On a broader perspective, the `Value` class is responsible for two things: 
> (a) get a value from the interpreter to compiled code (see test case); (b) 
> set a value from compiled code to the interpreter. The second case is not yet 
> covered (I can open soon another patch). The major use-case is calling at 
> runtime functions and taking input parameters from compiled code.
> 
> FWIW, we should probably move all of these entities in a separate namespace. 
> I'd suggest `caas` (compiler-as-a-service) and possibly rename the `Value` to 
> `InterpreterValue` since `Value` is very generic and there are already a 
> couple of classes with that name in llvm and clang. 
> We can include the others that you suggest. All the relevant ones are 
> described in clang::BuiltinType::getName.

Okay, so the plan is to handle all the builtin types (`_BitInt`, `_Complex`, 
various floating point formats, etc)? Will that be part of this patch or in 
follow-up work? (My intuition is that we should consider it up front because 
some of the builtin types are interesting -- like `_BitInt` because it's 
parameterized, which makes it novel compared to the other types.)

> We cannot use BuiltinTypes.def because we want to have a mapping between the 
> type as written in the language (eg, bool, unsigned, etc) and its underlying 
> type name. That mapping is not available in BuiltinTypes.def. Ideally we 
> should extend BuiltinTypes.def somehow but I'd prefer outside of this patch. 
> One of the challenges is that some of the types depend on the language 
> options (eg. _Bool vs bool) and I am not sure this can be resolved by 
> tablegen.

Thanks for the explanation! BuiltinTypes.def works well enough for times when 
we want to use macros and include the file to generate switch cases and the 
likes, but you're right that it's not well-suited for this. One thing to 
consider is whether we should change `BuiltinTypes.def` to be `BuiltinTypes.td` 
instead and use tablegen to generate the macro/include dance form as well as 
other output (such as for your needs, that can then consider language options 
or more complex predicates).

> FWIW, we should probably move all of these entities in a separate namespace. 
> I'd suggest caas (compiler-as-a-service) and possibly rename the Value to 
> InterpreterValue since Value is very generic and there are already a couple 
> of classes with that name in llvm and clang.

I'm not in love with the name `caas` because that's not really a common acronym 
or abbreviation (and it looks like a typo due to `aa`). However, we already 
have an `interp` namespace in Clang for one of the other interpreters (constant 
expression evaluation), so that's not available for use. 

[PATCH] D148822: [clang][BFloat] Avoid redefining bfloat16_t in arm_neon.h

2023-04-28 Thread Dimitry Andric via Phabricator via cfe-commits
dim added a comment.

In D148822#4305188 , @simonbutcher 
wrote:

> I can't see anything wrong with this patch and it looks pretty 
> straightforward to me, but is it necessary?
>
> '-Wtypedef-redefinition' is documented as not applying to system headers 
> ,
>  and I couldn't reproduce the issue unless I changed the headers to not be 
> system headers.

I think this due to the way some parts of FreeBSD get compiled, where we 
definitely use -Wsystem-headers. It is likely that this warning (which was 
turned into an error because parts of the tree also get compiled with -Werror) 
came through because of that. In any case, there is no need to redefine 
bfloat16_t, at least not here. Another option is to add yet another define like 
`__bfloat_16_defined` and test for that, but it only makes things uglier.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148822

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


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-04-28 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis planned changes to this revision.
TIFitis added a comment.

@kiranchandramohan I am in the process of submitting a new patch for review 
which moves the map processing from Clang Codegen to OMPIRBuilder. Once that is 
moved we can just use that for dealing with the map operands.
Thus putting this patch on hold for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

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


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-04-28 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 517921.
TIFitis added a comment.

Rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -12,28 +12,24 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
 // CHECK-LABEL: define void @_QPopenmp_target_data() {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
-// CHECK: br label %[[VAL_4:.*]]
-// CHECK:   [[VAL_4]]:
+// CHECK: %[[VAL_2:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
 // CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_5]], align 8
+// CHECK: store ptr %[[VAL_2]], ptr %[[VAL_5]], align 8
 // CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_7]], align 4
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_8]], ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
-// CHECK: store i32 99, ptr %[[VAL_3]], align 4
-// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_12:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_13:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_11]], ptr %[[VAL_12]], ptr %[[VAL_13]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store ptr %[[VAL_2]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_7]], ptr %[[VAL_8]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store i32 99, ptr %[[VAL_2]], align 4
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
 // CHECK: ret void
 
 // -
@@ -52,34 +48,30 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4096]
 // CHECK-LABEL: define void @_QPopenmp_target_data_region
 // CHECK: (ptr %[[ARG_0:.*]]) {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: br label %[[VAL_3:.*]]
-// CHECK:   [[VAL_3]]:
+// CHECK: br label %[[VAL_2:.*]]
+// CHECK:   entry:; preds = %[[VAL_3:.*]]
 // CHECK: %[[VAL_4:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_5:.*]], ptr 

[PATCH] D149364: [CUDA] Temporarily undefine __noinline__ when including bits/shared_ptr_base.h

2023-04-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.

LGTM.

This issue does not affect HIP as HIP headers have removed `__noinline__` as a 
macro since https://reviews.llvm.org/D124866 and 
`__attribute__((__noinline__))` is equivalent to `__attribute__((noinline))` 
for HIP.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149364

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


[PATCH] D148663: [RFC][clangd] Use interpolation for CDB pushed via LSP protocol

2023-04-28 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.

In D148663#4305202 , @ilya-biryukov 
wrote:

> In D148663#4301589 , 
> @DmitryPolukhin wrote:
>
>> And, if they do so, this diff will just does nothing because there is an 
>> exact match. It starts playing only if client provided partial CDB and 
>> inference is required.
>
> (hypothesising below)
> I think this depends on a client at question. If I were writing one and had 
> an idea what I want to do for headers, e.g. I might have a project system 
> that knows which build targets headers belong to,
> I would rather see no compile errors for a header (if I have bugs in my 
> integration) than for Clangd to kick in with interpolation and silently hide 
> the bug.
>
> From what I can recollect, your case is different and you just want to "pipe" 
> `compile_commands.json` to Clangd provided by some build system, but without 
> `clangd` actually reading it.
> I don't actually write an LSP client, though, would let @kadircet decide 
> which path is preferable.

We have LSP client that works like a proxy and exposes LSP protocol to higher 
level. Now we do very deep processing of CDB and partially replicates logic 
clangd about command inference.
Clangd usually does good job in command inference and we would like to use this 
feature instead of keep our logic up-to-date. I can put this inference logic 
for LSP behind some command line flag
if you think that it might really break some good use case. Please let me know.

>> Pushing command via LSP might be preferable in comparison with file based 
>> approach to avoid race condition with updating the file and clangd reading it
>
> Ideally this should be handled with atomic writes (write to temp file and 
> move to destination), at least on Linux and Mac. I'm not sure if build 
> systems do that, though.
> Does Clangd ever re-read the compilation database now? It used to load it 
> only once, so rereading would require a restart of clangd anyway. Race on 
> just one read is very unlikely (although not impossible).
> However, the `compile_commands.json` file is parsed lazily, when the command 
> for a particular file is actually requested, if you see crashes or 
> inconsistencies in your scenarios, it highly likely due to this.

Yes, clangd re-read CDB in some cases but it won't try to read CDB again from a 
directory if there was none before for performance reasons I think. I think 
synchronisation here is hard we cannot control when
clangd will actually read CDB so it might use wrong flags. Also we run multiple 
clangd behind multiplexing proxy and they might need different CDBs. Also CDB 
tends to become large and hard to manage so
per-file LSP protocol has lots of advantages for us.

>> + it works better with build systems that can generate compiles commands on 
>> the fly for files and generating all of them in advance may not be possible.
>
> FYI, there is separate support for pushing command per-file in Clangd via an 
> LSP extension 
> .
> I think this should cover build systems that generate commands on the fly 
> better, but this also does not use interpolation.

It is exactly the LSP protocol we are using and I added inference.

> A meta-comment: it would be really useful to understand how you use Clangd a 
> bit better. Would it be hard to write down which kind of client you have and 
> what are requirements for Clangd? Which build systems are at play, how does 
> the client use them, etc?
> To validate whether patches like this one are a good fit to solve the problem 
> or there are better ways, it's really useful to have a higher level overview 
> of how Clangd is being used.

We use Buck  and Buck2  as our main 
build system + some projects uses other build systems like CMake, and in 
general we don't limit build systems that subproject might use.
Therefore we cannot limit ourself to any particular clangd version and had to 
support multiple of them simultaneously because individual projects might might 
use incompatible features. So we have a LSP multiplexing proxy that 
encapsulates build system specifics and combines results from several clangds. 
Changes in clangd that we would like to put in upstream in our understanding 
should be usable not only in our setup but should also improve clangd for all 
users.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148663

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


[PATCH] D149436: [clang] Do not attempt to zero-extend _BitInt(1) when not required

2023-04-28 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

This looks right to me, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149436

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


[PATCH] D149447: [clang][analyzer] Improve documentation of StdCLibraryFunctionArgs checker (NFC)

2023-04-28 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, gamesh411, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Documentation is made more exact, term "constraint" is removed entirely,
description of checker option is corrected.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149447

Files:
  clang/docs/analyzer/checkers.rst

Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -2434,7 +2434,7 @@
 
   void test_alnum_concrete(int v) {
 int ret = isalnum(256); // \
-// warning: Function argument constraint is not satisfied
+// warning: Function argument outside of allowed range
 (void)ret;
   }
 
@@ -2456,24 +2456,25 @@
 If the user disables the checker then the argument violation warning is
 suppressed. However, the assumption about the argument is still modeled. This
 is because exploring an execution path that already contains undefined behavior
-is not valuable.
+is not valuable. This applies to all the restrictions that are listed below.
 
-There are different kind of constraints modeled: range constraint, not null
-constraint, buffer size constraint. A **range constraint** requires the
-argument's value to be in a specific range, see ``isalnum`` as an example above.
-A **not null constraint** requires the pointer argument to be non-null.
-
-A **buffer size** constraint specifies the minimum size of the buffer
-argument. The size might be a known constant. For example, ``asctime_r`` requires
-that the buffer argument's size must be greater than or equal to ``26`` bytes. In
-other cases, the size is denoted by another argument or as a multiplication of
-two arguments.
-For instance, ``size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)``.
-Here, ``ptr`` is the buffer, and its minimum size is ``size * nmemb``
+There may be different restrictions about values passed as function arguments.
+ - The argument has an allowed range (or multiple ranges) of values. The checker
+   can detect if a passed value is outside of the allowed range and show the
+   actual and allowed values.
+ - The argument has pointer type and is not allowed to be null pointer. Many
+   (but not all) standard functions can produce undefined behavior if a null
+   pointer is passed, these cases can be detected by the checker.
+ - The argument is a pointer to a memory block and the minimal size of this
+   buffer is determined by another argument to the function, or by
+   multiplication of two arguments (like at function ``fread``), or is a fixed
+   value (for example ``asctime_r`` requires at least a buffer of size 26). The
+   checker can detect if the buffer size is too small and in optimal case show
+   the size of the buffer and the values of the corresponding arguments.
 
 .. code-block:: c
 
-  void buffer_size_constraint_violation(FILE *file) {
+  void buffer_size_violation(FILE *file) {
 enum { BUFFER_SIZE = 1024 };
 wchar_t wbuf[BUFFER_SIZE];
 
@@ -2486,22 +2487,62 @@
 fread(wbuf, size, nitems, file);
   }
 
+**List of checked functions**
+
+``fgetc``, ``fread``, ``fwrite``, ``getc``, ``getchar``, ``getdelim``,
+``getenv``, ``getline``, ``isalnum``, ``isalpha``, ``isascii``, ``isblank``,
+``isdigit``, ``isgraph``, ``islower``, ``isprint``, ``ispunct``, ``isspace``,
+``isupper``, ``isxdigit``, ``read``, ``toascii``, ``tolower``, ``toupper``,
+``write``
+
+Additional functions in POSIX mode (see Parameters below):
+
+``a64l``, ``accept``, ``access``, ``alarm``, ``asctime_r``, ``bind``, ``chdir``,
+``chmod``, ``chown``, ``clock_gettime``, ``close``, ``closedir``, ``connect``,
+``creat``, ``ctime_r``, ``dirfd``, ``dup``, ``dup2``, ``execv``, ``execvp``,
+``faccessat``, ``fchmod``, ``fchmodat``, ``fchown``, ``fchownat``, ``fclose``,
+``fdatasync``, ``fdopen``, ``fdopendir``, ``fileno``, ``fileno``, ``fnmatch``,
+``fopen``, ``fpathconf``, ``freopen``, ``fseek``, ``fseeko``, ``fstat``,
+``fstatat``, ``fsync``, ``ftello``, ``futimens``, ``getcwd``, ``getitimer``,
+``getnameinfo``, ``getopt``, ``getpeername``, ``getsockname``, ``getsockopt``,
+``gmtime``, ``gmtime_r``, ``isatty``, ``l64a``, ``lchown``, ``link``,
+``linkat``, ``listen``, ``localtime``, ``localtime_r``, ``lockf``, ``lseek``,
+``lstat``, ``mkdir``, ``mkdirat``, ``mkdtemp``, ``mknod``, ``mknodat``,
+``mkstemp``, ``mmap``, ``mmap64``, ``nanosleep``, ``opendir``, ``pathconf``,
+``pclose``, ``pipe``, ``popen``, ``pthread_attr_destroy``,
+``pthread_attr_getguardsize``, ``pthread_attr_getstacksize``,
+``pthread_attr_init``, ``pthread_attr_setguardsize``,
+``pthread_attr_setstacksize``, ``pthread_cond_broadcast``,
+``pthread_cond_signal``, 

[PATCH] D147626: [clang] Reject flexible array member in a union in C++

2023-04-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147626

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


[PATCH] D146269: MIPS: allow o32 abi with 64bit CPU and 64 abi with 32bit triple

2023-04-28 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa updated this revision to Diff 517903.

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

https://reviews.llvm.org/D146269

Files:
  clang/lib/Basic/Targets/Mips.cpp
  clang/test/Driver/mips-abi.c
  clang/test/Driver/mips-cpu64abi32.c
  llvm/lib/Target/Mips/MipsSubtarget.cpp

Index: llvm/lib/Target/Mips/MipsSubtarget.cpp
===
--- llvm/lib/Target/Mips/MipsSubtarget.cpp
+++ llvm/lib/Target/Mips/MipsSubtarget.cpp
@@ -104,8 +104,7 @@
 report_fatal_error("Code generation for MIPS-V is not implemented", false);
 
   // Check if Architecture and ABI are compatible.
-  assert(((!isGP64bit() && isABI_O32()) ||
-  (isGP64bit() && (isABI_N32() || isABI_N64( &&
+  assert(((!isGP64bit() && isABI_O32()) || isGP64bit()) &&
  "Invalid  Arch & ABI pair.");
 
   if (hasMSA() && !isFP64bit())
Index: clang/test/Driver/mips-cpu64abi32.c
===
--- /dev/null
+++ clang/test/Driver/mips-cpu64abi32.c
@@ -0,0 +1,68 @@
+/// Check handling the CPU is 64bit while ABI is O32.
+/// when build for MIPS platforms.
+
+/// abi-n32
+// RUN: %clang -### -c %s --target=mips-linux-gnu -mabi=n32 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ABI-N32 %s
+// CHECK-ABI-N32: "-target-abi" "n32"
+
+/// abi-64
+// RUN: %clang -### -c %s --target=mips-linux-gnu -mabi=64 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ABI-64 %s
+// CHECK-ABI-64: "-target-abi" "n64"
+
+
+/// -march=mips3
+// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips3 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPS3 %s
+// CHECK-MIPS-MIPS3: "-target-cpu" "mips3" {{.*}} "-target-abi" "o32"
+
+/// -march=mips4
+// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips4 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPS4 %s
+// CHECK-MIPS-MIPS4: "-target-cpu" "mips4" {{.*}} "-target-abi" "o32"
+
+/// FIXME: MIPS V is not implemented yet.
+
+/// -march=mips64
+/// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips64 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPS64 %s
+// CHECK-MIPS-MIPS64: "-target-cpu" "mips64" {{.*}} "-target-abi" "o32"
+
+/// -march=mips64r2
+/// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips64r2 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPS64R2 %s
+// CHECK-MIPS-MIPS64R2: "-target-cpu" "mips64r2" {{.*}} "-target-abi" "o32"
+
+/// -march=mips64r6
+// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips64r6 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPS64R6 %s
+// CHECK-MIPS-MIPS64R6: "-target-cpu" "mips64r6" {{.*}} "-target-abi" "o32"
+
+
+/// mipsisa3
+// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips3 -mabi=32 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPSISA3 %s
+// CHECK-MIPS-MIPSISA3: "-target-cpu" "mips3" {{.*}} "-target-abi" "o32"
+
+/// mipsisa4
+// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips4 -mabi=32 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPSISA4 %s
+// CHECK-MIPS-MIPSISA4: "-target-cpu" "mips4" {{.*}} "-target-abi" "o32"
+
+/// FIXME: MIPS V is not implemented yet.
+
+/// mipsisa64
+// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips64 -mabi=32 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPSISA64 %s
+// CHECK-MIPS-MIPSISA64: "-target-cpu" "mips64" {{.*}} "-target-abi" "o32"
+
+/// mipsisa64r2
+// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips64r2 -mabi=32 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPSISA64R2 %s
+// CHECK-MIPS-MIPSISA64R2: "-target-cpu" "mips64r2" {{.*}} "-target-abi" "o32"
+
+/// mipsisa64r6
+// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips64r6 -mabi=32 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS-MIPSISA64R6 %s
+// CHECK-MIPS-MIPSISA64R6: "-target-cpu" "mips64r6" {{.*}} "-target-abi" "o32"
Index: clang/test/Driver/mips-abi.c
===
--- clang/test/Driver/mips-abi.c
+++ clang/test/Driver/mips-abi.c
@@ -9,13 +9,6 @@
 // MIPS32R2-O32: "-target-cpu" "mips32r2"
 // MIPS32R2-O32: "-target-abi" "o32"
 //
-// FIXME: This is a valid combination of options but we reject it at the moment
-//because the backend can't handle it.
-// RUN: not %clang -target mips-linux-gnu -c %s \
-// RUN:-march=mips64r2 -mabi=32 2>&1 \
-// RUN:   | FileCheck -check-prefix=MIPS64R2-O32 %s
-// MIPS64R2-O32: error: ABI 'o32' is not supported on CPU 'mips64r2'
-//
 // RUN: %clang -target mips64-linux-gnu -### -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS64R2-N64 %s
 // RUN: %clang -target mips-img-linux-gnu -mips64r2 -### -c %s 2>&1 \
Index: clang/lib/Basic/Targets/Mips.cpp
===
--- clang/lib/Basic/Targets/Mips.cpp
+++ clang/lib/Basic/Targets/Mips.cpp
@@ -238,12 +238,6 @@
 

  1   2   >