[PATCH] D147591: [clang][Interp] Handle CXXTemporaryObjectExprs

2023-04-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  This is a CXXConstructExpr, so create a local temporary variable and
  initialize it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147591

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


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -314,7 +314,7 @@
 int Pos = 0;
 
 {
-  auto T = Test(Arr, Pos);
+  Test(Arr, Pos);
   // End of scope, should destroy Test.
 }
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -91,6 +91,8 @@
   bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E);
   bool VisitExprWithCleanups(const ExprWithCleanups *E);
   bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
+  bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E);
+  bool VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *E);
   bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
   bool VisitTypeTraitExpr(const TypeTraitExpr *E);
   bool VisitLambdaExpr(const LambdaExpr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -898,6 +898,24 @@
   return false;
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXBindTemporaryExpr(
+const CXXBindTemporaryExpr *E) {
+
+  return this->visit(E->getSubExpr());
+}
+
+template 
+bool ByteCodeExprGen::VisitCXXTemporaryObjectExpr(
+const CXXTemporaryObjectExpr *E) {
+
+  if (std::optional LocalIndex =
+  allocateLocal(E, /*IsExtended=*/false)) {
+return this->visitLocalInitializer(E, *LocalIndex);
+  }
+  return false;
+}
+
 template 
 bool ByteCodeExprGen::VisitCompoundLiteralExpr(
 const CompoundLiteralExpr *E) {


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -314,7 +314,7 @@
 int Pos = 0;
 
 {
-  auto T = Test(Arr, Pos);
+  Test(Arr, Pos);
   // End of scope, should destroy Test.
 }
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -91,6 +91,8 @@
   bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E);
   bool VisitExprWithCleanups(const ExprWithCleanups *E);
   bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
+  bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E);
+  bool VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *E);
   bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
   bool VisitTypeTraitExpr(const TypeTraitExpr *E);
   bool VisitLambdaExpr(const LambdaExpr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -898,6 +898,24 @@
   return false;
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXBindTemporaryExpr(
+const CXXBindTemporaryExpr *E) {
+
+  return this->visit(E->getSubExpr());
+}
+
+template 
+bool ByteCodeExprGen::VisitCXXTemporaryObjectExpr(
+const CXXTemporaryObjectExpr *E) {
+
+  if (std::optional LocalIndex =
+  allocateLocal(E, /*IsExtended=*/false)) {
+return this->visitLocalInitializer(E, *LocalIndex);
+  }
+  return false;
+}
+
 template 
 bool ByteCodeExprGen::VisitCompoundLiteralExpr(
 const CompoundLiteralExpr *E) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147395: [Clangd] Make the type hint length limit configurable

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

Thanks, looks good with a nit.




Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:80
   C.InlayHints.Designators = false;
+  C.InlayHints.TypeNameLimit = 1;
   return C;

why do we need this change? I think it should be fine without it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147395

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


cfe-commits@lists.llvm.org

2023-04-05 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

The test is also failing on our Windows on Arm bot: 
https://lab.llvm.org/buildbot/#/builders/65/builds/8950


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143128

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


cfe-commits@lists.llvm.org

2023-04-05 Thread David Spickett via cfe-commits

Author: David Spickett
Date: 2023-04-05T08:07:19Z
New Revision: d5c428356f6ee107a97977eb9ef1aa4d5fa0c378

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

LOG: Revert "[-Wunsafe-buffer-usage] Fix-Its transforming `&DRE[any]` to 
`&DRE.data()[any]`"

This reverts commit 87b5807d3802b932c06d83c4287014872aa2caab.

The test case is failing on Windows 
https://lab.llvm.org/buildbot/#/builders/65/builds/8950.

Added: 


Modified: 
clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
clang/lib/Analysis/UnsafeBufferUsage.cpp

Removed: 

clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-addressof-arraysubscript.cpp



diff  --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index f78cf2c57689c..8957ab664ed93 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -43,7 +43,7 @@ class UnsafeBufferUsageHandler {
 
   /// Returns the text indicating that the user needs to provide input there:
   virtual std::string
-  getUserFillPlaceHolder(StringRef HintTextToUser = "placeholder") const {
+  getUserFillPlaceHolder(StringRef HintTextToUser = "placeholder") {
 std::string s = std::string("<# ");
 s += HintTextToUser;
 s += " #>";

diff  --git 
a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
index f0c99a767071f..a8485682c1d1f 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
@@ -30,10 +30,9 @@ WARNING_GADGET(Decrement)
 WARNING_GADGET(ArraySubscript)
 WARNING_GADGET(PointerArithmetic)
 WARNING_GADGET(UnsafeBufferUsageAttr)
-FIXABLE_GADGET(ULCArraySubscript)  // `DRE[any]` in an Unspecified 
Lvalue Context
+FIXABLE_GADGET(ULCArraySubscript)
 FIXABLE_GADGET(DerefSimplePtrArithFixable)
 FIXABLE_GADGET(PointerDereference)
-FIXABLE_GADGET(UPCAddressofArraySubscript) // '&DRE[any]' in an Unspecified 
Pointer Context
 
 #undef FIXABLE_GADGET
 #undef WARNING_GADGET

diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 1ef276ab90444..4a8358af68ec5 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -15,7 +15,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include 
 #include 
-#include 
 
 using namespace llvm;
 using namespace clang;
@@ -113,15 +112,6 @@ class MatchDescendantVisitor
   bool Matches;
 };
 
-// Because we're dealing with raw pointers, let's define what we mean by that.
-static auto hasPointerType() {
-return hasType(hasCanonicalType(pointerType()));
-}
-
-static auto hasArrayType() {
-return hasType(hasCanonicalType(arrayType()));
-}
-  
 AST_MATCHER_P(Stmt, forEveryDescendant, internal::Matcher, innerMatcher) 
{
   const DynTypedMatcher &DTM = static_cast(innerMatcher);
 
@@ -155,30 +145,6 @@ static auto 
isInUnspecifiedLvalueContext(internal::Matcher innerMatcher) {
 ));
 // clang-format off
 }
-
-
-// Returns a matcher that matches any expression `e` such that `InnerMatcher`
-// matches `e` and `e` is in an Unspecified Pointer Context (UPC).
-static internal::Matcher
-isInUnspecifiedPointerContext(internal::Matcher InnerMatcher) {
-  // A UPC can be
-  // 1. an argument of a function call (except the callee has [[unsafe_...]]
-  // attribute), or
-  // 2. the operand of a cast operation; or
-  // ...
-  auto CallArgMatcher =
-  callExpr(hasAnyArgument(allOf(
-   hasPointerType() /* array also decays to pointer type*/,
-   InnerMatcher)),
-   unless(callee(functionDecl(hasAttr(attr::UnsafeBufferUsage);
-  auto CastOperandMatcher =
-  explicitCastExpr(hasCastKind(CastKind::CK_PointerToIntegral),
-   castSubExpr(allOf(hasPointerType(), InnerMatcher)));
-
- return stmt(anyOf(CallArgMatcher, CastOperandMatcher));
-  // FIXME: any more cases? (UPC excludes the RHS of an assignment.  For now we
-  // don't have to check that.)
-}
 } // namespace clang::ast_matchers
 
 namespace {
@@ -193,6 +159,15 @@ using FixItList = SmallVector;
 class Strategy;
 } // namespace
 
+// Because we're dealing with raw pointers, let's define what we mean by that.
+static auto hasPointerType() {
+return hasType(hasCanonicalType(pointerType()));
+}
+
+static auto hasArrayType() {
+return hasType(hasCanonicalType(arrayType()));
+}
+
 namespace {
 /// Gadget is an individual operation in the code that may be of interest to
 /// this analysis. Each (non-abstract) subclass corresp

cfe-commits@lists.llvm.org

2023-04-05 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

I've reverted this, please try to fix the test then reland.

The full test output can be downloaded from the buildbot page, if you need any 
more information let me know.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143128

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


[PATCH] D146389: [clang-repl][CUDA] Initial interactive CUDA support for clang-repl

2023-04-05 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added inline comments.



Comment at: clang/include/clang/Interpreter/Interpreter.h:43-44
 public:
   static llvm::Expected>
   create(std::vector &ClangArgv);
+  static llvm::Expected>

If I understand the change correctly, the "old" `create` function on its own is 
not sufficient anymore to create a fully working `CompilerInstance` - should we 
make it `private`? (and unify the two `Builder` classes into one?)

Alternatively, we could keep the current function working and move the bulk of 
the work to an `createInternal` function. What do you think?



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:296
   }
+  LinkModules.clear();
   return false; // success

This looks like a change that has implications beyond support for CUDA. Would 
it make sense to break this out into a separate review, ie does this change 
something in the current setup?



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:125
 
+static CodeGenerator *getCodeGen(FrontendAction *Act);
+

Is it possible to move the `static` function here instead of forward declaring? 
Or does it depend on other functions in this file?



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:143-156
+  // An initial PTU is needed as CUDA includes some headers automatically
+  auto PTU = ParseOrWrapTopLevelDecl();
+  if (auto E = PTU.takeError()) {
+consumeError(std::move(E)); // FIXME
+return; // PTU.takeError();
+  }
+

Should this be done as part of the "generic" `IncrementalParser` constructor, 
or only in the CUDA case by something else? Maybe `Interpreter::createWithCUDA`?



Comment at: clang/lib/Interpreter/Interpreter.cpp:270-274
+  if (DeviceParser) {
+auto DevicePTU = DeviceParser->Parse(Code);
+if (auto E = DevicePTU.takeError())
+  return E;
+  }

Just wondering about the order here: Do we have to parse the device side first? 
Does it make a difference for diagnostics? Maybe you can add a comment about 
the choice here...



Comment at: clang/lib/Interpreter/Offload.cpp:1
+//===-- Offload.cpp - CUDA Offloading ---*- C++ 
-*-===//
+//

v.g.vassilev wrote:
> How about `DeviceOffload.cpp`?
Or `IncrementalCUDADeviceParser.cpp` for the moment - not sure what other 
classes will be added in the future, and if they should be in the same TU.



Comment at: clang/lib/Interpreter/Offload.cpp:90-91
+  PTXCode += '\0';
+  while (PTXCode.size() % 8)
+PTXCode += '\0';
+  return PTXCode.str();

Is padding to 8 bytes a requirement for PTX? Maybe add a coment...



Comment at: clang/lib/Interpreter/Offload.h:20
+
+class DeviceCodeInlinerAction;
+

unused


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146389

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


[PATCH] D146389: [clang-repl][CUDA] Initial interactive CUDA support for clang-repl

2023-04-05 Thread Anubhab Ghosh via Phabricator via cfe-commits
argentite added a comment.

In D146389#4243900 , @tra wrote:

>> Initial interactive CUDA support for clang-repl
>
> What should a user expect to be supported, functionality wise? I assume it 
> should cover parsing and compilation. I'm not so sure about the execution. 
> Should it be expected to actually launch kernels, or will that come in a 
> future patch?

With this patch alone, we can launch kernels with the usual syntax. The 
`__device__` functions need to be `inline` for now. We plan to automate that in 
the future.




Comment at: clang/include/clang/Interpreter/Interpreter.h:43-44
 public:
   static llvm::Expected>
   create(std::vector &ClangArgv);
+  static llvm::Expected>

Hahnfeld wrote:
> If I understand the change correctly, the "old" `create` function on its own 
> is not sufficient anymore to create a fully working `CompilerInstance` - 
> should we make it `private`? (and unify the two `Builder` classes into one?)
> 
> Alternatively, we could keep the current function working and move the bulk 
> of the work to an `createInternal` function. What do you think?
Yes the old `create` should probably be private. I was also thinking we could 
merge `IncrementalCudaCompilerBuilder` with `IncrementalCompilerBuilder` and 
make it stateful with CUDA SDK path for example. Then we could do something 
like:
```
IncrementalCompilerBuilder Builder;
Builder.setCudaPath(...);
auto DeviceCI = Builder.createCudaDevice();
auto HostCI = Builder.createCudaHost();
```



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:296
   }
+  LinkModules.clear();
   return false; // success

Hahnfeld wrote:
> This looks like a change that has implications beyond support for CUDA. Would 
> it make sense to break this out into a separate review, ie does this change 
> something in the current setup?
It actually was a separate patch: D146388 Should I submit that for review?
It seems to be required because we call `LinkInModules()` once for every 
interpreter iteration.




Comment at: clang/lib/Interpreter/IncrementalParser.cpp:125
 
+static CodeGenerator *getCodeGen(FrontendAction *Act);
+

Hahnfeld wrote:
> Is it possible to move the `static` function here instead of forward 
> declaring? Or does it depend on other functions in this file?
We can probably move this. I just wanted to preserve the history,



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:143-156
+  // An initial PTU is needed as CUDA includes some headers automatically
+  auto PTU = ParseOrWrapTopLevelDecl();
+  if (auto E = PTU.takeError()) {
+consumeError(std::move(E)); // FIXME
+return; // PTU.takeError();
+  }
+

Hahnfeld wrote:
> Should this be done as part of the "generic" `IncrementalParser` constructor, 
> or only in the CUDA case by something else? Maybe 
> `Interpreter::createWithCUDA`?
That seems safer. Although I did not notice any side effects.



Comment at: clang/lib/Interpreter/Interpreter.cpp:270-274
+  if (DeviceParser) {
+auto DevicePTU = DeviceParser->Parse(Code);
+if (auto E = DevicePTU.takeError())
+  return E;
+  }

Hahnfeld wrote:
> Just wondering about the order here: Do we have to parse the device side 
> first? Does it make a difference for diagnostics? Maybe you can add a comment 
> about the choice here...
The fatbinary from the device side is used in the host pipeline.



Comment at: clang/lib/Interpreter/Offload.cpp:1
+//===-- Offload.cpp - CUDA Offloading ---*- C++ 
-*-===//
+//

Hahnfeld wrote:
> v.g.vassilev wrote:
> > How about `DeviceOffload.cpp`?
> Or `IncrementalCUDADeviceParser.cpp` for the moment - not sure what other 
> classes will be added in the future, and if they should be in the same TU.
I wanted to avoid "CUDA" in case we use it later for HIP.



Comment at: clang/tools/clang-repl/ClangRepl.cpp:137
+
+ExitOnErr(Interp->LoadDynamicLibrary("libcudart.so"));
+  } else

v.g.vassilev wrote:
> tra wrote:
> > v.g.vassilev wrote:
> > > tra wrote:
> > > > Is there any doc describing the big picture approach to CUDA REPL 
> > > > implementation and how all the pieces tie together?
> > > > 
> > > > From the patch I see that we will compile GPU side of the code to PTX, 
> > > > pack it into fatbinary, but it's not clear now do we get from there to 
> > > > actually launching the kernels. Loading libcudart.so here also does not 
> > > > appear to be tied to anything else. I do not see any direct API calls, 
> > > > and the host-side compilation appears to be done w.o passing the GPU 
> > > > binary to it, which would normally trigger generation of the glue code 
> > > > to register the kernels with CUDA runtime. I may be missing something, 
> > > > too.
> > > > 
> > > > I assum

[PATCH] D140722: [OpenMP] Prefix outlined and reduction func names with original func's name

2023-04-05 Thread Itay Bookstein via Phabricator via cfe-commits
nextsilicon-itay-bookstein added a comment.

Ping :)


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

https://reviews.llvm.org/D140722

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


[PATCH] D147209: [clang][lit] Make LIT aware of env CLANG_CRASH_DIAGNOSTICS_DIR.

2023-04-05 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added a comment.

In D147209#4244615 , @leonardchan 
wrote:

> Hi. I think this led to some test failures on our builder at 
> https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8784708268307261009/overview:

Hi @leonardchan - thank you for the heads up!

I do not have access to this bot (the link you sent just shows me a blank 
page), and I have not seen this (clang?) test failing in my local build. I can 
revert the patch, but I'll need some more info to be able to fix those failures.

Francesco


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147209

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


[PATCH] D146389: [clang-repl][CUDA] Initial interactive CUDA support for clang-repl

2023-04-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:296
   }
+  LinkModules.clear();
   return false; // success

argentite wrote:
> Hahnfeld wrote:
> > This looks like a change that has implications beyond support for CUDA. 
> > Would it make sense to break this out into a separate review, ie does this 
> > change something in the current setup?
> It actually was a separate patch: D146388 Should I submit that for review?
> It seems to be required because we call `LinkInModules()` once for every 
> interpreter iteration.
> 
The problem with going for a separate change is that we cannot test it. Landing 
it without a test makes the history commit unclear. This patch (and the tests 
we add here) will at least indirectly test that change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146389

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


[PATCH] D146389: [clang-repl][CUDA] Initial interactive CUDA support for clang-repl

2023-04-05 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added inline comments.



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:296
   }
+  LinkModules.clear();
   return false; // success

v.g.vassilev wrote:
> argentite wrote:
> > Hahnfeld wrote:
> > > This looks like a change that has implications beyond support for CUDA. 
> > > Would it make sense to break this out into a separate review, ie does 
> > > this change something in the current setup?
> > It actually was a separate patch: D146388 Should I submit that for review?
> > It seems to be required because we call `LinkInModules()` once for every 
> > interpreter iteration.
> > 
> The problem with going for a separate change is that we cannot test it. 
> Landing it without a test makes the history commit unclear. This patch (and 
> the tests we add here) will at least indirectly test that change.
Ok, that's why I was asking if it changes something in the current setup (ie 
can be tested). Thanks for clarifying.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146389

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


[clang] a5e1a93 - [clang] Fix crash when handling nested immediate invocations

2023-04-05 Thread Mariya Podchishchaeva via cfe-commits

Author: Mariya Podchishchaeva
Date: 2023-04-05T05:20:51-04:00
New Revision: a5e1a93ea10ffc06a32df6d9f410e9b297ed136d

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

LOG: [clang] Fix crash when handling nested immediate invocations

Before this patch it was expected that if there was several immediate
invocations they all belong to the same expression evaluation context.
During parsing of non local variable initializer a new evaluation context is
pushed, so code like this
```
namespace scope {
struct channel {
consteval channel(const char* name) noexcept { }
};
consteval const char* make_channel_name(const char* name) { return name;}

channel rsx_log(make_channel_name("rsx_log"));
}
```
produced a nested immediate invocation whose subexpressions are attached
to different expression evaluation contexts. The constructor call
belongs to TU context and `make_channel_name` call to context of
variable initializer.

This patch removes this assumption and adds tracking of previously
failed immediate invocations, so it is possible when handling an
immediate invocation th check that its subexpressions from possibly another
evaluation context contains errors and not produce duplicate
diagnostics.

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

Reviewed By: aaron.ballman, shafik

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e39c8606ffd38..1e280cb633e23 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -271,6 +271,9 @@ Bug Fixes in This Version
   (`#60887 `_)
 - Fix incorrect merging of lambdas across modules.
   (`#60985 `_)
+- Fix crash when handling nested immediate invocations in initializers of 
global
+  variables.
+  (`#58207 `_)
 
 
 Bug Fixes to Compiler Builtins

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index d7f0f1184a7e6..a46bc758dd6af 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1392,6 +1392,9 @@ class Sema final {
   /// A stack of expression evaluation contexts.
   SmallVector ExprEvalContexts;
 
+  // Set of failed immediate invocations to avoid double diagnosing.
+  llvm::SmallPtrSet FailedImmediateInvocations;
+
   /// Emit a warning for all pending noderef expressions that we recorded.
   void WarnOnPendingNoDerefs(ExpressionEvaluationContextRecord &Rec);
 

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 47b548e9a9fc6..351db6d7ccf27 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17860,6 +17860,7 @@ static void EvaluateAndDiagnoseImmediateInvocation(
   bool Result = CE->EvaluateAsConstantExpr(
   Eval, SemaRef.getASTContext(), ConstantExprKind::ImmediateInvocation);
   if (!Result || !Notes.empty()) {
+SemaRef.FailedImmediateInvocations.insert(CE);
 Expr *InnerExpr = CE->getSubExpr()->IgnoreImplicit();
 if (auto *FunctionalCast = dyn_cast(InnerExpr))
   InnerExpr = FunctionalCast->getSubExpr();
@@ -17904,10 +17905,16 @@ static void RemoveNestedImmediateInvocation(
  [E](Sema::ImmediateInvocationCandidate Elem) {
return Elem.getPointer() == E;
  });
-  assert(It != IISet.rend() &&
- "ConstantExpr marked IsImmediateInvocation should "
- "be present");
-  It->setInt(1); // Mark as deleted
+  // It is possible that some subexpression of the current immediate
+  // invocation was handled from another expression evaluation context. Do
+  // not handle the current immediate invocation if some of its
+  // subexpressions failed before.
+  if (It == IISet.rend()) {
+if (SemaRef.FailedImmediateInvocations.contains(E))
+  CurrentII->setInt(1);
+  } else {
+It->setInt(1); // Mark as deleted
+  }
 }
 ExprResult TransformConstantExpr(ConstantExpr *E) {
   if (!E->isImmediateInvocation())
@@ -17980,10 +17987,13 @@ HandleImmediateInvocations(Sema &SemaRef,
   SemaRef.RebuildingImmediateInvocation)
 return;
 
-  /// When we have more then 1 ImmediateInvocationCandidates we need to check
-  /// for nested ImmediateInvocationCandidates. when we have only 1 we only
-  /// need to remove ReferenceToConsteval in the immediate invocation.
-  if (Rec.ImmediateInvocationCandidates.size() > 1) {

[PATCH] D146234: [clang] Fix crash when handling nested immediate invocations

2023-04-05 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa5e1a93ea10f: [clang] Fix crash when handling nested 
immediate invocations (authored by Fznamznon).

Changed prior to commit:
  https://reviews.llvm.org/D146234?vs=509039&id=511027#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146234

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp

Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1065,3 +1065,41 @@
 static_assert(B == 0);
 
 }
+
+namespace GH58207 {
+struct tester {
+consteval tester(const char* name) noexcept { }
+};
+consteval const char* make_name(const char* name) { return name;}
+consteval const char* pad(int P) { return "thestring"; }
+
+int bad = 10; // expected-note 6{{declared here}}
+
+tester glob1(make_name("glob1"));
+tester glob2(make_name("glob2"));
+constexpr tester cglob(make_name("cglob"));
+tester paddedglob(make_name(pad(bad))); // expected-error {{call to consteval function 'GH58207::make_name' is not a constant expression}} \
+// expected-note {{read of non-const variable 'bad' is not allowed in a constant expression}}
+
+constexpr tester glob3 = { make_name("glob3") };
+constexpr tester glob4 = { make_name(pad(bad)) }; // expected-error {{call to consteval function 'GH58207::make_name' is not a constant expression}} \
+  // expected-error {{constexpr variable 'glob4' must be initialized by a constant expression}} \
+  // expected-note 2{{read of non-const variable 'bad' is not allowed in a constant expression}}
+
+auto V = make_name(pad(3));
+auto V1 = make_name(pad(bad)); // expected-error {{call to consteval function 'GH58207::make_name' is not a constant expression}} \
+   // expected-note {{read of non-const variable 'bad' is not allowed in a constant expression}}
+
+
+void foo() {
+  static tester loc1(make_name("loc1"));
+  static constexpr tester loc2(make_name("loc2"));
+  static tester paddedloc(make_name(pad(bad))); // expected-error {{call to consteval function 'GH58207::make_name' is not a constant expression}} \
+// expected-note {{read of non-const variable 'bad' is not allowed in a constant expression}}
+}
+
+void bar() {
+  static tester paddedloc(make_name(pad(bad))); // expected-error {{call to consteval function 'GH58207::make_name' is not a constant expression}} \
+// expected-note {{read of non-const variable 'bad' is not allowed in a constant expression}}
+}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -17860,6 +17860,7 @@
   bool Result = CE->EvaluateAsConstantExpr(
   Eval, SemaRef.getASTContext(), ConstantExprKind::ImmediateInvocation);
   if (!Result || !Notes.empty()) {
+SemaRef.FailedImmediateInvocations.insert(CE);
 Expr *InnerExpr = CE->getSubExpr()->IgnoreImplicit();
 if (auto *FunctionalCast = dyn_cast(InnerExpr))
   InnerExpr = FunctionalCast->getSubExpr();
@@ -17904,10 +17905,16 @@
  [E](Sema::ImmediateInvocationCandidate Elem) {
return Elem.getPointer() == E;
  });
-  assert(It != IISet.rend() &&
- "ConstantExpr marked IsImmediateInvocation should "
- "be present");
-  It->setInt(1); // Mark as deleted
+  // It is possible that some subexpression of the current immediate
+  // invocation was handled from another expression evaluation context. Do
+  // not handle the current immediate invocation if some of its
+  // subexpressions failed before.
+  if (It == IISet.rend()) {
+if (SemaRef.FailedImmediateInvocations.contains(E))
+  CurrentII->setInt(1);
+  } else {
+It->setInt(1); // Mark as deleted
+  }
 }
 ExprResult TransformConstantExpr(ConstantExpr *E) {
   if (!E->isImmediateInvocation())
@@ -17980,10 +17987,13 @@
   SemaRef.RebuildingImmediateInvocation)
 return;
 
-  /// When we have more then 1 ImmediateInvocationCandidates we need to check
-  /// for nested ImmediateInvocationCandidates. when we have only 1 we only
-  /// need to remove ReferenceToConsteval in the immediate invocation.
-  if (Rec.ImmediateInvocationCandidates.size() > 1) {
+  /// When we have more than 1 ImmediateInvocationCandidates or previously
+  /// failed immediate invocations, we need to check for nest

[PATCH] D146757: [Driver] Enable defining multilib print options independently of flags

2023-04-05 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

Approach looks good to me. Some suggestions, mostly around documenting the 
interface.




Comment at: clang/include/clang/Driver/Multilib.h:56
   /// This is enforced with an assert in the constructor.
   Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},
+   StringRef IncludeSuffix = {}, const flags_list &Flags = 
flags_list(),

I think it is worth adding some information from the commit message to the 
comment. In particular what the default behaviour is and what, if any, 
restrictions are there on the PrintOptionsList.

For example there is a comment in the  assert in the constructor body that 
probably ought to be in the header
```
// If PrintOptions is something other than List then PrintOptionsList must be
// empty.
```

Are there any restrictions on the format of PrintOptionsList for it to print 
correctly? For example does each option need to be prefixed with `-`? 



Comment at: clang/include/clang/Driver/Multilib.h:58
+   StringRef IncludeSuffix = {}, const flags_list &Flags = 
flags_list(),
+   PrintOptionsType PrintOptions = PrintOptionsType::PlusFlags,
+   const flags_list &PrintOptionsList = flags_list());

How would someone using `makeMultilib()` from `MultilibBuilder` use these 
parameters? If they can't do they need to? If so we may need something like a 
makeMultilib overload to supply the extra parameters.



Comment at: clang/lib/Driver/Multilib.cpp:44
+  assert(PrintOptions == PrintOptionsType::List || PrintOptionsList.empty());
+}
+

If there are any restrictions on the strings in PrintOptionsList could be worth 
assertions. Please ignore if there are no restrictions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146757

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


[clang-tools-extra] dfa8f5b - [clang-tidy] Fix init-list handling in readability-implicit-bool-conversion

2023-04-05 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-04-05T10:22:10Z
New Revision: dfa8f5b13e58cd742821860c351005e63f9ce890

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

LOG: [clang-tidy] Fix init-list handling in readability-implicit-bool-conversion

Adds support for explicit casts using initListExpr,
for example: int{boolValue} constructions.

Fixes: #47000

Reviewed By: ccotter

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 7ec63d0fd9edf..863ac4dbbf4c6 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -262,7 +262,10 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
   expr(anyOf(allOf(isMacroExpansion(), unless(isNULLMacroExpansion())),
  has(ignoringImplicit(
  memberExpr(hasDeclaration(fieldDecl(hasBitWidth(1)),
- hasParent(explicitCastExpr(;
+ hasParent(explicitCastExpr()),
+ expr(hasType(qualType().bind("type")),
+  hasParent(initListExpr(hasParent(explicitCastExpr(
+  hasType(qualType(equalsBoundNode("type"));
   auto ImplicitCastFromBool = implicitCastExpr(
   anyOf(hasCastKind(CK_IntegralCast), hasCastKind(CK_IntegralToFloating),
 // Prior to C++11 cast from bool literal to pointer was allowed.
@@ -290,7 +293,7 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
unless(ExceptionCases), unless(has(BoolXor)),
// Retrieve also parent statement, to check if we need
// additional parens in replacement.
-   anyOf(hasParent(stmt().bind("parentStmt")), anything()),
+   optionally(hasParent(stmt().bind("parentStmt"))),
unless(isInTemplateInstantiation()),
unless(hasAncestor(functionTemplateDecl(
.bind("implicitCastToBool")),

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 2dfc29e630624..6a87bcb3903e6 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -240,6 +240,10 @@ Changes in existing checks
   behavior of using `i` as the prefix for enum tags, set the 
`EnumConstantPrefix`
   option to `i` instead of using `EnumConstantHungarianPrefix`.
 
+- Fixed a false positive in :doc:`readability-implicit-bool-conversion
+  ` check warning would
+  be unnecessarily emitted for explicit cast using direct list initialization.
+
 - Added support to optionally ignore user-defined literals in
   
:doc:`readability-magic-numbers`.
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
index d5e9bee4294d3..323cf813c0470 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
@@ -471,3 +471,10 @@ bool f(S& s) {
 }
 
 } // namespace ignore_1bit_bitfields
+
+namespace PR47000 {
+  int to_int(bool x) { return int{x}; }
+
+  using IntType = int;
+  int to_int2(bool x) { return IntType{x}; }
+}



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


[PATCH] D147551: [clang-tidy] Fix init-list handling in readability-implicit-bool-conversion

2023-04-05 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdfa8f5b13e58: [clang-tidy] Fix init-list handling in 
readability-implicit-bool-conversion (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147551

Files:
  clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
@@ -471,3 +471,10 @@
 }
 
 } // namespace ignore_1bit_bitfields
+
+namespace PR47000 {
+  int to_int(bool x) { return int{x}; }
+
+  using IntType = int;
+  int to_int2(bool x) { return IntType{x}; }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -240,6 +240,10 @@
   behavior of using `i` as the prefix for enum tags, set the 
`EnumConstantPrefix`
   option to `i` instead of using `EnumConstantHungarianPrefix`.
 
+- Fixed a false positive in :doc:`readability-implicit-bool-conversion
+  ` check warning would
+  be unnecessarily emitted for explicit cast using direct list initialization.
+
 - Added support to optionally ignore user-defined literals in
   
:doc:`readability-magic-numbers`.
 
Index: clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -262,7 +262,10 @@
   expr(anyOf(allOf(isMacroExpansion(), unless(isNULLMacroExpansion())),
  has(ignoringImplicit(
  memberExpr(hasDeclaration(fieldDecl(hasBitWidth(1)),
- hasParent(explicitCastExpr(;
+ hasParent(explicitCastExpr()),
+ expr(hasType(qualType().bind("type")),
+  hasParent(initListExpr(hasParent(explicitCastExpr(
+  hasType(qualType(equalsBoundNode("type"));
   auto ImplicitCastFromBool = implicitCastExpr(
   anyOf(hasCastKind(CK_IntegralCast), hasCastKind(CK_IntegralToFloating),
 // Prior to C++11 cast from bool literal to pointer was allowed.
@@ -290,7 +293,7 @@
unless(ExceptionCases), unless(has(BoolXor)),
// Retrieve also parent statement, to check if we need
// additional parens in replacement.
-   anyOf(hasParent(stmt().bind("parentStmt")), anything()),
+   optionally(hasParent(stmt().bind("parentStmt"))),
unless(isInTemplateInstantiation()),
unless(hasAncestor(functionTemplateDecl(
.bind("implicitCastToBool")),


Index: clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
@@ -471,3 +471,10 @@
 }
 
 } // namespace ignore_1bit_bitfields
+
+namespace PR47000 {
+  int to_int(bool x) { return int{x}; }
+
+  using IntType = int;
+  int to_int2(bool x) { return IntType{x}; }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -240,6 +240,10 @@
   behavior of using `i` as the prefix for enum tags, set the `EnumConstantPrefix`
   option to `i` instead of using `EnumConstantHungarianPrefix`.
 
+- Fixed a false positive in :doc:`readability-implicit-bool-conversion
+  ` check warning would
+  be unnecessarily emitted for explicit cast using direct list initialization.
+
 - Added support to optionally ignore user-defined literals in
   :doc:`readability-magic-numbers`.
 
Index: clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -262,7 +262,10 @@
   expr(anyOf(allOf(isMacroExpansion(), unless(isNULLMacroExpansion())),
  has(ignoringImplicit(
  memberExpr(

[PATCH] D146358: [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables

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



Comment at: clang/lib/AST/ExprConstant.cpp:2357-2361
+if (SubobjectDecl) {
+  Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized) << 
SubobjectDecl;
+  Info.Note(SubobjectDecl->getLocation(),
+diag::note_constexpr_subobject_declared_here);
+}

aaron.ballman wrote:
> hazohelet wrote:
> > aaron.ballman wrote:
> > > Hmm, this breaks one of the contracts of our constexpr evaluation engine, 
> > > doesn't it? My understanding is that if constexpr evaluation fails, we 
> > > will have emitted a note diagnostic for why it failed. But if the caller 
> > > doesn't pass a nonnull `SubobjectDecl`, we'll return `false` but we won't 
> > > issue a diagnostic.
> > > 
> > > I'm surprised no tests lost notes as a result of this change, that 
> > > suggests we're missing test coverage for the cases where nullptr is 
> > > passed in explicitly to this function.
> > Yeah, I was looking into when `SubobjectDecl` can be null here. I 
> > `assert`ed the non-nullness of `SubobjectDecl` before and found that there 
> > exists two lines of code 
> > (https://github.com/llvm/llvm-project/blob/22a3f974d35da89247c0396594f2e4cd592742eb/clang/test/SemaCXX/attr-weak.cpp#L49
> >  and 
> > https://github.com/llvm/llvm-project/blob/abf4a8cb15d4faf04ee0da14e37d7349d3bde9a1/clang/test/CodeGenCXX/weak-external.cpp#L97)
> >  in the test codes that nulls here.
> > It seems they are doing the same thing, doing comparison against a pointer 
> > to a `[[gnu::weak]]` member. A simple reproducing code is here: 
> > https://godbolt.org/z/qn997n85n
> > As you can see from the compiler explorer, there's no note emitted here 
> > before the patch.
> > I inserted some `printf` into the code before this patch  and confirmed 
> > `Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized) << true << Type` 
> > was actually called when compiling the reproducing code and that somehow it 
> > is ignored. FWIW, `SubobjectLoc.isValid()` was `false` here.
> > It seems they are doing the same thing, doing comparison against a pointer 
> > to a [[gnu::weak]] member. A simple reproducing code is here: 
> > https://godbolt.org/z/qn997n85n
> > As you can see from the compiler explorer, there's no note emitted here 
> > before the patch.
> 
> I see a note generated there:
> ```
> :4:41: note: comparison against pointer to weak member 
> 'Weak::weak_method' can only be performed at runtime
> constexpr bool val = &Weak::weak_method != nullptr;
> ^
> ```
> The situations I'm concerned about are the changes to ExprConstant.cpp:2270 
> or line 2399 and so on.
The `FFDiag` call can just stay as it was, right? And then only the `Info.Note` 
call needs to be conditional for whether we have  a `SubobjectDecl`.


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

https://reviews.llvm.org/D146358

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


[PATCH] D147601: [clang][dataflow] Eliminate code duplication in Environment::createValueUnlessSelfReferential().

2023-04-05 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147601

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp


Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -688,9 +688,9 @@
 return &create();
   }
 
-  if (Type->isReferenceType()) {
+  if (Type->isReferenceType() || Type->isPointerType()) {
 CreatedValuesCount++;
-QualType PointeeType = Type->castAs()->getPointeeType();
+QualType PointeeType = Type->getPointeeType();
 auto &PointeeLoc = createStorageLocation(PointeeType);
 
 if (Visited.insert(PointeeType.getCanonicalType()).second) {
@@ -702,24 +702,10 @@
 setValue(PointeeLoc, *PointeeVal);
 }
 
-return &create(PointeeLoc);
-  }
-
-  if (Type->isPointerType()) {
-CreatedValuesCount++;
-QualType PointeeType = Type->castAs()->getPointeeType();
-auto &PointeeLoc = createStorageLocation(PointeeType);
-
-if (Visited.insert(PointeeType.getCanonicalType()).second) {
-  Value *PointeeVal = createValueUnlessSelfReferential(
-  PointeeType, Visited, Depth, CreatedValuesCount);
-  Visited.erase(PointeeType.getCanonicalType());
-
-  if (PointeeVal != nullptr)
-setValue(PointeeLoc, *PointeeVal);
-}
-
-return &create(PointeeLoc);
+if (Type->isReferenceType())
+  return &create(PointeeLoc);
+else
+  return &create(PointeeLoc);
   }
 
   if (Type->isStructureOrClassType() || Type->isUnionType()) {


Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -688,9 +688,9 @@
 return &create();
   }
 
-  if (Type->isReferenceType()) {
+  if (Type->isReferenceType() || Type->isPointerType()) {
 CreatedValuesCount++;
-QualType PointeeType = Type->castAs()->getPointeeType();
+QualType PointeeType = Type->getPointeeType();
 auto &PointeeLoc = createStorageLocation(PointeeType);
 
 if (Visited.insert(PointeeType.getCanonicalType()).second) {
@@ -702,24 +702,10 @@
 setValue(PointeeLoc, *PointeeVal);
 }
 
-return &create(PointeeLoc);
-  }
-
-  if (Type->isPointerType()) {
-CreatedValuesCount++;
-QualType PointeeType = Type->castAs()->getPointeeType();
-auto &PointeeLoc = createStorageLocation(PointeeType);
-
-if (Visited.insert(PointeeType.getCanonicalType()).second) {
-  Value *PointeeVal = createValueUnlessSelfReferential(
-  PointeeType, Visited, Depth, CreatedValuesCount);
-  Visited.erase(PointeeType.getCanonicalType());
-
-  if (PointeeVal != nullptr)
-setValue(PointeeLoc, *PointeeVal);
-}
-
-return &create(PointeeLoc);
+if (Type->isReferenceType())
+  return &create(PointeeLoc);
+else
+  return &create(PointeeLoc);
   }
 
   if (Type->isStructureOrClassType() || Type->isUnionType()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147603: [clang][dataflow] Use `isRecordType()` where appropriate.

2023-04-05 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is less verbose than checking for class, struct, and union individually,
and I believe it's also more efficient (not that that should be the overriding
concern).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147603

Files:
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp


Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -608,7 +608,7 @@
 auto &AggregateLoc = *cast(&Loc);
 
 const QualType Type = AggregateLoc.getType();
-assert(Type->isStructureOrClassType() || Type->isUnionType());
+assert(Type->isRecordType());
 
 for (const FieldDecl *Field : DACtx->getReferencedFields(Type)) {
   assert(Field != nullptr);
@@ -722,7 +722,7 @@
 return &create(PointeeLoc);
   }
 
-  if (Type->isStructureOrClassType() || Type->isUnionType()) {
+  if (Type->isRecordType()) {
 CreatedValuesCount++;
 llvm::DenseMap FieldValues;
 for (const FieldDecl *Field : DACtx->getReferencedFields(Type)) {
Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -45,8 +45,7 @@
 }
 
 StorageLocation &DataflowAnalysisContext::createStorageLocation(QualType Type) 
{
-  if (!Type.isNull() &&
-  (Type->isStructureOrClassType() || Type->isUnionType())) {
+  if (!Type.isNull() && Type->isRecordType()) {
 llvm::DenseMap FieldLocs;
 // During context-sensitive analysis, a struct may be allocated in one
 // function, but its field accessed in a function lower in the stack than


Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -608,7 +608,7 @@
 auto &AggregateLoc = *cast(&Loc);
 
 const QualType Type = AggregateLoc.getType();
-assert(Type->isStructureOrClassType() || Type->isUnionType());
+assert(Type->isRecordType());
 
 for (const FieldDecl *Field : DACtx->getReferencedFields(Type)) {
   assert(Field != nullptr);
@@ -722,7 +722,7 @@
 return &create(PointeeLoc);
   }
 
-  if (Type->isStructureOrClassType() || Type->isUnionType()) {
+  if (Type->isRecordType()) {
 CreatedValuesCount++;
 llvm::DenseMap FieldValues;
 for (const FieldDecl *Field : DACtx->getReferencedFields(Type)) {
Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -45,8 +45,7 @@
 }
 
 StorageLocation &DataflowAnalysisContext::createStorageLocation(QualType Type) {
-  if (!Type.isNull() &&
-  (Type->isStructureOrClassType() || Type->isUnionType())) {
+  if (!Type.isNull() && Type->isRecordType()) {
 llvm::DenseMap FieldLocs;
 // During context-sensitive analysis, a struct may be allocated in one
 // function, but its field accessed in a function lower in the stack than
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146757: [Driver] Enable defining multilib print options independently of flags

2023-04-05 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 511073.
michaelplatings marked 3 inline comments as done.
michaelplatings added a comment.

Expand constructor comment as suggested by @peter.smith


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146757

Files:
  clang/include/clang/Driver/Multilib.h
  clang/lib/Driver/Multilib.cpp
  clang/unittests/Driver/MultilibBuilderTest.cpp
  clang/unittests/Driver/MultilibTest.cpp

Index: clang/unittests/Driver/MultilibTest.cpp
===
--- clang/unittests/Driver/MultilibTest.cpp
+++ clang/unittests/Driver/MultilibTest.cpp
@@ -187,3 +187,19 @@
   EXPECT_EQ("/a", Selection[0].gccSuffix());
   EXPECT_EQ("/b", Selection[1].gccSuffix());
 }
+
+TEST(MultilibBuilder, PrintOptions) {
+  ASSERT_EQ(Multilib::flags_list(), Multilib().getPrintOptions());
+  ASSERT_EQ(Multilib::flags_list({"-x"}),
+Multilib({}, {}, {}, {"+x"}).getPrintOptions());
+  ASSERT_EQ(Multilib::flags_list({"-x"}),
+Multilib({}, {}, {}, {"+x"}, Multilib::PrintOptionsType::PlusFlags)
+.getPrintOptions());
+  ASSERT_EQ(
+  Multilib::flags_list({"-x", "-a", "-c"}),
+  Multilib({}, {}, {}, {"+x", "-y", "+a", "-b", "+c"}).getPrintOptions());
+  ASSERT_EQ(
+  Multilib::flags_list({"-y"}),
+  Multilib({}, {}, {}, {"+x"}, Multilib::PrintOptionsType::List, {"-y"})
+  .getPrintOptions());
+}
Index: clang/unittests/Driver/MultilibBuilderTest.cpp
===
--- clang/unittests/Driver/MultilibBuilderTest.cpp
+++ clang/unittests/Driver/MultilibBuilderTest.cpp
@@ -207,3 +207,14 @@
 << "Selection picked " << Selection << " which was not expected ";
   }
 }
+
+TEST(MultilibBuilderTest, PrintOptions) {
+  Multilib M = MultilibBuilder()
+   .flag("+x")
+   .flag("-y")
+   .flag("+a")
+   .flag("-b")
+   .flag("+c")
+   .makeMultilib();
+  ASSERT_EQ(Multilib::flags_list({"-x", "-a", "-c"}), M.getPrintOptions());
+}
Index: clang/lib/Driver/Multilib.cpp
===
--- clang/lib/Driver/Multilib.cpp
+++ clang/lib/Driver/Multilib.cpp
@@ -26,15 +26,43 @@
 using namespace llvm::sys;
 
 Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix,
-   StringRef IncludeSuffix, const flags_list &Flags)
+   StringRef IncludeSuffix, const flags_list &Flags,
+   PrintOptionsType PrintOptions,
+   const flags_list &PrintOptionsList)
 : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix),
-  Flags(Flags) {
+  Flags(Flags), PrintOptionsList(PrintOptionsList),
+  PrintOptions(PrintOptions) {
   assert(GCCSuffix.empty() ||
  (StringRef(GCCSuffix).front() == '/' && GCCSuffix.size() > 1));
   assert(OSSuffix.empty() ||
  (StringRef(OSSuffix).front() == '/' && OSSuffix.size() > 1));
   assert(IncludeSuffix.empty() ||
  (StringRef(IncludeSuffix).front() == '/' && IncludeSuffix.size() > 1));
+  // If PrintOptions is something other than List then PrintOptionsList must be
+  // empty.
+  assert(PrintOptions == PrintOptionsType::List || PrintOptionsList.empty());
+}
+
+static Multilib::flags_list
+getPrintOptionsFromPlusFlags(const Multilib::flags_list &Flags) {
+  // Derive print options from flags beginning '+', replacing the first
+  // character with '-'.
+  Multilib::flags_list PrintOptions;
+  for (StringRef Flag : Flags) {
+if (Flag.front() == '+')
+  PrintOptions.push_back(("-" + Flag.substr(1)).str());
+  }
+  return PrintOptions;
+}
+
+Multilib::flags_list Multilib::getPrintOptions() const {
+  switch (PrintOptions) {
+  case PrintOptionsType::List:
+return PrintOptionsList;
+  case PrintOptionsType::PlusFlags:
+return getPrintOptionsFromPlusFlags(Flags);
+  }
+  llvm_unreachable("Unknown Multilib::PrintOptionsType");
 }
 
 LLVM_DUMP_METHOD void Multilib::dump() const {
@@ -44,14 +72,11 @@
 void Multilib::print(raw_ostream &OS) const {
   if (GCCSuffix.empty())
 OS << ".";
-  else {
+  else
 OS << StringRef(GCCSuffix).drop_front();
-  }
   OS << ";";
-  for (StringRef Flag : Flags) {
-if (Flag.front() == '+')
-  OS << "@" << Flag.substr(1);
-  }
+  for (StringRef Option : getPrintOptions())
+OS << "@" << Option.substr(1);
 }
 
 bool Multilib::operator==(const Multilib &Other) const {
Index: clang/include/clang/Driver/Multilib.h
===
--- clang/include/clang/Driver/Multilib.h
+++ clang/include/clang/Driver/Multilib.h
@@ -31,19 +31,39 @@
 public:
   using flags_list = std::vector;
 
+  /// When -print-multi-lib is used, this defines how the printed options must
+  /// be calculated.
+  enum class PrintOptionsTyp

[PATCH] D146757: [Driver] Enable defining multilib print options independently of flags

2023-04-05 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings added inline comments.



Comment at: clang/include/clang/Driver/Multilib.h:58
+   StringRef IncludeSuffix = {}, const flags_list &Flags = 
flags_list(),
+   PrintOptionsType PrintOptions = PrintOptionsType::PlusFlags,
+   const flags_list &PrintOptionsList = flags_list());

peter.smith wrote:
> How would someone using `makeMultilib()` from `MultilibBuilder` use these 
> parameters? If they can't do they need to? If so we may need something like a 
> makeMultilib overload to supply the extra parameters.
MultilibBuilder is constructed around the concept of using '+' and '-' to 
indicate which command line options are compatible and incompatible, so in that 
case you'd only want to use PlusFlags.



Comment at: clang/lib/Driver/Multilib.cpp:44
+  assert(PrintOptions == PrintOptionsType::List || PrintOptionsList.empty());
+}
+

peter.smith wrote:
> If there are any restrictions on the strings in PrintOptionsList could be 
> worth assertions. Please ignore if there are no restrictions.
There are restrictions - PrintOptionsList should only contain valid Clang 
options. However if you violate this then the only consequence is that the 
-print-multi-lib output will be equally invalid. Since there would be a lot of 
complexity involved in enforcing the restriction I think it's best to leave it 
unenforced.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146757

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


[PATCH] D147610: [RISCV][MC] Add support for experimental Zfbfmin extension

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

As documented, this extension includes FLH, FSH, FMV.H.X, and FMH.X.H as 
defined in Zfh/Zfhmin, but doesn't require either extension.

No Zfbfinxmin has been defined (though you would expect one in the future, for 
symmetry with Zfhinxmin). See issue 
https://github.com/riscv/riscv-bfloat16/issues/27.

This patch is not ready for merging because the fcvt.bf16.s encoding collides 
with fround.h from zfa. See issue 
https://github.com/riscv/riscv-bfloat16/issues/33. Applying this patch causes 
tests failures due to this. Posting in order to allow early review, though I 
intended to wait for the encoding clash to be resolved before pushing to get 
this committed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147610

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/docs/ReleaseNotes.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZfbfmin.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZfh.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zfbfmin-invalid.s
  llvm/test/MC/RISCV/rv32zfbfmin-valid.s
  llvm/test/MC/RISCV/rv64zhinx-invalid.s
  llvm/test/MC/RISCV/rv64zhinxmin-invalid.s

Index: llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
===
--- llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
+++ llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
@@ -1,7 +1,7 @@
 # RUN: not llvm-mc -triple riscv64 -mattr=+zhinxmin %s 2>&1 | FileCheck %s
 
 # Not support float registers
-flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal){{$}}
+flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts){{$}}
 
 # Invalid instructions
 fsh a5, 12(sp) # CHECK: :[[@LINE]]:5: error: invalid operand for instruction
Index: llvm/test/MC/RISCV/rv64zhinx-invalid.s
===
--- llvm/test/MC/RISCV/rv64zhinx-invalid.s
+++ llvm/test/MC/RISCV/rv64zhinx-invalid.s
@@ -1,7 +1,7 @@
 # RUN: not llvm-mc -triple riscv64 -mattr=+zhinx %s 2>&1 | FileCheck %s
 
 # Not support float registers
-flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal){{$}}
+flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts){{$}}
 
 # Invalid instructions
 fsh a5, 12(sp) # CHECK: :[[@LINE]]:5: error: invalid operand for instruction
Index: llvm/test/MC/RISCV/rv32zfbfmin-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zfbfmin-valid.s
@@ -0,0 +1,56 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zfbfmin,+f -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zfbfmin,+f -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zfbfmin,+d < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zfbfmin,+f -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zfbfmin,+d < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zfbfmin,+f -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: flh ft0, 12(a0)
+# CHECK-ASM: encoding: [0x07,0x10,0xc5,0x00]
+flh f0, 12(a0)
+# CHECK-ASM-AND-OBJ: flh ft1, 4(ra)
+# CHECK-ASM: encoding: [0x87,0x90,0x40,0x00]
+flh f1, +4(ra)
+# CHECK-ASM-AND-OBJ: flh ft2, -2048(a3)
+# CHECK-ASM: encoding: [0x07,0x91,0x06,0x80]
+flh f2, -2048(x13)
+# CHECK-ASM-AND-OBJ: flh ft3, -2048(s1)
+# CHECK-ASM: encoding: [0x87,0x91,0x04,0x8

[PATCH] D147611: [RISCV][MC] Add support for experimental Zvfbfmin extension

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

The current specification version doesn't explicitly mark Zvfbfmin as dependent 
on Zve32f, but this is believed to be an oversight. See 
https://github.com/riscv/riscv-bfloat16/pull/34.

Zvfbfmin does not appear to have a dependency on Zfbfmin as currently specified.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147611

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/docs/ReleaseNotes.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfoV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZvfbf.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rvv/zvfbfmin.s

Index: llvm/test/MC/RISCV/rvv/zvfbfmin.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvfbfmin.s
@@ -0,0 +1,42 @@
+# RUN: llvm-mc -triple=riscv32 -show-encoding -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv32 -show-encoding -mattr=+v,+f %s 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv32 -filetype=obj -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:| llvm-objdump -d --mattr=+f,+experimental-zvfbfmin - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv32 -filetype=obj -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+# RUN: llvm-mc -triple=riscv64 -show-encoding -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv64 -show-encoding -mattr=+v,+f %s 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv64 -filetype=obj -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:| llvm-objdump -d --mattr=+f,+experimental-zvfbfmin - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv64 -filetype=obj -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+# CHECK-INST: vfncvtbf16.f.f.w v8, v4, v0.t
+# CHECK-ENCODING: [0x57,0x94,0x4e,0x48]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfmin' (Vector BF16 Converts){{$}}
+# CHECK-UNKNOWN: 57 94 4e 48 
+vfncvtbf16.f.f.w v8, v4, v0.t
+
+# CHECK-INST: vfncvtbf16.f.f.w v8, v4
+# CHECK-ENCODING: [0x57,0x94,0x4e,0x4a]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfmin' (Vector BF16 Converts){{$}}
+# CHECK-UNKNOWN: 57 94 4e 4a 
+vfncvtbf16.f.f.w v8, v4
+
+# CHECK-INST: vfwcvtbf16.f.f.v v8, v4, v0.t
+# CHECK-ENCODING: [0x57,0x94,0x46,0x48]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfmin' (Vector BF16 Converts){{$}}
+# CHECK-UNKNOWN: 57 94 46 48 
+vfwcvtbf16.f.f.v v8, v4, v0.t
+
+# CHECK-INST: vfwcvtbf16.f.f.v v8, v4
+# CHECK-ENCODING: [0x57,0x94,0x46,0x4a]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfmin' (Vector BF16 Converts){{$}}
+# CHECK-UNKNOWN: 57 94 46 4a 
+vfwcvtbf16.f.f.v v8, v4
Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -239,3 +239,6 @@
 
 .attribute arch, "rv32if_zfbfmin0p2"
 # CHECK: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin0p2"
+
+.attribute arch, "rv32if_zvfbfmin0p2"
+# CHECK: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfbfmin0p2_zvl32b1p0"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -66,6 +66,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+zve32x -mattr=+experimental-zvksh %s -o - | FileCheck --check-prefix=RV32ZVKSH %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicond %s -o - | FileCheck --check-prefix=RV32ZICOND %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZFBFMIN %s
+; RUN: llc -mtriple=riscv32 -mattr=+f,+experimental-zvfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZVFBFMIN %s
 
 ; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-pref

[PATCH] D147612: [RISCV][MC] Add support for experimental Zvfbfwma extension

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

The current specification version doesn't explicitly mark Zvfbfwma as dependent 
on Zve32f, but this is believed to be an oversight. See 
https://github.com/riscv/riscv-bfloat16/pull/34.

As currently specified, Zvfbfwma does not appear to have a dependency on 
Zvfbfmin or Zfbfmin.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147612

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/docs/ReleaseNotes.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZvfbf.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv64zhinx-invalid.s
  llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
  llvm/test/MC/RISCV/rvv/zvfbfwma-invalid.s
  llvm/test/MC/RISCV/rvv/zvfbfwma.s

Index: llvm/test/MC/RISCV/rvv/zvfbfwma.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvfbfwma.s
@@ -0,0 +1,68 @@
+# RUN: llvm-mc -triple=riscv32 -show-encoding -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv32 -show-encoding -mattr=+v,+f %s 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv32 -filetype=obj -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:| llvm-objdump -d --mattr=+f,+experimental-zvfbfwma - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv32 -filetype=obj -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+# RUN: llvm-mc -triple=riscv64 -show-encoding -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv64 -show-encoding -mattr=+v,+f %s 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv64 -filetype=obj -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:| llvm-objdump -d --mattr=+f,+experimental-zvfbfwma - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv64 -filetype=obj -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+# CHECK-INST: vfwmaccbf16.vv v8, v20, v4, v0.t
+# CHECK-ENCODING: [0x57,0x14,0x4a,0x8c]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 57 14 4a 8c 
+vfwmaccbf16.vv v8, v20, v4, v0.t
+
+# CHECK-INST: vfwmaccbf16.vv v8, v20, v4
+# CHECK-ENCODING: [0x57,0x14,0x4a,0x8e]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 57 14 4a 8e 
+vfwmaccbf16.vv v8, v20, v4
+
+# CHECK-INST: vfwmaccbf16.vf v8, fa0, v4, v0.t
+# CHECK-ENCODING: [0x57,0x54,0x45,0x8c]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 57 54 45 8c 
+vfwmaccbf16.vf v8, fa0, v4, v0.t
+
+# CHECK-INST: vfwmaccbf16.vf v8, fa0, v4
+# CHECK-ENCODING: [0x57,0x54,0x45,0x8e]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 57 54 45 8e 
+vfwmaccbf16.vf v8, fa0, v4
+
+# Check scalar half FP load/store/move included in this extension.
+
+# CHECK-INST: flh ft0, 12(a0)
+# CHECK-ENCODING: [0x07,0x10,0xc5,0x00]
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 07 10 c5 00 
+flh f0, 12(a0)
+
+# CHECK-INST: fsh ft6, 2047(s4)
+# CHECK-ENCODING: [0xa7,0x1f,0x6a,0x7e]
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: a7 1f 6a 7e 
+fsh f6, 2047(s4)
+
+# CHECK-INST: fmv.x.h a2, fs7
+# CHECK-ENCODING: [0x53,0x86,0x0b,0xe4]
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widen

[PATCH] D147574: [NFC][clang] Fix Coverity static analyzer tool concerns about auto_causes_copy

2023-04-05 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.

Previous comments on this were here: https://reviews.llvm.org/D147552.  I've 
copy/pasted them into here to keep history at least somewhat reasonable.

This LGTM.




Comment at: clang/lib/AST/ComputeDependence.cpp:753
   // expansions.
-  for (auto A : E->template_arguments())
+  for (const auto &A : E->template_arguments())
 Deps |= toExprDependence(A.getArgument().getDependence());

Ends up being pretty sizable, TemplateArgumentLoc has a TemplateArgument (which 
we typically pass around by value), but it also has a TemplateArgumentLocInfo, 
which is a pair of pointers + a pair of source locations.



Comment at: clang/lib/Frontend/FrontendActions.cpp:885
 // Now let's print out any modules we did not see as part of the Primary.
-for (auto SM : SubModMap) {
+for (const auto &SM : SubModMap) {
   if (!SM.second.Seen && SM.second.Mod) {

A pair of a string and the other type, definitely worth saving the copies.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147574

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


[PATCH] D147610: [RISCV][MC] Add support for experimental Zfbfmin extension

2023-04-05 Thread Alex Bradbury via Phabricator via cfe-commits
asb updated this revision to Diff 511080.

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

https://reviews.llvm.org/D147610

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/docs/ReleaseNotes.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZfbfmin.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZfh.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zfbfmin-invalid.s
  llvm/test/MC/RISCV/rv32zfbfmin-valid.s
  llvm/test/MC/RISCV/rv64zhinx-invalid.s
  llvm/test/MC/RISCV/rv64zhinxmin-invalid.s

Index: llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
===
--- llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
+++ llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
@@ -1,7 +1,7 @@
 # RUN: not llvm-mc -triple riscv64 -mattr=+zhinxmin %s 2>&1 | FileCheck %s
 
 # Not support float registers
-flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal){{$}}
+flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts){{$}}
 
 # Invalid instructions
 fsh a5, 12(sp) # CHECK: :[[@LINE]]:5: error: invalid operand for instruction
Index: llvm/test/MC/RISCV/rv64zhinx-invalid.s
===
--- llvm/test/MC/RISCV/rv64zhinx-invalid.s
+++ llvm/test/MC/RISCV/rv64zhinx-invalid.s
@@ -1,7 +1,7 @@
 # RUN: not llvm-mc -triple riscv64 -mattr=+zhinx %s 2>&1 | FileCheck %s
 
 # Not support float registers
-flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal){{$}}
+flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts){{$}}
 
 # Invalid instructions
 fsh a5, 12(sp) # CHECK: :[[@LINE]]:5: error: invalid operand for instruction
Index: llvm/test/MC/RISCV/rv32zfbfmin-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zfbfmin-valid.s
@@ -0,0 +1,56 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zfbfmin,+f -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zfbfmin,+f -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zfbfmin,+d < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zfbfmin,+f -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zfbfmin,+d < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zfbfmin,+f -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: flh ft0, 12(a0)
+# CHECK-ASM: encoding: [0x07,0x10,0xc5,0x00]
+flh f0, 12(a0)
+# CHECK-ASM-AND-OBJ: flh ft1, 4(ra)
+# CHECK-ASM: encoding: [0x87,0x90,0x40,0x00]
+flh f1, +4(ra)
+# CHECK-ASM-AND-OBJ: flh ft2, -2048(a3)
+# CHECK-ASM: encoding: [0x07,0x91,0x06,0x80]
+flh f2, -2048(x13)
+# CHECK-ASM-AND-OBJ: flh ft3, -2048(s1)
+# CHECK-ASM: encoding: [0x87,0x91,0x04,0x80]
+flh f3, %lo(2048)(s1)
+# CHECK-ASM-AND-OBJ: flh ft4, 2047(s2)
+# CHECK-ASM: encoding: [0x07,0x12,0xf9,0x7f]
+flh f4, 2047(s2)
+# CHECK-ASM-AND-OBJ: flh ft5, 0(s3)
+# CHECK-ASM: encoding: [0x87,0x92,0x09,0x00]
+flh f5, 0(s3)
+
+# CHECK-ASM-AND-OBJ: fsh ft6, 2047(s4)
+# CHECK-ASM: encoding: [0xa7,0x1f,0x6a,0x7e]
+fsh f6, 2047(s4)
+# CHECK-ASM-AND-OBJ: fsh ft7, -2048(s5)
+# CHECK-ASM: encoding: [0x27,0x90,0x7a,0x80]
+fsh f7, -2048(s5)
+# CHECK-ASM-AND-OBJ: fsh fs0, -2048(s6)
+# CHECK-ASM: encoding: [0x27,0x10,0x8b,0x80]
+fsh f8, %lo(2048)(s6)
+# CHECK-ASM-AND-OBJ: fsh fs1, 999(s7)
+# CHECK-ASM: encoding: [0xa7,0x93,0x9b,0x3e]
+fsh f9, 999(s7)
+
+# CHECK-ASM-AND-OBJ: fmv.x.h a2, fs7
+# CHECK-ASM: encoding: [0x53,0x86,0x0b,0xe4]
+fmv.x.h a2, fs7
+# CHECK-ASM-AND-OBJ: fmv.h.x ft1, a6
+# CHECK-ASM: encoding: [0xd3,0x00,0x08,0xf4]
+fmv.h.x ft1, a6
+
+# CHECK-ASM-AND-OBJ: fcvt.s.bf16 fa0, ft0
+# CHECK-ASM: encoding: [0x53,0x75,0x60,0x10]
+fcvt.s.bf16 fa0, ft0
+# CHECK-ASM-AND-OBJ: fcvt.bf16.s ft2, fa2
+# CHECK-ASM: encoding: [0x53,0x71,0x46,0x44]
+fcvt.bf16.s ft2, fa2
Index: llvm/test/MC/RISCV/rv32zfbfmin-invalid.s
===
--- /dev/nul

[PATCH] D147611: [RISCV][MC] Add support for experimental Zvfbfmin extension

2023-04-05 Thread Alex Bradbury via Phabricator via cfe-commits
asb updated this revision to Diff 511081.

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

https://reviews.llvm.org/D147611

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/docs/ReleaseNotes.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfoV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZvfbf.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rvv/zvfbfmin.s

Index: llvm/test/MC/RISCV/rvv/zvfbfmin.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvfbfmin.s
@@ -0,0 +1,42 @@
+# RUN: llvm-mc -triple=riscv32 -show-encoding -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv32 -show-encoding -mattr=+v,+f %s 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv32 -filetype=obj -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:| llvm-objdump -d --mattr=+f,+experimental-zvfbfmin - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv32 -filetype=obj -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+# RUN: llvm-mc -triple=riscv64 -show-encoding -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv64 -show-encoding -mattr=+v,+f %s 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv64 -filetype=obj -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:| llvm-objdump -d --mattr=+f,+experimental-zvfbfmin - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv64 -filetype=obj -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+# CHECK-INST: vfncvtbf16.f.f.w v8, v4, v0.t
+# CHECK-ENCODING: [0x57,0x94,0x4e,0x48]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfmin' (Vector BF16 Converts){{$}}
+# CHECK-UNKNOWN: 57 94 4e 48 
+vfncvtbf16.f.f.w v8, v4, v0.t
+
+# CHECK-INST: vfncvtbf16.f.f.w v8, v4
+# CHECK-ENCODING: [0x57,0x94,0x4e,0x4a]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfmin' (Vector BF16 Converts){{$}}
+# CHECK-UNKNOWN: 57 94 4e 4a 
+vfncvtbf16.f.f.w v8, v4
+
+# CHECK-INST: vfwcvtbf16.f.f.v v8, v4, v0.t
+# CHECK-ENCODING: [0x57,0x94,0x46,0x48]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfmin' (Vector BF16 Converts){{$}}
+# CHECK-UNKNOWN: 57 94 46 48 
+vfwcvtbf16.f.f.v v8, v4, v0.t
+
+# CHECK-INST: vfwcvtbf16.f.f.v v8, v4
+# CHECK-ENCODING: [0x57,0x94,0x46,0x4a]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfmin' (Vector BF16 Converts){{$}}
+# CHECK-UNKNOWN: 57 94 46 4a 
+vfwcvtbf16.f.f.v v8, v4
Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -239,3 +239,6 @@
 
 .attribute arch, "rv32if_zfbfmin0p2"
 # CHECK: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin0p2"
+
+.attribute arch, "rv32if_zvfbfmin0p2"
+# CHECK: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfbfmin0p2_zvl32b1p0"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -66,6 +66,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+zve32x -mattr=+experimental-zvksh %s -o - | FileCheck --check-prefix=RV32ZVKSH %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicond %s -o - | FileCheck --check-prefix=RV32ZICOND %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZFBFMIN %s
+; RUN: llc -mtriple=riscv32 -mattr=+f,+experimental-zvfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZVFBFMIN %s
 
 ; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefixes=CHECK,RV64M %s
@@ -139,6 +140,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zve32x -mattr=+experimental-zvksh %s -o - | FileCheck --check-prefix=RV64ZVKSH %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zicond %s -o - | FileCheck --check-prefix=RV64ZICOND %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV64ZFBFMIN %s
+; RUN: llc -mtriple=riscv64 -mattr=+f,+experimental-zvfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV64ZVFBFMIN %s
 
 ; CHECK: .attribute 4, 16
 
@@ -207,6 +209,7 @@
 ; RV32ZVKSH: .attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_zvksh0p3_zvl32b1p0"
 ; RV32ZICOND: .attribute 5, "rv32i2p1_zicond1p0"
 ; RV32ZFBFMIN: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin0p2"
+; RV32ZVFBFMIN: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zve32f

[PATCH] D147612: [RISCV][MC] Add support for experimental Zvfbfwma extension

2023-04-05 Thread Alex Bradbury via Phabricator via cfe-commits
asb updated this revision to Diff 511082.

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

https://reviews.llvm.org/D147612

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/docs/ReleaseNotes.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZvfbf.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv64zhinx-invalid.s
  llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
  llvm/test/MC/RISCV/rvv/zvfbfwma-invalid.s
  llvm/test/MC/RISCV/rvv/zvfbfwma.s

Index: llvm/test/MC/RISCV/rvv/zvfbfwma.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvfbfwma.s
@@ -0,0 +1,68 @@
+# RUN: llvm-mc -triple=riscv32 -show-encoding -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv32 -show-encoding -mattr=+v,+f %s 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv32 -filetype=obj -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:| llvm-objdump -d --mattr=+f,+experimental-zvfbfwma - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv32 -filetype=obj -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+# RUN: llvm-mc -triple=riscv64 -show-encoding -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv64 -show-encoding -mattr=+v,+f %s 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv64 -filetype=obj -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:| llvm-objdump -d --mattr=+f,+experimental-zvfbfwma - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv64 -filetype=obj -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+# CHECK-INST: vfwmaccbf16.vv v8, v20, v4, v0.t
+# CHECK-ENCODING: [0x57,0x14,0x4a,0x8c]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 57 14 4a 8c 
+vfwmaccbf16.vv v8, v20, v4, v0.t
+
+# CHECK-INST: vfwmaccbf16.vv v8, v20, v4
+# CHECK-ENCODING: [0x57,0x14,0x4a,0x8e]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 57 14 4a 8e 
+vfwmaccbf16.vv v8, v20, v4
+
+# CHECK-INST: vfwmaccbf16.vf v8, fa0, v4, v0.t
+# CHECK-ENCODING: [0x57,0x54,0x45,0x8c]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 57 54 45 8c 
+vfwmaccbf16.vf v8, fa0, v4, v0.t
+
+# CHECK-INST: vfwmaccbf16.vf v8, fa0, v4
+# CHECK-ENCODING: [0x57,0x54,0x45,0x8e]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 57 54 45 8e 
+vfwmaccbf16.vf v8, fa0, v4
+
+# Check scalar half FP load/store/move included in this extension.
+
+# CHECK-INST: flh ft0, 12(a0)
+# CHECK-ENCODING: [0x07,0x10,0xc5,0x00]
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 07 10 c5 00 
+flh f0, 12(a0)
+
+# CHECK-INST: fsh ft6, 2047(s4)
+# CHECK-ENCODING: [0xa7,0x1f,0x6a,0x7e]
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: a7 1f 6a 7e 
+fsh f6, 2047(s4)
+
+# CHECK-INST: fmv.x.h a2, fs7
+# CHECK-ENCODING: [0x53,0x86,0x0b,0xe4]
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 53 86 0b e4 
+fmv.x.h a2, fs7
+
+# CHECK-INST: fmv.h.x ft1, a6
+# CHECK-ENCODING: [0xd3,0x00,0x08,0xf4]
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: d3 00 08 f4 
+fmv.h.x ft1, a6
Index: llvm/test/MC/RISCV/rvv/zvfbfwma-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvfbfwma-invalid.s
@@ -0,0 +1,11 @@
+# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-zvfbfwma,+d < %s 2>&1 | \
+# RUN:   FileCheck %s
+# RUN: not llvm-mc -triple riscv64 -mattr=+experimental-zvfbfwma,+d < %s 2>&1 | \
+# RUN:   FileCheck %s

[PATCH] D144269: [Analyzer] Show "taint originated here" note of alpha.security.taint.TaintPropagation checker at the correct place

2023-04-05 Thread Daniel Krupp via Phabricator via cfe-commits
dkrupp updated this revision to Diff 511078.
dkrupp marked 21 inline comments as done.
dkrupp added a comment.

@steakhal thanks for your review. I tried to address all your concerns.
I added an extra test case too (multipleTaintSources(..)) which highlights the 
limitation of the current patch: If multiple tainted "variables" reach a sink, 
we only generate diagnostics for one of them. The main reason is that the 
isTainted() function returns a single tainted Symbolref instead of a vector of 
Symbolrefs if there are multiple instances. 
I highlighted this in the test and the implementation.

I think this could be still an acceptable limitation for now, because as the 
user sanitizes one of the tainted variables, he will get a new diagnostics for 
the remaining one(s).

So I suggest to address this limitation in  follow-up patche(s).
The implementation as is already greatly improves the understandability of the 
reports.


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

https://reviews.llvm.org/D144269

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Taint.h
  clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
  clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
  clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/Taint.cpp
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/lib/StaticAnalyzer/Core/CommonBugCategories.cpp
  clang/test/Analysis/taint-diagnostic-visitor.c
  clang/test/Analysis/taint-tester.c

Index: clang/test/Analysis/taint-tester.c
===
--- clang/test/Analysis/taint-tester.c
+++ clang/test/Analysis/taint-tester.c
@@ -122,7 +122,7 @@
   fscanf(pp, "%d", &ii);
   int jj = ii;// expected-warning + {{tainted}}
 
-  fscanf(p, "%d", &ii);
+  fscanf(p, "%d", &ii);// expected-warning + {{tainted}}
   int jj2 = ii;// expected-warning + {{tainted}}
 
   ii = 3;
Index: clang/test/Analysis/taint-diagnostic-visitor.c
===
--- clang/test/Analysis/taint-diagnostic-visitor.c
+++ clang/test/Analysis/taint-diagnostic-visitor.c
@@ -2,13 +2,24 @@
 
 // This file is for testing enhanced diagnostics produced by the GenericTaintChecker
 
+typedef unsigned long size_t;
+struct _IO_FILE;
+typedef struct _IO_FILE FILE;
+
 int scanf(const char *restrict format, ...);
 int system(const char *command);
+char* getenv( const char* env_var );
+size_t strlen( const char* str );
+void *malloc(size_t size );
+void free( void *ptr );
+char *fgets(char *str, int n, FILE *stream);
+FILE *stdin;
 
 void taintDiagnostic(void)
 {
   char buf[128];
   scanf("%s", buf); // expected-note {{Taint originated here}}
+// expected-note@-1 {{Taint propagated to argument 2}}
   system(buf); // expected-warning {{Untrusted data is passed to a system call}} // expected-note {{Untrusted data is passed to a system call (CERT/STR02-C. Sanitize data passed to complex subsystems)}}
 }
 
@@ -16,6 +27,7 @@
   int index;
   int Array[] = {1, 2, 3, 4, 5};
   scanf("%d", &index); // expected-note {{Taint originated here}}
+   // expected-note@-1 {{Taint propagated to argument 2}}
   return Array[index]; // expected-warning {{Out of bound memory access (index is tainted)}}
// expected-note@-1 {{Out of bound memory access (index is tainted)}}
 }
@@ -23,6 +35,7 @@
 int taintDiagnosticDivZero(int operand) {
   scanf("%d", &operand); // expected-note {{Value assigned to 'operand'}}
  // expected-note@-1 {{Taint originated here}}
+ // expected-note@-2 {{Taint propagated to argument 2}}
   return 10 / operand; // expected-warning {{Division by a tainted value, possibly zero}}
// expected-note@-1 {{Division by a tainted value, possibly zero}}
 }
@@ -31,6 +44,71 @@
   int x;
   scanf("%d", &x); // expected-note {{Value assigned to 'x'}}
// expected-note@-1 {{Taint originated here}}
+   // expected-note@-2 {{Taint propagated to argument 2}}
   int vla[x]; // expected-warning {{Declared variable-length array (VLA) has tainted size}}
   // expected-note@-1 {{Declared variable-length array (VLA) has tainted size}}
 }
+
+
+//Tests if the originated note is correctly placed even if the path is
+//propagating through variables and expressions
+char* taintDiagnosticPropagation(){
+  char *pathbuf;
+  char *pathlist=getenv("PATH"); // expected-note {{Taint originated here}}
+ // expected-note@-1 {{Taint propagated to the return value}}
+  if (pathlist){ // expected-note {{Assuming 'pathlist' is non-null}}
+	   // expected-note@-1 {{Taking true branch}}
+pathbuf=(char*) malloc(strlen(pathlist)+1); // expected-warning{{Untrusted data is used to specify the buf

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

2023-04-05 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 511084.
junaire added a comment.

Add IncrementalASTConsumer


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalASTConsumer.cpp
  clang/lib/Interpreter/IncrementalASTConsumer.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +281,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -314,4 +318,38 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_EQ(V2.getAs(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.castAs(), 3);
+
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V3));
+  EXPECT_EQ(V3.getInt(), 42);
+  EXPECT_TRUE(V3.getType()->isIntegerType());
+
+  // Change the global from the compiled code.
+  setGlobal(43);
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 43);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -19849,6 +19849,15 @@
   Context.getTranslationUnitDecl()->addDecl(New);
   return New;
 }
+Decl *Sema::SynthesizeDeclForValuePrinting(Stmt *S) {
+  Expr *E = cast(S);
+  if (ValuePrintingTransformer) {
+Decl *D = (*ValuePrintingTransformer)(E);
+Context.getTranslationUnitDec

[PATCH] D144269: [Analyzer] Show "taint originated here" note of alpha.security.taint.TaintPropagation checker at the correct place

2023-04-05 Thread Daniel Krupp via Phabricator via cfe-commits
dkrupp added a comment.

All comments addressed. Thanks for the review @steakhal .




Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:162
+  const CallEvent& Call) {
+  const LocationContext* LC = Call.getCalleeStackFrame(0);
+

steakhal wrote:
> If the `Call` parameter is only used for acquiring the `LocationContext`, 
> wouldn't it be more descriptive to directly pass the `LocationContext` to the 
> function instead?
> I'm also puzzled that we use `getCalleeStackFrame` here. I rarely ever see 
> this function, so I'm a bit worried if this pick was intentional. That we 
> pass the `0` as the `BlockCount` argument only reinforces this instinct.
The call.getCalleeStackFrame(0) gets the location context of the actual call 
that we are analyzing (in the pre or postcall), and that's what we need to mark 
interesting. It is intentionally used like this. I changed the parameter to 
locationcontext as use suggested.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:169
+// We give diagnostics only for taint related reports
+if (!BR.isInteresting(LC) ||
+BR.getBugType().getCategory() != categories::TaintedData) {

steakhal wrote:
> What does the first half of this condition guard against?
> Do you have a test for it to demonstrate?
To only follow taint propagation to function calls which actually result in 
tainted variables used in the report and not every function which returns a 
tainted variable. 

char* taintDiagnosticPropagation2() is such a test which is failing without 
this due to giving extra unrelated propagation notes.





Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:214
+  << TaintedArgs.at(i) << "\n");
+  Out << "Taint propagated to argument " << TaintedArgs.at(i);
+} else {

steakhal wrote:
> So, if `TaintedSymbols.size() > 1`, then the note message will look weird.
> Could you please have a test for this?
Test added multipleTaintedArgs (). I could not provoke the multi-argument 
message as we only track-back one tainted symbol now.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:871
+  }else{
+ LLVM_DEBUG(llvm::dbgs() << "Strange. Return value not tainted.\n");
+ LLVM_DEBUG(Call.getReturnValue().dumpToStream(llvm::dbgs()));

steakhal wrote:
> I cannot see a test against the "Strange" string. Is this dead code?
> Same for the other block.
It was a debugging code, which I removed. I noticed that in some cases (e.g. if 
the argument pointer is pointing to an unknown area) we don't get back a 
tainted symbol even though we call the addtaint on the arg/return value.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:919-922
+//Add taintedness to stdin parameters
+if (isStdin(C.getSVal(E),C.getASTContext())){
+  State = addTaint(State, C.getSVal(E));
+}

steakhal wrote:
> I just want to get it confirmed that this hunk is unrelated to your change 
> per-say. Is it?
> BTW I don't mind this change being part of this patch, rather the opposite. 
> Finally, we will have it.
It is related in the sense that in isTainted() function call did not return a 
valid SymbolRef for stdin if we did not make the stdin tainted when we first 
see it. Caused  testcase to fail as it was before. Now it is handled similarly 
to other tainted symbols.



Comment at: clang/lib/StaticAnalyzer/Checkers/Taint.cpp:228-230
+  if (SymbolRef TSR =
+  isTainted(State, SRV->getRegion(), Kind))
+return TSR;

steakhal wrote:
> What does `TSR` abbreviate? I would find `TaintedSym` more descriptive.
TSR = Tainted Symbol Ref

but I changed it as you suggested.



Comment at: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp:220-228
+if (Kind == VLA_Tainted)
+  BT.reset(new BugType(this,
+   "Dangerous variable-length array (VLA) declaration",
+   categories::TaintedData));
+else
+  BT.reset(new BugType(this,
+   "Dangerous variable-length array (VLA) declaration",

steakhal wrote:
> Why don't we use a distinct BugType for this?
You mean a new bug type instances? Would there be an advantage for that? Seemed 
to be simpler this way. To distinguish identify the tainted reports with the 
bug category.


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

https://reviews.llvm.org/D144269

___
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-05 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 511090.
junaire added a comment.

Remove old code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalASTConsumer.cpp
  clang/lib/Interpreter/IncrementalASTConsumer.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +281,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -314,4 +318,38 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_EQ(V2.getAs(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.castAs(), 3);
+
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V3));
+  EXPECT_EQ(V3.getInt(), 42);
+  EXPECT_TRUE(V3.getType()->isIntegerType());
+
+  // Change the global from the compiled code.
+  setGlobal(43);
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 43);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except in the special case where
   // we're trying to skip to EOF).
@@ -616,8 +617,8

[PATCH] D146873: [2/N][POC][Clang][RISCV] Define RVV tuple types

2023-04-05 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 511093.
eopXD added a comment.

Rebase upon change of parent patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146873

Files:
  clang/include/clang/Basic/RISCVVTypes.def
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-0.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-1.c
  clang/test/Sema/riscv-types.c

Index: clang/test/Sema/riscv-types.c
===
--- clang/test/Sema/riscv-types.c
+++ clang/test/Sema/riscv-types.c
@@ -133,6 +133,9 @@
 
   // CHECK: __rvv_int8mf2_t x43;
   __rvv_int8mf2_t x43;
+
+  // CHECK: __rvv_int32m1x2_t x44;
+  __rvv_int32m1x2_t x44;
 }
 
 typedef __rvv_bool4_t vbool4_t;
Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-1.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-1.c
@@ -0,0 +1,49 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
+// RUN: %clang_cc1 -triple riscv64 -target-feature +zve32x -disable-O0-optnone \
+// RUN:   -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s
+
+#include 
+
+// Declare local variable
+// CHECK-LABEL: define dso_local void @foo
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret void
+//
+void foo() {
+  __rvv_int32m1x2_t v_tuple;
+}
+
+// Declare local variable and return
+// CHECK-LABEL: define dso_local { ,  } @bar
+// CHECK-SAME: () #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret { ,  } undef
+//
+__rvv_int32m1x2_t bar() {
+  __rvv_int32m1x2_t v_tuple;
+  return v_tuple;
+}
+
+// Pass as function parameter
+// CHECK-LABEL: define dso_local void @baz
+// CHECK-SAME: ( [[V_TUPLE_COERCE0:%.*]],  [[V_TUPLE_COERCE1:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = insertvalue { ,  } undef,  [[V_TUPLE_COERCE0]], 0
+// CHECK-NEXT:[[TMP1:%.*]] = insertvalue { ,  } [[TMP0]],  [[V_TUPLE_COERCE1]], 1
+// CHECK-NEXT:ret void
+//
+void baz(__rvv_int32m1x2_t v_tuple) {
+}
+
+// Pass as function parameter and return
+// CHECK-LABEL: define dso_local { ,  } @qux
+// CHECK-SAME: ( [[V_TUPLE_COERCE0:%.*]],  [[V_TUPLE_COERCE1:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = insertvalue { ,  } undef,  [[V_TUPLE_COERCE0]], 0
+// CHECK-NEXT:[[TMP1:%.*]] = insertvalue { ,  } [[TMP0]],  [[V_TUPLE_COERCE1]], 1
+// CHECK-NEXT:ret { ,  } [[TMP1]]
+//
+__rvv_int32m1x2_t qux(__rvv_int32m1x2_t v_tuple) {
+  return v_tuple;
+}
Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-0.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-0.c
@@ -0,0 +1,65 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
+// RUN: %clang_cc1 -triple riscv64 -target-feature +zve32x -O0 \
+// RUN:   -emit-llvm %s -o - | FileCheck %s
+
+#include 
+
+// Declare local variable
+// CHECK-LABEL: define dso_local void @foo
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[V_TUPLE:%.*]] = alloca { ,  }, align 4
+// CHECK-NEXT:ret void
+//
+void foo() {
+  __rvv_int32m1x2_t v_tuple;
+}
+
+// Declare local variable and return
+// CHECK-LABEL: define dso_local { ,  } @bar
+// CHECK-SAME: () #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[V_TUPLE:%.*]] = alloca { ,  }, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load { ,  }, ptr [[V_TUPLE]], align 4
+// CHECK-NEXT:ret { ,  } [[TMP0]]
+//
+__rvv_int32m1x2_t bar() {
+  __rvv_int32m1x2_t v_tuple;
+  return v_tuple;
+}
+
+// Pass as function parameter
+// CHECK-LABEL: define dso_local void @baz
+// CHECK-SAME: ( [[V_TUPLE_COERCE0:%.*]],  [[V_TUPLE_COERCE1:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[V_TUPLE:%.*]] = alloca { ,  }, align 4
+// CHECK-NEXT:[[V_TUPLE_ADDR:%.*]] = alloca { ,  }, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load { ,  }, ptr [[V_TUPLE]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = insertvalue { ,  } [[TMP0]],  [[V_TUPLE_COERCE0]], 0
+// CHECK-NEXT:[[TMP2:%.*]] = insertvalue { ,  } [[TMP1]],  [[V_TUPLE_COERCE1]], 1
+// CHECK-NEXT:store { ,  } [[TMP2]], ptr [[V_TUPLE]], align 4
+// CHECK-NEXT:[[V_TUPLE1:%.*]] = load { ,  }, ptr [[V_TUPLE]], align 4
+// CHECK-NEXT:store { ,  } [[V_TUPLE1]], ptr [[V_TUPLE_ADDR]], align 4
+// CHECK-NEXT:ret void
+//
+void baz(__rvv_int32m1x2_t v_tuple) {
+}
+
+// Pass as function parameter and return
+// CHECK-LABEL: define dso_local { ,  } @qux
+// CHECK-SAME: ( [[V_TUPLE_COERCE0:%.*]],  [[V_TUPLE_COERCE1:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+//

[clang] 8ee5029 - [clang] don't serialize MODULE_DIRECTORY with ModuleFileHomeIsCwd

2023-04-05 Thread Richard Howell via cfe-commits

Author: Richard Howell
Date: 2023-04-05T07:19:48-07:00
New Revision: 8ee5029b225ba1ff415e0a0a6a68dc4e3efee4d1

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

LOG: [clang] don't serialize MODULE_DIRECTORY with ModuleFileHomeIsCwd

Fix a bug in the MODULE_DIRECTORY serialization logic
that would cause MODULE_DIRECTORY to be serialized when
`-fmodule-file-home-is-cwd` is specified.

This matches the original logic added in:
https://github.com/apple/llvm-project/commit/f7b41371d9ede1aecf0930e5bd4a463519264633

Reviewed By: keith

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

Added: 


Modified: 
clang/lib/Serialization/ASTWriter.cpp
clang/test/Modules/module-file-home-is-cwd.m

Removed: 




diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 177a3c3a34d73..245304254811a 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1288,11 +1288,11 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, 
ASTContext &Context,
 // If the home of the module is the current working directory, then we
 // want to pick up the cwd of the build process loading the module, not
 // our cwd, when we load this module.
-if (!(PP.getHeaderSearchInfo()
+if (!PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd &&
+(!PP.getHeaderSearchInfo()
   .getHeaderSearchOpts()
   .ModuleMapFileHomeIsCwd ||
-  PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd) 
||
-WritingModule->Directory->getName() != StringRef(".")) {
+ WritingModule->Directory->getName() != StringRef("."))) {
   // Module directory.
   auto Abbrev = std::make_shared();
   Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY));

diff  --git a/clang/test/Modules/module-file-home-is-cwd.m 
b/clang/test/Modules/module-file-home-is-cwd.m
index 706b815e6d0c2..a3875d578bb60 100644
--- a/clang/test/Modules/module-file-home-is-cwd.m
+++ b/clang/test/Modules/module-file-home-is-cwd.m
@@ -5,11 +5,12 @@
 // RUN: -fmodules-embed-all-files %S/Inputs/normal-module-map/module.map \
 // RUN: -o %t/mod.pcm
 // RUN: llvm-bcanalyzer --dump --disable-histogram %t/mod.pcm | FileCheck %s
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t/mod.pcm | FileCheck %s 
--check-prefix=INPUT
 
-// CHECK:  blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}module.map'
-// CHECK:  blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}a2.h'
-// CHECK:  blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}a1.h'
 // CHECK-NOT: MODULE_DIRECTORY
+// INPUT:  blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}module.map'
+// INPUT:  blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}a2.h'
+// INPUT:  blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}a1.h'
 
 @import libA;
 



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


[PATCH] D147561: [clang] don't serialize MODULE_DIRECTORY with ModuleFileHomeIsCwd

2023-04-05 Thread Richard Howell via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8ee5029b225b: [clang] don't serialize MODULE_DIRECTORY 
with ModuleFileHomeIsCwd (authored by rmaz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147561

Files:
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/module-file-home-is-cwd.m


Index: clang/test/Modules/module-file-home-is-cwd.m
===
--- clang/test/Modules/module-file-home-is-cwd.m
+++ clang/test/Modules/module-file-home-is-cwd.m
@@ -5,11 +5,12 @@
 // RUN: -fmodules-embed-all-files %S/Inputs/normal-module-map/module.map \
 // RUN: -o %t/mod.pcm
 // RUN: llvm-bcanalyzer --dump --disable-histogram %t/mod.pcm | FileCheck %s
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t/mod.pcm | FileCheck %s 
--check-prefix=INPUT
 
-// CHECK:  blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}module.map'
-// CHECK:  blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}a2.h'
-// CHECK:  blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}a1.h'
 // CHECK-NOT: MODULE_DIRECTORY
+// INPUT:  blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}module.map'
+// INPUT:  blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}a2.h'
+// INPUT:  blob data = 
'Inputs{{/|\\}}normal-module-map{{/|\\}}a1.h'
 
 @import libA;
 
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1288,11 +1288,11 @@
 // If the home of the module is the current working directory, then we
 // want to pick up the cwd of the build process loading the module, not
 // our cwd, when we load this module.
-if (!(PP.getHeaderSearchInfo()
+if (!PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd &&
+(!PP.getHeaderSearchInfo()
   .getHeaderSearchOpts()
   .ModuleMapFileHomeIsCwd ||
-  PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd) 
||
-WritingModule->Directory->getName() != StringRef(".")) {
+ WritingModule->Directory->getName() != StringRef("."))) {
   // Module directory.
   auto Abbrev = std::make_shared();
   Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY));


Index: clang/test/Modules/module-file-home-is-cwd.m
===
--- clang/test/Modules/module-file-home-is-cwd.m
+++ clang/test/Modules/module-file-home-is-cwd.m
@@ -5,11 +5,12 @@
 // RUN: -fmodules-embed-all-files %S/Inputs/normal-module-map/module.map \
 // RUN: -o %t/mod.pcm
 // RUN: llvm-bcanalyzer --dump --disable-histogram %t/mod.pcm | FileCheck %s
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t/mod.pcm | FileCheck %s --check-prefix=INPUT
 
-// CHECK:  blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}module.map'
-// CHECK:  blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a2.h'
-// CHECK:  blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a1.h'
 // CHECK-NOT: MODULE_DIRECTORY
+// INPUT:  blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}module.map'
+// INPUT:  blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a2.h'
+// INPUT:  blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a1.h'
 
 @import libA;
 
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1288,11 +1288,11 @@
 // If the home of the module is the current working directory, then we
 // want to pick up the cwd of the build process loading the module, not
 // our cwd, when we load this module.
-if (!(PP.getHeaderSearchInfo()
+if (!PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd &&
+(!PP.getHeaderSearchInfo()
   .getHeaderSearchOpts()
   .ModuleMapFileHomeIsCwd ||
-  PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd) ||
-WritingModule->Directory->getName() != StringRef(".")) {
+ WritingModule->Directory->getName() != StringRef("."))) {
   // Module directory.
   auto Abbrev = std::make_shared();
   Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147615: [clang][Sema][NFC] Save token name instead of the full token

2023-04-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added a reviewer: aaron.ballman.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This makes it a bit clearer why we're saving the token (so no need for the 
later comment).

I'm just not 100% sure about the lifetime of the token name.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147615

Files:
  clang/lib/Parse/ParseDeclCXX.cpp


Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -958,8 +958,8 @@
   assert(Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert) &&
  "Not a static_assert declaration");
 
-  // Save the token used for static assertion.
-  Token SavedTok = Tok;
+  // Save the token name used for static assertion.
+  const char *TokName = Tok.getName();
 
   if (Tok.is(tok::kw__Static_assert) && !getLangOpts().C11)
 Diag(Tok, diag::ext_c11_feature) << Tok.getName();
@@ -1027,9 +1027,7 @@
   T.consumeClose();
 
   DeclEnd = Tok.getLocation();
-  // Passing the token used to the error message.
-  ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert,
-   SavedTok.getName());
+  ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert, TokName);
 
   return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, 
AssertExpr.get(),
   AssertMessage.get(),


Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -958,8 +958,8 @@
   assert(Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert) &&
  "Not a static_assert declaration");
 
-  // Save the token used for static assertion.
-  Token SavedTok = Tok;
+  // Save the token name used for static assertion.
+  const char *TokName = Tok.getName();
 
   if (Tok.is(tok::kw__Static_assert) && !getLangOpts().C11)
 Diag(Tok, diag::ext_c11_feature) << Tok.getName();
@@ -1027,9 +1027,7 @@
   T.consumeClose();
 
   DeclEnd = Tok.getLocation();
-  // Passing the token used to the error message.
-  ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert,
-   SavedTok.getName());
+  ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert, TokName);
 
   return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, AssertExpr.get(),
   AssertMessage.get(),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147574: [NFC][clang] Fix Coverity static analyzer tool concerns about auto_causes_copy

2023-04-05 Thread Soumi Manna via Phabricator via cfe-commits
Manna added a comment.

Thanks @erichkeane.

Is this known failure?

Failed Tests (1):

  Clang :: SemaCXX/warn-unsafe-buffer-usage-fixits-addressof-arraysubscript.cpp

https://buildkite.com/llvm-project/premerge-checks/builds/145026#01874e21-00e2-47a9-9bc4-975357d197ef


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147574

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


[PATCH] D147324: [OpenMP][MLIR][Flang][bbc][Driver] Add OpenMP RTL Flags to Flang and generate omp.FlagsAttr from them

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

Hi @awarzynski would it please be possible to get this reviewed when you have a 
spare moment or few, it's essentially the segment of the modifications from 
this patch which you accepted: https://reviews.llvm.org/D145264 the lowering 
has been separated into a different phab review as was requested. This pass 
just adds flags and creates the attribute on the Module! So it is hopefully 
good to go or close to it depending on your feedback :-) although I'll commit 
it at the same time as the lowering segment of the pass is accepted.

Thank you very much as always for your time reviewing my patches, I appreciate 
it greatly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147324

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


[PATCH] D147574: [NFC][clang] Fix Coverity static analyzer tool concerns about auto_causes_copy

2023-04-05 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D147574#4245877 , @Manna wrote:

> Thanks @erichkeane.
>
> Is this known failure?
>
> Failed Tests (1):
>
>   Clang :: 
> SemaCXX/warn-unsafe-buffer-usage-fixits-addressof-arraysubscript.cpp
>
> https://buildkite.com/llvm-project/premerge-checks/builds/145026#01874e21-00e2-47a9-9bc4-975357d197ef

Looks like the commit that added that test got reverted here 
d5c428356f6ee107a97977eb9ef1aa4d5fa0c378 
 because 
it caused the test to fail, so it looks like the answer is 'yes'.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147574

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


[PATCH] D146042: [clang-format] Fix numerous issues with "LambdaBodyIndentation: OuterScope" option

2023-04-05 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 updated this revision to Diff 511098.
jp4a50 added a comment.

Add release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146042

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22009,9 +22009,9 @@
   verifyFormat("void test() {\n"
"  (\n"
"  []() -> auto {\n"
-   "int b = 32;\n"
-   "return 3;\n"
-   "  },\n"
+   "int b = 32;\n"
+   "return 3;\n"
+   "  },\n"
"  foo, bar)\n"
"  .foo();\n"
"}",
@@ -22025,17 +22025,82 @@
"  .bar();\n"
"}",
Style);
-  Style = getGoogleStyle();
-  Style.LambdaBodyIndentation = FormatStyle::LBI_OuterScope;
-  verifyFormat("#define A   \\\n"
-   "  [] {  \\\n"
-   "xxx(\\\n"
-   "x); \\\n"
-   "  }",
-   Style);
-  // TODO: The current formatting has a minor issue that's not worth fixing
-  // right now whereby the closing brace is indented relative to the signature
-  // instead of being aligned. This only happens with macros.
+  verifyFormat("#define A  \\\n"
+   "  [] { \\\n"
+   "xxx(   \\\n"
+   "x);\\\n"
+   "  }",
+   Style);
+  verifyFormat("void foo() {\n"
+   "  aFunction(1, b(c(foo, bar, baz, [](d) {\n"
+   "auto f = e(d);\n"
+   "return f;\n"
+   "  })));\n"
+   "}",
+   Style);
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  verifyFormat("void foo() {\n"
+   "  aFunction(\n"
+   "  1, b(c(\n"
+   " [](d) -> Foo {\n"
+   "auto f = e(d);\n"
+   "return f;\n"
+   "  },\n"
+   " foo, Bar{},\n"
+   " [] {\n"
+   "auto g = h();\n"
+   "return g;\n"
+   "  },\n"
+   " baz)));\n"
+   "}",
+   Style);
+  verifyFormat("void foo() {\n"
+   "  aFunction(1, b(c(foo, Bar{}, baz, [](d) -> Foo {\n"
+   "auto f = e(\n"
+   "foo,\n"
+   "[&] {\n"
+   "  auto g = h();\n"
+   "  return g;\n"
+   "},\n"
+   "qux,\n"
+   "[&] -> Bar {\n"
+   "  auto i = j();\n"
+   "  return i;\n"
+   "});\n"
+   "return f;\n"
+   "  })));\n"
+   "}",
+   Style);
+  verifyFormat("Namespace::Foo::Foo(\n"
+   "LongClassName bar, AnotherLongClassName baz)\n"
+   ": baz{baz}, func{[&] {\n"
+   "  auto qux = bar;\n"
+   "  return aFunkyFunctionCall(qux);\n"
+   "}} {}",
+   Style);
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.BeforeLambdaBody = true;
+  verifyFormat("void foo() {\n"
+   "  aFunction(\n"
+   "  1, b(c(foo, Bar{}, baz,\n"
+   " [](d) -> Foo\n"
+   "  {\n"
+   "auto f = e(\n"
+   "[&]\n"
+   "{\n"
+   "  auto g = h();\n"
+   "  return g;\n"
+   "},\n"
+   "qux,\n"
+   "[&] -> Bar\n"
+   "{\n"
+   "  auto i = j();\n"
+   "  return i;\n"
+   "});\n"
+   "return f;\n"
+   "  })));\n"
+   "}",
+   Style);
 }
 
 TEST_F(FormatTest, LambdaWithLineComments) {
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1003,17 +10

[PATCH] D147574: [NFC][clang] Fix Coverity static analyzer tool concerns about auto_causes_copy

2023-04-05 Thread Soumi Manna via Phabricator via cfe-commits
Manna added a comment.

In D147574#4245881 , @erichkeane 
wrote:

> In D147574#4245877 , @Manna wrote:
>
>> Thanks @erichkeane.
>>
>> Is this known failure?
>>
>> Failed Tests (1):
>>
>>   Clang :: 
>> SemaCXX/warn-unsafe-buffer-usage-fixits-addressof-arraysubscript.cpp
>>
>> https://buildkite.com/llvm-project/premerge-checks/builds/145026#01874e21-00e2-47a9-9bc4-975357d197ef
>
> Looks like the commit that added that test got reverted here 
> d5c428356f6ee107a97977eb9ef1aa4d5fa0c378 
>  because 
> it caused the test to fail, so it looks like the answer is 'yes'.

Thanks @erichkeane for confirming!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147574

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


[PATCH] D147324: [OpenMP][MLIR][Flang][bbc][Driver] Add OpenMP RTL Flags to Flang and generate omp.FlagsAttr from them

2023-04-05 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan accepted this revision.
kiranchandramohan added a comment.
This revision is now accepted and ready to land.

LG. This portion of the patch was accepted in https://reviews.llvm.org/D145264.

See inline comment about location of LLVM Dialect tests. You may either remove 
the LLVM dialect tests from this patch and land it. Or you can submit this and 
move the tests in a separate NFC patch and submit without review.




Comment at: flang/test/Lower/OpenMP/rtl-flags.f90:10-27
+!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | fir-opt --fir-to-llvm-ir | 
FileCheck %s  --check-prefix=DEFAULT-HOST-LLVMDIALECT
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-is-device %s -o - | fir-opt 
--fir-to-llvm-ir | FileCheck %s --check-prefix=DEFAULT-DEVICE-LLVMDIALECT
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-target-debug -fopenmp-is-device 
%s -o - | fir-opt --fir-to-llvm-ir | FileCheck %s 
--check-prefix=DBG-DEVICE-LLVMDIALECT
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-target-debug=111 
-fopenmp-is-device %s -o - | fir-opt --fir-to-llvm-ir | FileCheck %s 
--check-prefix=DBG-EQ-DEVICE-LLVMDIALECT
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-assume-teams-oversubscription 
-fopenmp-is-device %s -o - | fir-opt --fir-to-llvm-ir | FileCheck %s 
--check-prefix=TEAMS-OSUB-DEVICE-LLVMDIALECT
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-assume-threads-oversubscription 
-fopenmp-is-device %s -o - | fir-opt --fir-to-llvm-ir | FileCheck %s 
--check-prefix=THREAD-OSUB-DEVICE-LLVMDIALECT
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-assume-no-thread-state 
-fopenmp-is-device %s -o - | fir-opt --fir-to-llvm-ir | FileCheck %s 
--check-prefix=THREAD-STATE-DEVICE-LLVMDIALECT

The tests for LLVM dialect should be in 
https://github.com/llvm/llvm-project/blob/main/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir.

Same for other LLVM dialect RUN lines below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147324

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


[PATCH] D144036: [clang-tidy] Add bugprone-enum-to-bool-conversion check

2023-04-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Such a great check, thanks! I have very minor comments, the most debatable one 
about the name of the check (but no strong opinion).




Comment at: clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp:107
+CheckFactories.registerCheck(
+"bugprone-enum-to-bool-conversion");
 CheckFactories.registerCheck(

I think the name is a bit generic, do we foresee risk of conflict with other 
similar checks in the future? I wonder if we should narrow it down to something 
like `bugprone-non-zero-enum-to-bool-conversion`. WDYT?



Comment at: 
clang-tools-extra/clang-tidy/bugprone/EnumToBoolConversionCheck.cpp:23
+AST_MATCHER(EnumDecl, isCompleteAndHasNoZeroValue) {
+  const auto *Definition = Node.getDefinition();
+  return Definition and Node.isComplete() and

 Use explicit type



Comment at: 
clang-tools-extra/clang-tidy/bugprone/EnumToBoolConversionCheck.cpp:24
+  const auto *Definition = Node.getDefinition();
+  return Definition and Node.isComplete() and
+ std::none_of(

The convention in the LLVM repo is to use traditional operators, please keep 
consistency.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/EnumToBoolConversionCheck.cpp:27
+ Definition->enumerator_begin(), Definition->enumerator_end(),
+ [](const auto *Value) { return Value->getInitVal().isZero(); });
+}

Use explicit type



Comment at: 
clang-tools-extra/clang-tidy/bugprone/EnumToBoolConversionCheck.cpp:72
+  << Enum;
+
+  diag(Enum->getLocation(), "enum is defined here", DiagnosticIDs::Note);

Unnecessary empty line



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:112
 
+- New :doc:`bugprone-enum-to-bool-conversion
+  ` check.

Keep alphabetical order.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-bool-conversion.rst:12-13
+
+The check produces false positives if the ``enum`` is used to store other 
values
+(used as a bit-mask or zero-initialized on purpose). To deal with 
false-positives,
+``//NOLINT`` or casting first to the underlying type before casting to ``bool``

I can't think of a case where this could happen, might be worth adding an 
example below.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-bool-conversion.rst:14
+(used as a bit-mask or zero-initialized on purpose). To deal with 
false-positives,
+``//NOLINT`` or casting first to the underlying type before casting to ``bool``
+can be used.

Nit: Add space between `//` and `NOLINT`



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-bool-conversion.rst:38
+void process(EStatus status)
+{
+if (not status)

Nit: use 2 chars indentation



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-bool-conversion.rst:39
+{
+if (not status)
+{

Use traditional operators for consistency.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-bool-conversion.rst:41
+{
+// this true-branch in theory wont be executed
+return;

won't



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-bool-conversion.rst:41
+{
+// this true-branch in theory wont be executed
+return;

carlosgalvezp wrote:
> won't
Remove?



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/enum-to-bool-conversion-cpp11.cpp:9
+SUCCESS   = 1,
+FAILURE   = 2,
+INVALID_PARAM = 3,

Indent with 2 chars instead of 4.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/enum-to-bool-conversion-cpp11.cpp:16
+{
+// CHECK-MESSAGES: :[[@LINE+1]]:12: warning: conversion of 'EStatus' into 
'bool' will always return 'true', enum doesn't have a zero-value enumerator 
[bugprone-enum-to-bool-conversion]
+return static_cast(value);

Nit: Add 2 chars indentation to align with the code.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/enum-to-bool-conversion-cpp11.cpp:20
+
+enum EResult : short
+{

Maybe test also "int", since it's the most common default? Also test one `enum 
class` without explicit underlying type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144036

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


[PATCH] D144036: [clang-tidy] Add bugprone-enum-to-bool-conversion check

2023-04-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Thank you for review, I will correct comments in this week.




Comment at: clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp:107
+CheckFactories.registerCheck(
+"bugprone-enum-to-bool-conversion");
 CheckFactories.registerCheck(

carlosgalvezp wrote:
> I think the name is a bit generic, do we foresee risk of conflict with other 
> similar checks in the future? I wonder if we should narrow it down to 
> something like `bugprone-non-zero-enum-to-bool-conversion`. WDYT?
I'm fine with name change



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-bool-conversion.rst:41
+{
+// this true-branch in theory wont be executed
+return;

carlosgalvezp wrote:
> carlosgalvezp wrote:
> > won't
> Remove?
enums are ints, you can assign them any value by using static casts or when 
reading data from external message, so thats why in theory, but in this example 
you right, there is no "in theory"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144036

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


[PATCH] D144036: [clang-tidy] Add bugprone-enum-to-bool-conversion check

2023-04-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL planned changes to this revision.
PiotrZSL added a comment.

TODO: Fix review comments, rename check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144036

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


[PATCH] D147574: [NFC][clang] Fix Coverity static analyzer tool concerns about auto_causes_copy

2023-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147574

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


[PATCH] D147621: [clang][Interp] Start handling mutable record members

2023-04-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147621

Files:
  clang/lib/AST/Interp/Interp.cpp
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -664,6 +664,28 @@
 };
 #endif
 
+namespace MutableFields {
+  class Foo {
+  public:
+constexpr Foo() : I(1) {}
+mutable int I; // ref-note {{declared here}}
+  };
+
+
+  constexpr int foo() {
+const Foo F;
+F.I = 12;
+return F.I;
+  }
+  static_assert(foo() == 12, "");
+
+  /// FIXME: This should also be rejected in the new interpreter.
+  constexpr Foo GlobalF;
+  constexpr int foo2() { // ref-error {{never produces a constant expression}}
+return GlobalF.I; // ref-note {{read of mutable member 'I' is not allowed 
in a constant expression}}
+  }
+}
+
 /// FIXME: The following tests are broken.
 ///   They are using CXXDefaultInitExprs which contain a CXXThisExpr. The This 
pointer
 ///   in those refers to the declaration we are currently initializing, *not* 
the
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -224,6 +224,14 @@
 return true;
   }
 
+  // Writing to mutable fields is fine even if the parent is
+  // declared const.
+  if (S.getLangOpts().CPlusPlus14) {
+if (const auto *FD = dyn_cast(Ptr.getFieldDesc()->asDecl());
+FD && FD->isMutable())
+  return true;
+  }
+
   const QualType Ty = Ptr.getType();
   const SourceInfo &Loc = S.Current->getSource(OpPC);
   S.FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;
@@ -236,6 +244,11 @@
 return true;
   }
 
+  // In C++14 onwards, it is permitted to read a mutable member whose
+  // lifetime began within the evaluation.
+  if (S.getLangOpts().CPlusPlus14)
+return true;
+
   const SourceInfo &Loc = S.Current->getSource(OpPC);
   const FieldDecl *Field = Ptr.getField();
   S.FFDiag(Loc, diag::note_constexpr_access_mutable, 1) << AK_Read << Field;


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -664,6 +664,28 @@
 };
 #endif
 
+namespace MutableFields {
+  class Foo {
+  public:
+constexpr Foo() : I(1) {}
+mutable int I; // ref-note {{declared here}}
+  };
+
+
+  constexpr int foo() {
+const Foo F;
+F.I = 12;
+return F.I;
+  }
+  static_assert(foo() == 12, "");
+
+  /// FIXME: This should also be rejected in the new interpreter.
+  constexpr Foo GlobalF;
+  constexpr int foo2() { // ref-error {{never produces a constant expression}}
+return GlobalF.I; // ref-note {{read of mutable member 'I' is not allowed in a constant expression}}
+  }
+}
+
 /// FIXME: The following tests are broken.
 ///   They are using CXXDefaultInitExprs which contain a CXXThisExpr. The This pointer
 ///   in those refers to the declaration we are currently initializing, *not* the
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -224,6 +224,14 @@
 return true;
   }
 
+  // Writing to mutable fields is fine even if the parent is
+  // declared const.
+  if (S.getLangOpts().CPlusPlus14) {
+if (const auto *FD = dyn_cast(Ptr.getFieldDesc()->asDecl());
+FD && FD->isMutable())
+  return true;
+  }
+
   const QualType Ty = Ptr.getType();
   const SourceInfo &Loc = S.Current->getSource(OpPC);
   S.FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;
@@ -236,6 +244,11 @@
 return true;
   }
 
+  // In C++14 onwards, it is permitted to read a mutable member whose
+  // lifetime began within the evaluation.
+  if (S.getLangOpts().CPlusPlus14)
+return true;
+
   const SourceInfo &Loc = S.Current->getSource(OpPC);
   const FieldDecl *Field = Ptr.getField();
   S.FFDiag(Loc, diag::note_constexpr_access_mutable, 1) << AK_Read << Field;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-05 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 58.
zequanwu added a comment.
Herald added a subscriber: ormris.

- Pass `LangOptions.UseTargetPathSeparator` down to TargetOptions to use host

path separator when it's set.

- Add a test case. The problem is when if we are targeting to linux, clang

won't generate codeview debuginfo with `-gcodeview`. So, I only add the test to
target on windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147256

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-slash.c
  clang/test/CodeGen/use-target-path-separator.c
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -791,7 +791,15 @@
 // Don't emit the filename if we're writing to stdout or to /dev/null.
 PathRef = {};
   } else {
-llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);
+llvm::sys::path::Style Style =
+(!llvm::sys::path::is_absolute(PathRef,
+   llvm::sys::path::Style::posix) &&
+ Asm->TM.Options.UseTargetPathSeparator)
+? (Asm->TM.getTargetTriple().isOSWindows()
+   ? llvm::sys::path::Style::windows_backslash
+   : llvm::sys::path::Style::posix)
+: llvm::sys::path::Style::native;
+llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true, Style);
 PathRef = PathStore;
   }
 
Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -127,7 +127,8 @@
 : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
   NoTrappingFPMath(true), NoSignedZerosFPMath(false),
   ApproxFuncFPMath(false), EnableAIXExtendedAltivecABI(false),
-  HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
+  HonorSignDependentRoundingFPMathOption(false),
+  UseTargetPathSeparator(false), NoZerosInBSS(false),
   GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
   EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
   DisableIntegratedAS(false), RelaxELFRelocations(true),
@@ -206,6 +207,11 @@
 unsigned HonorSignDependentRoundingFPMathOption : 1;
 bool HonorSignDependentRoundingFPMath() const;
 
+/// UseTargetPathSeparator - This Indicates whether to use target's
+/// platform-specific file separator when concatenating filename with
+/// directory.
+unsigned UseTargetPathSeparator : 1;
+
 /// NoZerosInBSS - By default some codegens place zero-initialized data to
 /// .bss section. This flag disables such behaviour (necessary, e.g. for
 /// crt*.o compiling).
Index: clang/test/CodeGen/use-target-path-separator.c
===
--- /dev/null
+++ clang/test/CodeGen/use-target-path-separator.c
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t-dir
+// RUN: mkdir -p %t-dir/subdir
+// RUN: cd %t-dir
+// RUN: %clang_cl --target=x86_64-windows-msvc -ffile-reproducible /c /Z7 -fdebug-compilation-dir=. /Fosubdir/win.obj -- %s
+// RUN: llvm-readobj --codeview subdir/win.obj | FileCheck --check-prefix=WIN %s
+
+int main (void) {
+  return 0;
+}
+
+// WIN: ObjectName: subdir\win.obj
Index: clang/test/CodeGen/debug-info-slash.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-slash.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-pc-win32  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=WIN %s
+// RUN: %clang -target x86_64-linux-gnu  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=LINUX %s
+int main() { return 0; }
+
+// WIN:   !DIFile(filename: "{{.*}}\\debug-info-slash.c"
+// LINUX: !DIFile(filename: "{{.*}}/debug-info-slash.c"
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -528,6 +528,7 @@
   // Get absolute path name.
   SourceManager &SM = CGM.getContext().getSourceManager();
   auto &CGO = CGM.getCodeGenOpts();
+  const LangOptions &LO = CGM.getLangOpts();
   std::string MainFileName = CGO.MainFileName;
   if (MainFileName.empty())
 MainFileName = "";
@@ -542,9 +543,15 @@
 MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);
-  llvm::

[PATCH] D144269: [Analyzer] Show "taint originated here" note of alpha.security.taint.TaintPropagation checker at the correct place

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

Looks even better. Only minor concerns remained, mostly about style and 
suggestions of llvm utilities.




Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:129-130
 /// Given a pointer/reference argument, return the value it refers to.
-std::optional getPointeeOf(const CheckerContext &C, SVal Arg) {
+std::optional getPointeeOf(ASTContext &ASTCtx,
+ const ProgramStateRef State, SVal Arg) {
   if (auto LValue = Arg.getAs())

BTW I don't know but `State->getStateManager().getContext()` can give you an 
`ASTContext`. And we tend to not put `const` to variable declarations. See [[ 
https://releases.llvm.org/4.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/readability-avoid-const-params-in-decls.html
 | readability-avoid-const-params-in-decls ]]

In other places we tend to refer to `ASTContext` by the `ACtx` I think.
We also prefer const refs over mutable refs. Is the mutable ref justified for 
this case?



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:159
+/// when the return value, or the outgoing parameters are tainted.
+const NoteTag *taintOriginTrackerTag(CheckerContext &C,
+ std::vector TaintedSymbols,

My bad. In LLVM style we use `UpperCamelCase` for variable names.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:173-175
+if (TaintedSymbols.empty()) {
+  return "Taint originated here";
+}

Generally, in LLVM style we don't put braces to single block statements unless 
it would hurt readability, which I don't think applies here.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:176-180
+for (auto Sym : llvm::enumerate(TaintedSymbols)) {
+  LLVM_DEBUG(llvm::dbgs() << "Taint Propagated from argument "
+  << TaintedArgs.at(Sym.index()) + 1 << "\n");
+  BR.markInteresting(Sym.value());
+}

I was also bad with this recommendation.
I think we can now use structured bindings to get the index and value right 
there, like:
`for (auto [Idx, Sym] : llvm::enumerate(TaintedSymbols))`
[[ 
https://github.com/llvm/llvm-project/blob/main/llvm/docs/ProgrammersManual.rst#enumerate
 | See ]]



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:203
+int nofTaintedArgs = 0;
+for (auto Sym : llvm::enumerate(TaintedSymbols)) {
+  if (BR.isInteresting(Sym.value())) {

Same here about structured bindings.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:209-214
+  if (nofTaintedArgs == 0)
+Out << "Taint propagated to argument "
+<< TaintedArgs.at(Sym.index()) + 1;
+  else
+Out << ", " << TaintedArgs.at(Sym.index()) + 1;
+  nofTaintedArgs++;

I'd recommend using `llvm::interleaveComma()` in such cases.
You can probably get rid of `nofTaintedArgs` as well - by using this function.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:211
+Out << "Taint propagated to argument "
+<< TaintedArgs.at(Sym.index()) + 1;
+  else

For clang diagnostics we usually use ordinary suffixes like `{st,nd,rd,th}`. It 
would be nice to align with the rest of the clang diagnostics on this.
It would require a bit of work on the wording though, I admit.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:213
+  else
+Out << ", " << TaintedArgs.at(Sym.index()) + 1;
+  nofTaintedArgs++;

I believe this branch is uncovered by tests.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:221
+}
+return std::string(Out.str());
+  });

I think since you explicitly specify the return type of the lambda, you could 
omit the spelling of `std::string` here.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:863-864
   State = addTaint(State, Call.getReturnValue());
+  SymbolRef TaintedSym = isTainted(State, Call.getReturnValue());
+  if (TaintedSym) {
+TaintedSymbols.push_back(TaintedSym);

We tend to fuse such declarations:
I've seen other cases like this elsewhere. Please check.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:875-878
+  // FIXME: The call argument may be a complex expression
+  // referring to multiple tainted variables.
+  // Now we generate notes and track back only one of them.
+  SymbolRef TaintedSym = isTainted(State, *V);

You could iterate over the symbol dependencies of the SymExpr (of the `*V` 
SVal).

```lang=c++
Symb

[PATCH] D144269: [Analyzer] Show "taint originated here" note of alpha.security.taint.TaintPropagation checker at the correct place

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

I think as we converge, now it could be time to update the summary of the patch 
to reflect the current implementation. (e.g. flowids etc.)


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

https://reviews.llvm.org/D144269

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


[PATCH] D147626: [clang] Do not crash when initializing union with flexible array member

2023-04-05 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Due to missing check on union, there was a null expression added to init
list that caused crash later.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147626

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/init.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 = { (uintptr_t)&bitfieldvar }; // 
expected-error {{initializer element is not a compile-time constant}}
+
+// GH61746
+union { char x[]; } r = {0}; // expected-error {{flexible array member 'x' in 
a union is not allowed}}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -805,7 +805,7 @@
   // order to leave them uninitialized, the ILE is expanded and the extra
   // fields are then filled with NoInitExpr.
   unsigned NumElems = numStructUnionElements(ILE->getType());
-  if (RDecl->hasFlexibleArrayMember())
+  if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember())
 ++NumElems;
   if (!VerifyOnly && ILE->getNumInits() < NumElems)
 ILE->resizeInits(SemaRef.Context, NumElems);


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 = { (uintptr_t)&bitfieldvar }; // expected-error {{initializer element is not a compile-time constant}}
+
+// GH61746
+union { char x[]; } r = {0}; // expected-error {{flexible array member 'x' in a union is not allowed}}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -805,7 +805,7 @@
   // order to leave them uninitialized, the ILE is expanded and the extra
   // fields are then filled with NoInitExpr.
   unsigned NumElems = numStructUnionElements(ILE->getType());
-  if (RDecl->hasFlexibleArrayMember())
+  if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember())
 ++NumElems;
   if (!VerifyOnly && ILE->getNumInits() < NumElems)
 ILE->resizeInits(SemaRef.Context, NumElems);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146591: [dataflow] add HTML logger: browse code/cfg/analysis timeline/state

2023-04-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 511126.
sammccall marked 8 inline comments as done.
sammccall added a comment.

address comments (sorry about long turnaround!)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146591

Files:
  clang/include/clang/Analysis/FlowSensitive/Logger.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
  clang/lib/Analysis/FlowSensitive/HTMLLogger.css
  clang/lib/Analysis/FlowSensitive/HTMLLogger.html
  clang/lib/Analysis/FlowSensitive/HTMLLogger.js
  clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
  clang/utils/bundle_resources.py

Index: clang/utils/bundle_resources.py
===
--- /dev/null
+++ clang/utils/bundle_resources.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+#===- bundle_resources.py - Generate string constants with file contents. ===
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===--===
+
+# Usage: bundle-resources.py foo.inc a.js path/b.css ...
+# Produces foo.inc containing:
+#   const char a_js[] = "...";
+#   const char b_css[] = "...";
+import os
+import sys
+
+outfile = sys.argv[1]
+infiles = sys.argv[2:]
+
+with open(outfile, 'w') as out:
+  for filename in infiles:
+varname = os.path.basename(filename).replace('.', '_')
+out.write("const char " + varname + "[] = \n");
+# MSVC limits each chunk of string to 2k, so split by lines.
+# The overall limit is 64k, which ought to be enough for anyone.
+for line in open(filename).read().split('\n'):
+  out.write('  R"x(' + line + ')x" "\\n"\n' )
+out.write('  ;\n');
Index: clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
@@ -9,6 +9,7 @@
 
 namespace clang::dataflow::test {
 namespace {
+using testing::HasSubstr;
 
 struct TestLattice {
   int Elements = 0;
@@ -83,19 +84,24 @@
   void logText(llvm::StringRef Text) override { OS << Text << "\n"; }
 };
 
-TEST(LoggerTest, Sequence) {
+AnalysisInputs makeInputs() {
   const char *Code = R"cpp(
 int target(bool b, int p, int q) {
   return b ? p : q;
 }
 )cpp";
+  static const std::vector Args = {
+  "-fsyntax-only", "-fno-delayed-template-parsing", "-std=c++17"};
 
   auto Inputs = AnalysisInputs(
   Code, ast_matchers::hasName("target"),
   [](ASTContext &C, Environment &) { return TestAnalysis(C); });
-  std::vector Args = {
-  "-fsyntax-only", "-fno-delayed-template-parsing", "-std=c++17"};
   Inputs.ASTBuildArgs = Args;
+  return Inputs;
+}
+
+TEST(LoggerTest, Sequence) {
+  auto Inputs = makeInputs();
   std::string Log;
   TestLogger Logger(Log);
   Inputs.BuiltinOptions.Log = &Logger;
@@ -148,5 +154,29 @@
 )");
 }
 
+TEST(LoggerTest, HTML) {
+  auto Inputs = makeInputs();
+  std::vector Logs;
+  auto Logger = Logger::html([&]() {
+Logs.emplace_back();
+return std::make_unique(Logs.back());
+  });
+  Inputs.BuiltinOptions.Log = Logger.get();
+
+  ASSERT_THAT_ERROR(checkDataflow(std::move(Inputs),
+[](const AnalysisOutputs &) {}),
+llvm::Succeeded());
+
+  // Simple smoke tests: we can't meaningfully test the behavior.
+  ASSERT_THAT(Logs, testing::SizeIs(1));
+  EXPECT_THAT(Logs[0], HasSubstr("function updateSelection")) << "embeds JS";
+  EXPECT_THAT(Logs[0], HasSubstr("html {")) << "embeds CSS";
+  EXPECT_THAT(Logs[0], HasSubstr("b (ImplicitCastExpr")) << "has CFG elements";
+  EXPECT_THAT(Logs[0], HasSubstr("\"B3:1_B3.1\":"))
+  << "has analysis point state";
+  EXPECT_THAT(Logs[0], HasSubstr("transferBranch(0)")) << "has analysis logs";
+  EXPECT_THAT(Logs[0], HasSubstr("LocToVal")) << "has built-in lattice dump";
+}
+
 } // namespace
 } // namespace clang::dataflow::test
Index: clang/lib/Analysis/FlowSensitive/HTMLLogger.js
===
--- /dev/null
+++ clang/lib/Analysis/FlowSensitive/HTMLLogger.js
@@ -0,0 +1,213 @@
+//===-- HTMLLogger.js -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// Based on selected objects, hide/show sections & populate data from templates.
+//
+// For example, if the selecti

[libunwind] d080b5f - [libunwind] Fix a case of inconsistent indentation. NFC.

2023-04-05 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2023-04-05T19:23:18+03:00
New Revision: d080b5f1737b4040aa74a5614ae01338f28cd714

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

LOG: [libunwind] Fix a case of inconsistent indentation. NFC.

Added: 


Modified: 
libunwind/include/__libunwind_config.h

Removed: 




diff  --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index f69fe89e9a265..a4e1a3613bbf9 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -196,7 +196,7 @@
 # define _LIBUNWIND_TARGET_RISCV 1
 # define _LIBUNWIND_TARGET_VE 1
 # define _LIBUNWIND_TARGET_S390X 1
-#define _LIBUNWIND_TARGET_LOONGARCH 1
+ #define _LIBUNWIND_TARGET_LOONGARCH 1
 # define _LIBUNWIND_CONTEXT_SIZE 167
 # define _LIBUNWIND_CURSOR_SIZE 179
 # define _LIBUNWIND_HIGHEST_DWARF_REGISTER 287



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


[PATCH] D146090: [Clang] Updating handling of defaulted comparison operators to reflect changes from P2448R2

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



Comment at: clang/docs/ReleaseNotes.rst:91-92
   expressions and how their types are deduced therein, in all C++ language 
versions.
+- Implemented partial support for `P2448R2: Relaxing some constexpr 
restrictions `_
+  Explicitly defaulted functions no longer have to be constexpr-compatible but 
merely constexpr suitable.
 

Should we also say what's still missing that causes this to be partial?



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:9415-9421
+  "invokes a non-constexpr comparison function is a C++2b extension">, 
InGroup;
+def warn_cxx2b_compat_incorrect_defaulted_comparison_constexpr : Warning<
+  "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
+  "three-way comparison operator}0 that is "
+  "declared %select{constexpr|consteval}2 but"
+  "%select{|for which the corresponding implicit 'operator==' }0 "
+  "invokes a non-constexpr comparison function is a C++2b extension">, 
InGroup, DefaultIgnore;

Formatting fix-up and a wording correction.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:9410-9421
+def ext_incorrect_defaulted_comparison_constexpr : Extension<
   "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
   "three-way comparison operator}0 "
-  "cannot be declared %select{constexpr|consteval}2 because "
+  "declared %select{constexpr|consteval}2 but "
   "%select{it|the corresponding implicit 'operator=='}0 "
-  "invokes a non-constexpr comparison function">;
+  "invokes a non-constexpr comparison function are a C++2b extension">, 
InGroup;
+def warn_cxx2b_incorrect_defaulted_comparison_constexpr : Warning<

shafik wrote:
> rsmith wrote:
> > The grammar of these diagnostics looks a bit peculiar. Suggested an 
> > alternative, but it's still a bit awkward ("...but for which..."), maybe 
> > you can find something better.
> @aaron.ballman any suggestions for less awkward wording here? I don't think 
> what there is here now is too bad but asking for a another opinion.
Yeah, that wording is a bit... wordy, but I'm struggling to think of something 
more approachable that's still accurate.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:8811
+  // The concept of constexpr-compatible was removed.
+  // C++23 [dcl.fct.def.default]/p3 [P2448R2]
+  //  A function explicitly defaulted on its first declaration is implicitly





Comment at: clang/test/CXX/class/class.compare/class.compare.default/p4.cpp:153
+
+constexpr friend bool operator==(const my_struct &, const my_struct &) 
noexcept = default; // no diagnostic extension-warning {{declared constexpr but 
invokes a non-constexpr comparison function is a C++2b extension}}
+};

`no diagnostic extension-warning`?



Comment at: clang/test/CXX/class/class.compare/class.compare.default/p4.cpp:162
+
+my_struct obj; // extension-note {{in instantiation of 
template class 'GH61238::my_struct' requested 
here}}
+}

Can you add an instantiation that does use a constexpr suitable type to show 
that we don't issue the diagnostic on that instantiation, or do you think that 
is sufficiently covered by other test coverage?



Comment at: clang/www/cxx_status.html:1485
   https://wg21.link/P2448R2";>P2448R2
-  No
+  Partial
 

Please add   markup to explain why the support is partial, and it's 
probably not a bad idea to say `Clang 17 (Partial)` so users know when the 
partial support started.


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

https://reviews.llvm.org/D146090

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


[PATCH] D147574: [NFC][clang] Fix Coverity static analyzer tool concerns about auto_causes_copy

2023-04-05 Thread Soumi Manna via Phabricator via cfe-commits
Manna added a comment.

In D147574#4246004 , @aaron.ballman 
wrote:

> LGTM

Thank you @aaron.ballman


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147574

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


[PATCH] D146376: Update static_assert message for redundant cases

2023-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D146376#4244355 , 
@Krishna-13-cyber wrote:

> - Updated with release note
> - I had tried adding more text to the `expected-error` but it already gives a 
> diagnostic of `static assertion failed due to requirement` currently. If I 
> try additions to `{{failed}}` then we get **error diagnostics expected but 
> not seen**.

Ah, sorry for being unclear! We didn't mean add an additional `expected-error` 
comment, but to modify the ones you have. e.g.,

Currently:

  static_assert(true && false, ""); // expected-error {{failed}}

Changes to:

  static_assert(true && false, ""); // expected-error {{static assertion failed 
due to requirement 'true && false'}}

(or whatever the actual expected full text of the diagnostic is.)

This helps the reviewers to make sure that the diagnostic behavior isn't 
regressing in surprising ways but pass all our tests because we're only looking 
for the word `failed` and considering that passing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146376

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


[PATCH] D147626: [clang] Do not crash when initializing union with flexible array member

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



Comment at: clang/lib/Sema/SemaInit.cpp:808
   unsigned NumElems = numStructUnionElements(ILE->getType());
-  if (RDecl->hasFlexibleArrayMember())
+  if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember())
 ++NumElems;

Just for some context, numStructUnionElements checks that there is a flexible 
array member and returns number_of_initializable_fields-1 for structs. For 
unions it just returns 1 or 0, so flexible array member caused adding one more 
element to initlistexpr that was never properly handled.

Instead of doing this change, we could probably never enter initialization 
since the record (union) declaration is not valid, but that is not the case 
even for other types of errors in code, for example, I've tried declaring field 
of struct with a typo:

```
struct { cha x[]; } r = {1}; 
```
Initialization is still performed by clang.
Also, it seems MSVC considers flexible array member inside union as valid, so 
the test code is probably not always invalid.


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] D147623: [MSVC] Allow declaration of multi-dim 'property' array fields

2023-04-05 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Ah, needs a release note however!


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

https://reviews.llvm.org/D147623

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


[PATCH] D147623: [MSVC] Allow declaration of multi-dim 'property' array fields

2023-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

Changes LGTM but please add a release note about the new functionality when 
landing.


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

https://reviews.llvm.org/D147623

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


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-05 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

An LLVM code change should be testable on its own; this has it tested by Clang.
I think you need a new command-line option to set 
TargetOptions::UseTargetPathSeparator e.g. via llvm-mc. Other TargetOptions are 
handled this way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147256

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


[clang] 78d0d59 - Add some additional comments to this test; NFC

2023-04-05 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-04-05T13:15:34-04:00
New Revision: 78d0d59209bf858435bcd19046e94fce0386ace8

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

LOG: Add some additional comments to this test; NFC

It isn't immediately obvious why that code should be accepted given the
wording of C2x 6.7.10p4, so this adds a comment explaining that there
is an existing extension to support zero-sized arrays in C, and that
empty initialization of an unbounded array in C++ deduces the array
extent as zero, so C is exposing the same extension as in C++.

Added: 


Modified: 
clang/test/C/C2x/n2900_n3011.c

Removed: 




diff  --git a/clang/test/C/C2x/n2900_n3011.c b/clang/test/C/C2x/n2900_n3011.c
index b0de79e9a516f..6aaff3374c168 100644
--- a/clang/test/C/C2x/n2900_n3011.c
+++ b/clang/test/C/C2x/n2900_n3011.c
@@ -15,6 +15,13 @@ void test(void) {
   pedantic-warning {{use of an empty 
initializer is a C2x extension}}
   int j = (int){}; // compat-warning {{use of an empty initializer is 
incompatible with C standards before C2x}} \
   pedantic-warning {{use of an empty initializer is a C2x 
extension}}
+
+  // C2x 6.7.10p4 says, in part: An array of unknown size shall not be
+  // initialized by an empty initializer.
+  // However, Clang allows zero-sized arrays as an extension in both C and C++,
+  // and this initialization form will deduce the array extent as zero. Given
+  // that we support empty initialization of an unbounded array in C++, we also
+  // support it in C.
   int unknown_size[] = {}; // pedantic-warning {{zero size arrays are an 
extension}} \
   pedantic-warning {{use of an empty initializer 
is a C2x extension}} \
   compat-warning {{use of an empty initializer is 
incompatible with C standards before C2x}}



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


[PATCH] D147324: [OpenMP][MLIR][Flang][bbc][Driver] Add OpenMP RTL Flags to Flang and generate omp.FlagsAttr from them

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

In D147324#4245932 , 
@kiranchandramohan wrote:

> LG. This portion of the patch was accepted in 
> https://reviews.llvm.org/D145264.
>
> See inline comment about location of LLVM Dialect tests. You may either 
> remove the LLVM dialect tests from this patch and land it. Or you can submit 
> this and move the tests in a separate NFC patch and submit without review.

Hi Kiran,

Thanks for the quick reply. I'll do the former and remove the tests and land 
the patch today (back tracking on the previous statement of leaving landing it 
till later), I don't believe they add anything to the test suite as there is no 
modifications between FIR -> LLVM Dialect as far as this attribute and the 
ModuleOp go.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147324

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


[clang] 57caadc - [MSVC] Allow declaration of multi-dim 'property' array fields

2023-04-05 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2023-04-05T10:29:37-07:00
New Revision: 57caadc57a30f2279099e5b86bb555b4aab621ce

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

LOG: [MSVC] Allow declaration of multi-dim 'property' array fields

MSVC allows declaration of multi-dim arrays like this:

__declspec(property(get=GetX, put=PutX)) int x[][][];

This syntax can appear in generated typelib headers.

Currently clang errors on declarators like this since it forms an array
type of incomplete array. Rather than try to handle such a type, ignore
adjacent empty chunks so this is treated as if there was only one empty
array chunk (i.e. int x[]).

The functionality to handle multi-dim subscripts of property fields
already works, but only if declared as a single-dim array.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/ParsedAttr.h
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CodeGenCXX/ms-property.cpp
clang/test/SemaCXX/ms-property-error.cpp
clang/test/SemaCXX/ms-property.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1e280cb633e23..bbfef9ff3cf7c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -146,6 +146,8 @@ Non-comprehensive list of changes in this release
 - Clang now supports ``__builtin_assume_separate_storage`` that indicates that
   its arguments point to objects in separate storage allocations.
 - Clang now supports expressions in ``#pragma clang __debug dump``.
+- Clang now supports declaration of multi-dimensional arrays with
+  ``__declspec(property)``.
 
 New Compiler Flags
 --

diff  --git a/clang/include/clang/Sema/ParsedAttr.h 
b/clang/include/clang/Sema/ParsedAttr.h
index e2b4be48c0bd1..5f45668851c73 100644
--- a/clang/include/clang/Sema/ParsedAttr.h
+++ b/clang/include/clang/Sema/ParsedAttr.h
@@ -896,6 +896,16 @@ class ParsedAttributesView {
 });
   }
 
+  const ParsedAttr *getMSPropertyAttr() const {
+auto It = llvm::find_if(AttrList, [](const ParsedAttr *AL) {
+  return AL->isDeclspecPropertyAttribute();
+});
+if (It != AttrList.end())
+  return *It;
+return nullptr;
+  }
+  bool hasMSPropertyAttr() const { return getMSPropertyAttr(); }
+
 private:
   VecTy AttrList;
 };

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index e28c44f97f1fe..312b6f801c1f0 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -3235,16 +3235,6 @@ static bool InitializationHasSideEffects(const FieldDecl 
&FD) {
   return false;
 }
 
-static const ParsedAttr *getMSPropertyAttr(const ParsedAttributesView &list) {
-  ParsedAttributesView::const_iterator Itr =
-  llvm::find_if(list, [](const ParsedAttr &AL) {
-return AL.isDeclspecPropertyAttribute();
-  });
-  if (Itr != list.end())
-return &*Itr;
-  return nullptr;
-}
-
 // Check if there is a field shadowing.
 void Sema::CheckShadowInheritedFields(const SourceLocation &Loc,
   DeclarationName FieldName,
@@ -3322,7 +3312,7 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier 
AS, Declarator &D,
 
   bool isFunc = D.isDeclarationOfFunction();
   const ParsedAttr *MSPropertyAttr =
-  getMSPropertyAttr(D.getDeclSpec().getAttributes());
+  D.getDeclSpec().getAttributes().getMSPropertyAttr();
 
   if (cast(CurContext)->isInterface()) {
 // The Microsoft extension __interface only permits public member functions

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 53852dd930a71..e195e85ab75b7 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5070,6 +5070,19 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
   DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr;
   Expr *ArraySize = static_cast(ATI.NumElts);
   ArrayType::ArraySizeModifier ASM;
+
+  // Microsoft property fields can have multiple sizeless array chunks
+  // (i.e. int x[][][]). Skip all of these except one to avoid creating
+  // bad incomplete array types.
+  if (chunkIndex != 0 && !ArraySize &&
+  D.getDeclSpec().getAttributes().hasMSPropertyAttr()) {
+// This is a sizeless chunk. If the next is also, skip this one.
+DeclaratorChunk &NextDeclType = D.getTypeObject(chunkIndex - 1);
+if (NextDeclType.Kind == DeclaratorChunk::Array &&
+!NextDeclType.Arr.NumElts)
+  break;
+  }
+
   if (ATI.isStar)
 ASM = ArrayType::Star;
   else if (ATI.hasStatic)
@@ -6523,6 +6536,12 @@ GetTypeSourceInfoForDeclarator(TypeProcessingState 
&State,
   }
 
   for (unsigned i = 0, e = D.getNumTypeObjects(); i 

[PATCH] D147623: [MSVC] Allow declaration of multi-dim 'property' array fields

2023-04-05 Thread Mike Rice via Phabricator via cfe-commits
mikerice closed this revision.
mikerice added a comment.

57caadc57a30f2279099e5b86bb555b4aab621ce 



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

https://reviews.llvm.org/D147623

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


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Ah, I like this approach -- it keeps things roughly in sync with checking for 
unique object representations, which is great. I spotted a few questions, but 
in general this is heading in the right direction. You should also add a 
release note to clang/docs/ReleaseNotes.rst so that users know there's a new 
builtin coming.

I suppose one thing to double-check: do you know of any other STL 
implementations that might be using this identifier as part of their 
implementation details? (We've had issues in the past where we accidentally 
stole a reserved identifier that was being used by libstdc++ and it caused 
issues.)




Comment at: clang/include/clang/AST/DeclCXX.h:1449
   /// Notify the class that this destructor is now selected.
-  /// 
+  ///
   /// Important properties of the class depend on destructor properties. Since

Spurious whitespace change.



Comment at: clang/lib/AST/Type.cpp:2598-2599
+static bool HasDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
+  if (Decl->isUnion())
+return false;
+

Hmmm, is this correct? I thought there was a defaulted equality comparison 
operator in this case, but it's defined as deleted.

http://eel.is/c++draft/class.compare.default#2

Perhaps this function is looking for a usable defaulted equality comparison 
operator and not just "does it have one at all"?



Comment at: clang/lib/AST/Type.cpp:2616-2617
+  }) &&
+ llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
+   if (!FD->getType()->isRecordType())
+ return true;

Do we have to look for fields with references per 
http://eel.is/c++draft/class.compare.default#2 ?



Comment at: clang/lib/AST/Type.cpp:4643-4645
+QualType Deduced, AutoTypeKeyword Keyword,
+bool IsDependent, ConceptDecl *CD,
+ArrayRef Arguments) {

Spurious whitespace changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147175

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


[clang] 53152f1 - [OpenMP][MLIR][Flang][bbc][Driver] Add OpenMP RTL Flags to Flang and generate omp.FlagsAttr from them

2023-04-05 Thread Andrew Gozillon via cfe-commits

Author: Andrew Gozillon
Date: 2023-04-05T12:50:32-05:00
New Revision: 53152f12a47bf6e97f1f2f2d6b71e7b4d4e3740a

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

LOG: [OpenMP][MLIR][Flang][bbc][Driver] Add OpenMP RTL Flags to Flang and 
generate omp.FlagsAttr from them

This patch ports OpenMP RTL flags from the shared Clang compiler
options to Flang. As well as adding a limited subset to bbc.

This patch enables the flags below (and any equals or inverse variants)
for Flang that exist in Clang:

-fopenmp-target-debug
-fopenmp-assume-threads-oversubscription
-fopenmp-assume-teams-oversubscription
-fopenmp-assume-no-nested-parallelism
-fopenmp-assume-no-thread-state

For the bbc tool it only utilises the primary variants to minimize
additional complexity in the tool.

The patch also provides FlagAttr generation from these flags. Which
will be lowered to LLVM-IR in a subsequent patch.

Reviewers: kiranchandramohan, awarzynski

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

Added: 
flang/test/Lower/OpenMP/rtl-flags.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/LangOptions.def
flang/include/flang/Tools/CrossToolHelpers.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/test/Driver/driver-help.f90
flang/test/Driver/omp-frontend-forwarding.f90
flang/tools/bbc/bbc.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 831f8dd65a3e6..5e008fc9b26ee 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2680,26 +2680,39 @@ def fopenmp_cuda_blocks_per_sm_EQ : Joined<["-"], 
"fopenmp-cuda-blocks-per-sm=">
   Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
 def fopenmp_cuda_teams_reduction_recs_num_EQ : Joined<["-"], 
"fopenmp-cuda-teams-reduction-recs-num=">, Group,
   Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
-def fopenmp_target_debug : Flag<["-"], "fopenmp-target-debug">, 
Group, Flags<[CC1Option, NoArgumentUnused]>,
+
+//===--===//
+// Shared cc1 + fc1 OpenMP Target Options
+//===--===//
+
+let Flags = [CC1Option, FC1Option, NoArgumentUnused] in {
+let Group = f_Group in {
+
+def fopenmp_target_debug : Flag<["-"], "fopenmp-target-debug">,
   HelpText<"Enable debugging in the OpenMP offloading device RTL">;
-def fno_openmp_target_debug : Flag<["-"], "fno-openmp-target-debug">, 
Group, Flags<[NoArgumentUnused]>;
-def fopenmp_target_debug_EQ : Joined<["-"], "fopenmp-target-debug=">, 
Group, Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
-def fopenmp_assume_teams_oversubscription : Flag<["-"], 
"fopenmp-assume-teams-oversubscription">,
-  Group, Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
-def fopenmp_assume_threads_oversubscription : Flag<["-"], 
"fopenmp-assume-threads-oversubscription">,
-  Group, Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
-def fno_openmp_assume_teams_oversubscription : Flag<["-"], 
"fno-openmp-assume-teams-oversubscription">,
-  Group, Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
-def fno_openmp_assume_threads_oversubscription : Flag<["-"], 
"fno-openmp-assume-threads-oversubscription">,
-  Group, Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
-def fopenmp_assume_no_thread_state : Flag<["-"], 
"fopenmp-assume-no-thread-state">, Group,
-  Flags<[CC1Option, NoArgumentUnused, HelpHidden]>,
+def fno_openmp_target_debug : Flag<["-"], "fno-openmp-target-debug">;
+
+} // let Group = f_Group
+} // let Flags = [CC1Option, FC1Option, NoArgumentUnused]
+
+let Flags = [CC1Option, FC1Option, NoArgumentUnused, HelpHidden] in {
+let Group = f_Group in {
+
+def fopenmp_target_debug_EQ : Joined<["-"], "fopenmp-target-debug=">;
+def fopenmp_assume_teams_oversubscription : Flag<["-"], 
"fopenmp-assume-teams-oversubscription">;
+def fopenmp_assume_threads_oversubscription : Flag<["-"], 
"fopenmp-assume-threads-oversubscription">;
+def fno_openmp_assume_teams_oversubscription : Flag<["-"], 
"fno-openmp-assume-teams-oversubscription">;
+def fno_openmp_assume_threads_oversubscription : Flag<["-"], 
"fno-openmp-assume-threads-oversubscription">;
+def fopenmp_assume_no_thread_state : Flag<["-"], 
"fopenmp-assume-no-thread-state">,
   HelpText<"Assert no thread in a parallel region modifies an ICV">,
   MarshallingInfoFlag>;
-def fopenmp_assume_no_nested_parallelism : Flag<["-"], 
"fopenmp-assume-no-nested-parallelism">, Group,
-  Flags<[CC1Option, NoArgumentUnused, HelpHidden]>,
+def fopenmp_assume_no_nested_parallelism : Flag<["-"], 
"fopenmp-assume-no-nested-parallelism

[PATCH] D147324: [OpenMP][MLIR][Flang][bbc][Driver] Add OpenMP RTL Flags to Flang and generate omp.FlagsAttr from them

2023-04-05 Thread Andrew Gozillon via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG53152f12a47b: [OpenMP][MLIR][Flang][bbc][Driver] Add OpenMP 
RTL Flags to Flang and generate… (authored by agozillon).

Changed prior to commit:
  https://reviews.llvm.org/D147324?vs=510080&id=511154#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147324

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/LangOptions.def
  flang/include/flang/Tools/CrossToolHelpers.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/omp-frontend-forwarding.f90
  flang/test/Lower/OpenMP/rtl-flags.f90
  flang/tools/bbc/bbc.cpp

Index: flang/tools/bbc/bbc.cpp
===
--- flang/tools/bbc/bbc.cpp
+++ flang/tools/bbc/bbc.cpp
@@ -129,6 +129,38 @@
llvm::cl::desc("enable openmp device compilation"),
llvm::cl::init(false));
 
+// A simplified subset of the OpenMP RTL Flags from Flang, only the primary
+// positive options are available, no negative options e.g. fopen_assume* vs
+// fno_open_assume*
+static llvm::cl::opt setOpenMPTargetDebug(
+"fopenmp-target-debug",
+llvm::cl::desc("Enable debugging in the OpenMP offloading device RTL"),
+llvm::cl::init(0));
+
+static llvm::cl::opt setOpenMPThreadSubscription(
+"fopenmp-assume-threads-oversubscription",
+llvm::cl::desc("Assume work-shared loops do not have more "
+   "iterations than participating threads."),
+llvm::cl::init(false));
+
+static llvm::cl::opt setOpenMPTeamSubscription(
+"fopenmp-assume-teams-oversubscription",
+llvm::cl::desc("Assume distributed loops do not have more iterations than "
+   "participating teams."),
+llvm::cl::init(false));
+
+static llvm::cl::opt setOpenMPNoThreadState(
+"fopenmp-assume-no-thread-state",
+llvm::cl::desc(
+"Assume that no thread in a parallel region will modify an ICV."),
+llvm::cl::init(false));
+
+static llvm::cl::opt setOpenMPNoNestedParallelism(
+"fopenmp-assume-no-nested-parallelism",
+llvm::cl::desc("Assume that no thread in a parallel region will encounter "
+   "a parallel region."),
+llvm::cl::init(false));
+
 static llvm::cl::opt enableOpenACC("fopenacc",
  llvm::cl::desc("enable openacc"),
  llvm::cl::init(false));
@@ -244,8 +276,13 @@
   kindMap, loweringOptions, {});
   burnside.lower(parseTree, semanticsContext);
   mlir::ModuleOp mlirModule = burnside.getModule();
-  if (enableOpenMP)
-setOffloadModuleInterfaceAttributes(mlirModule, enableOpenMPDevice);
+  if (enableOpenMP) {
+auto offloadModuleOpts =
+OffloadModuleOpts(setOpenMPTargetDebug, setOpenMPTeamSubscription,
+  setOpenMPThreadSubscription, setOpenMPNoThreadState,
+  setOpenMPNoNestedParallelism, enableOpenMPDevice);
+setOffloadModuleInterfaceAttributes(mlirModule, offloadModuleOpts);
+  }
   std::error_code ec;
   std::string outputName = outputFilename;
   if (!outputName.size())
Index: flang/test/Lower/OpenMP/rtl-flags.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/rtl-flags.f90
@@ -0,0 +1,29 @@
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DEFAULT-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s --check-prefix=DEFAULT-HOST-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-target-debug -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DBG-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-target-debug=111 -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DBG-EQ-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-assume-teams-oversubscription -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=TEAMS-OSUB-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-assume-threads-oversubscription -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=THREAD-OSUB-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-assume-no-thread-state -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=THREAD-STATE-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-assume-no-nested-parallelism -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=NEST-PAR-DEVICE-FIR
+!RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-target-debug -fopenmp-assume-teams-oversubscription -fopenmp-assume-no-nested-parallelism -fopenmp-assume-threads-oversubscription -fopenmp-assume-no-thread-state -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=ALL-DEVICE-FIR
+!RUN: bbc -emit-fir -fopenmp -fopenmp-is-device -o - 

[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-04-05 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 511153.
john.brawn edited the summary of this revision.
john.brawn added a comment.

New version that checks for special filenames in ResolveImportedPath. I spent a 
while trying to come up with a test using just clang where not doing this 
fails, but couldn't as it looks like the failure is specific to objective-c 
module handing in lldb.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144651

Files:
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang/docs/ReleaseNotes.rst
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/PCH/macro-cmdline.c
  clang/test/PCH/ms-pch-macro.c

Index: clang/test/PCH/ms-pch-macro.c
===
--- clang/test/PCH/ms-pch-macro.c
+++ clang/test/PCH/ms-pch-macro.c
@@ -36,4 +36,4 @@
 // CHECK-FOO: definition of macro 'FOO' differs between the precompiled header ('1') and the command line ('blah')
 // CHECK-NOFOO: macro 'FOO' was defined in the precompiled header but undef'd on the command line
 
-// expected-warning@1 {{definition of macro 'BAR' does not match definition in precompiled header}}
+// expected-warning@2 {{definition of macro 'BAR' does not match definition in precompiled header}}
Index: clang/test/PCH/macro-cmdline.c
===
--- /dev/null
+++ clang/test/PCH/macro-cmdline.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -emit-pch -o %t1.pch -DMACRO1=1
+// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t1.pch -DMACRO2=1 2>&1 | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+#else
+#define MACRO1 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO1' macro redefined
+// CHECK: {{.*}}previous definition is here
+#define MACRO2 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO2' macro redefined
+// CHECK: {{.*}}previous definition is here
+#endif
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -,6 +,11 @@
 bool ASTWriter::PreparePathForOutput(SmallVectorImpl &Path) {
   assert(Context && "should have context when outputting path");
 
+  // Leave special file names as they are.
+  StringRef PathStr(Path.data(), Path.size());
+  if (PathStr == "" || PathStr == "")
+return false;
+
   bool Changed =
   cleanPathForOutput(Context->getSourceManager().getFileManager(), Path);
 
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -654,6 +654,10 @@
   SmallVector ExistingMacroNames;
   collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames);
 
+  // Use a line marker to enter the  file, as the defines and
+  // undefines here will have come from the command line.
+  SuggestedPredefines += "# 1 \"\" 1\n";
+
   for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) {
 // Dig out the macro definition in the existing preprocessor options.
 StringRef MacroName = ExistingMacroNames[I];
@@ -713,6 +717,10 @@
 }
 return true;
   }
+
+  // Leave the  file and return to .
+  SuggestedPredefines += "# 1 \"\" 2\n";
+
   if (Validation == OptionValidateStrictMatches) {
 // If strict matches are requested, don't tolerate any extra defines in
 // the AST file that are missing on the command line.
@@ -1579,8 +1587,13 @@
 auto Buffer = ReadBuffer(SLocEntryCursor, Name);
 if (!Buffer)
   return true;
-SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
-   BaseOffset + Offset, IncludeLoc);
+FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
+BaseOffset + Offset, IncludeLoc);
+if (Record[3]) {
+  auto &FileInfo =
+  const_cast(SourceMgr.getSLocEntry(FID).getFile());
+  FileInfo.setHasLineDirectives();
+}
 break;
   }
 
@@ -2510,7 +2523,8 @@
 }
 
 void ASTReader::ResolveImportedPath(std::string &Filename, StringRef Prefix) {
-  if (Filename.empty() || llvm::sys::path::is_absolute(Filename))
+  if (Filename.empty() || llvm::sys::path::is_absolute(Filename) ||
+  Filename == "" || Filename == "")
 return;
 
   SmallString<128> Buffer;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -198,8 +198,8 @@
 - Diagnostic notes and fix-its are now generated for ``ifunc``/``alias`` attributes
   which point to functions whose names are mangled.
 - Diagnostics relating to macros on the command line of a preprocessed assembly
-  file are now reported as coming from the file  instead of
-  .
+  file or precompiled 

[PATCH] D147569: [Coverage] Fix crash when visiting PseudoObjectExpr.

2023-04-05 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 looks much better to me! LGTM, but please add a release note 
about the fix when landing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147569

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


[PATCH] D147209: [clang][lit] Make LIT aware of env CLANG_CRASH_DIAGNOSTICS_DIR.

2023-04-05 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In D147209#4245229 , @fpetrogalli 
wrote:

> In D147209#4244615 , @leonardchan 
> wrote:
>
>> Hi. I think this led to some test failures on our builder at 
>> https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8784708268307261009/overview:
>
> Hi @leonardchan - thank you for the heads up!
>
> I do not have access to this bot (the link you sent just shows me a blank 
> page), and I have not seen this (clang?) test failing in my local build. I 
> can revert the patch, but I'll need some more info to be able to fix those 
> failures.
>
> Francesco

Hmm, that's interesting since the link should be public and normally doesn't 
just appear as blank. Does it still show up as blank if you click it again? 
Otherwise I can share the full repro. I think you should be able to reproduce 
this if you define `CLANG_CRASH_DIAGNOSTICS_DIR` as an environment variable 
before running `ninja check-clang`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147209

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


[clang] 4e93bd4 - [Coverage] Fix crash when visiting PseudoObjectExpr.

2023-04-05 Thread Zequan Wu via cfe-commits

Author: Zequan Wu
Date: 2023-04-05T14:37:41-04:00
New Revision: 4e93bd4174454c7c70b8f2fa7512e2f97681f295

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

LOG: [Coverage] Fix crash when visiting PseudoObjectExpr.

This is a split of D147073.

Fixes #45481

Reviewed By: aaron.ballman

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

Added: 
clang/test/CoverageMapping/strong_order.cpp

Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/test/CoverageMapping/if.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 68e6457419ab1..426ac39b8767e 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1566,6 +1566,15 @@ struct CounterCoverageMappingBuilder
 // Lambdas are treated as their own functions for now, so we shouldn't
 // propagate counts into them.
   }
+
+  void VisitPseudoObjectExpr(const PseudoObjectExpr *POE) {
+// Just visit syntatic expression as this is what users actually write.
+VisitStmt(POE->getSyntacticForm());
+  }
+
+  void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
+Visit(OVE->getSourceExpr());
+  }
 };
 
 } // end anonymous namespace

diff  --git a/clang/test/CoverageMapping/if.cpp 
b/clang/test/CoverageMapping/if.cpp
index de3554c100b96..f477db980e7f4 100644
--- a/clang/test/CoverageMapping/if.cpp
+++ b/clang/test/CoverageMapping/if.cpp
@@ -1,6 +1,14 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp 
%s | FileCheck %s
+// RUN: %clang_cc1 -fms-extensions -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp 
%s | FileCheck %s
 
 int nop() { return 0; }
+struct S {
+   int i;
+   int putprop(int j) {
+  i = j;
+  return i;
+   }
+   __declspec(property(put = putprop)) int the_prop;
+};
 
 // CHECK-LABEL: _Z3foov:
 // CHECK-NEXT: [[@LINE+3]]:12 -> [[@LINE+8]]:2 
= #0
@@ -70,7 +78,17 @@ int main() {// CHECK: File 0, 
[[@LINE]]:12 -> {{[0-9]+}}:2 =
   constexpr int c_i = check_consteval(0);
   check_consteval(i);
 
-  return 0;
+  // GH-45481
+  S s;
+  s.the_prop = 0? 1 : 2;// CHECK-NEXT: File 0, [[@LINE]]:16 -> 
[[@LINE]]:17 = #0
+// CHECK-NEXT: Branch,File 0, [[@LINE-1]]:16 
-> [[@LINE-1]]:17 = 0, 0
+// CHECK-NEXT: Gap,File 0, [[@LINE-2]]:18 -> 
[[@LINE-2]]:19 = #7
+// CHECK-NEXT: File 0, [[@LINE-3]]:19 -> 
[[@LINE-3]]:20 = #7
+// CHECK-NEXT: File 0, [[@LINE-4]]:23 -> 
[[@LINE-4]]:24 = (#0 - #7)
+  if (s.the_prop = 1) { // CHECK-NEXT: File 0, [[@LINE]]:7 -> 
[[@LINE]]:21 = #0
+ return 1;  // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 -> 
[[@LINE-1]]:21 = #8, (#0 - #8)
+  } // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:22 -> 
[[@LINE-2]]:23 = #8
+// CHECK-NEXT: File 0, [[@LINE-3]]:23 -> 
[[@LINE-1]]:4 = #8
 }
 
 #define FOO true

diff  --git a/clang/test/CoverageMapping/strong_order.cpp 
b/clang/test/CoverageMapping/strong_order.cpp
new file mode 100644
index 0..ebda311d2489b
--- /dev/null
+++ b/clang/test/CoverageMapping/strong_order.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp %s
+
+// No crash for following example.
+// See https://github.com/llvm/llvm-project/issues/45481
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {

[PATCH] D147569: [Coverage] Fix crash when visiting PseudoObjectExpr.

2023-04-05 Thread Zequan Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4e93bd417445: [Coverage] Fix crash when visiting 
PseudoObjectExpr. (authored by zequanwu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147569

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/if.cpp
  clang/test/CoverageMapping/strong_order.cpp

Index: clang/test/CoverageMapping/strong_order.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/strong_order.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp %s
+
+// No crash for following example.
+// See https://github.com/llvm/llvm-project/issues/45481
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct S {
+friend bool operator<(const S&, const S&);
+friend bool operator==(const S&, const S&);
+};
+
+struct MyStruct {
+friend bool operator==(MyStruct const& lhs, MyStruct const& rhs) = delete;
+friend std::strong_ordering operator<=>(MyStruct const& lhs, MyStruct const& rhs) = default;
+S value;
+};
+
+void foo(MyStruct bar){
+(void)(bar <=> bar);
+}
Index: clang/test/CoverageMapping/if.cpp
===
--- clang/test/CoverageMapping/if.cpp
+++ clang/test/CoverageMapping/if.cpp
@@ -1,6 +1,14 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp %s | FileCheck %s
+// RUN: %clang_cc1 -fms-extensions -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++2b -triple %itanium_abi_triple -main-file-name if.cpp %s | FileCheck %s
 
 int nop() { return 0; }
+struct S {
+   int i;
+   int putprop(int j) {
+  i = j;
+  return i;
+   }
+   __declspec(property(put = putprop)) int the_prop;
+};
 
 // CHECK-LABEL: _Z3foov:
 // CHECK-NEXT: [[@LINE+3]]:12 -> [[@LINE+8]]:2 = #0
@@ -70,7 +78,17 @@
   constexpr int c_i = check_consteval(0);
   check_consteval(i);
 
-  return 0;
+  // GH-45481
+  S s;
+  s.the_prop = 0? 1 : 2;// CHECK-NEXT: File 0, [[@LINE]]:16 -> [[@LINE]]:17 = #0
+// CHECK-NEXT: Branch,File 0, [[@LINE-1]]:16 -> [[@LINE-1]]:17 = 0, 0
+// CHECK-NEXT: Gap,File 0, [[@LINE-2]]:18 -> [[@LINE-2]]:19 = #7
+// CHECK-NEXT: File 0, [[@LINE-3]]:19 -> [[@LINE-3]]:20 = #7
+// CHECK-NEXT: File 0, [[@LINE-4]]:23 -> [[@LINE-4]]:24 = (#0 - #7)
+  if (s.the_prop = 1) { // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:21 = #0
+ return 1;  // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 -> [[@LINE-1]]:21 = #8, (#0 - #8)
+  } // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:22 -> [[@LINE-2]]:23 = #8
+// CHECK-NEXT: File 0, [[@LINE-3]]:23 -> [[@LINE-1]]:4 = #8
 }
 
 #define FOO true
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1566,6 +1566,15 @@
 // Lambdas are treated as their own functions for now, so we shouldn't
 // propagate counts into them.
   }
+
+  void VisitPseudoObjectExpr(const PseudoObjectExpr *POE) {
+// Just visit syntatic expression a

[clang] 5bab909 - Add release note for D147569.

2023-04-05 Thread Zequan Wu via cfe-commits

Author: Zequan Wu
Date: 2023-04-05T14:43:52-04:00
New Revision: 5bab9097ce5b093289e8d40809d02f002febe910

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

LOG: Add release note for D147569.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bbfef9ff3cf7..03d14fc89be4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -276,7 +276,9 @@ Bug Fixes in This Version
 - Fix crash when handling nested immediate invocations in initializers of 
global
   variables.
   (`#58207 `_)
-
+- Fix crash when generating code coverage information for `PseudoObjectExpr` 
in 
+  Clang AST.
+  (`#45481 `_)
 
 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] D147569: [Coverage] Fix crash when visiting PseudoObjectExpr.

2023-04-05 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

Added the missing release note at rG5bab9097ce5b093289e8d40809d02f002febe910 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147569

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


[PATCH] D147209: [clang][lit] Make LIT aware of env CLANG_CRASH_DIAGNOSTICS_DIR.

2023-04-05 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added a comment.

In D147209#4246622 , @leonardchan 
wrote:

> In D147209#4245229 , @fpetrogalli 
> wrote:
>
>> In D147209#4244615 , @leonardchan 
>> wrote:
>>
>>> Hi. I think this led to some test failures on our builder at 
>>> https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8784708268307261009/overview:
>>
>> Hi @leonardchan - thank you for the heads up!
>>
>> I do not have access to this bot (the link you sent just shows me a blank 
>> page), and I have not seen this (clang?) test failing in my local build. I 
>> can revert the patch, but I'll need some more info to be able to fix those 
>> failures.
>>
>> Francesco
>
> Hmm, that's interesting since the link should be public and normally doesn't 
> just appear as blank. Does it still show up as blank if you click it again? 
> Otherwise I can share the full repro. I think you should be able to reproduce 
> this if you define `CLANG_CRASH_DIAGNOSTICS_DIR` as an environment variable 
> before running `ninja check-clang`.

yep - still a white page for me...

Anyway, thank you for the suggestion - I managed to reproduce the issue (for 
example, `FAIL: Clang :: Driver/crash-report.cpp (93 of 17575)`), I'll revert 
and submit a new patch with the fix.

Francesco


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147209

___
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-05 Thread Vaibhav Yenamandra via Phabricator via cfe-commits
vaibhav.y 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);
 

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.


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


[clang] 385bcc6 - Revert "[clang][lit] Make LIT aware of env CLANG_CRASH_DIAGNOSTICS_DIR."

2023-04-05 Thread Francesco Petrogalli via cfe-commits

Author: Francesco Petrogalli
Date: 2023-04-05T20:55:08+02:00
New Revision: 385bcc65ff44d9860572ee85adb5df1333860a05

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

LOG: Revert "[clang][lit] Make LIT aware of env CLANG_CRASH_DIAGNOSTICS_DIR."

This reverts commit 029212617ca8bdedd949d17bf2d33750605ea607.

Reverting because of failures when setting
`CLANG_CRASH_DIAGNOSTICS_DIR` before invoking `ninja check-clang`.

Added: 


Modified: 
clang/test/lit.cfg.py

Removed: 




diff  --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py
index 7c5a55c8e313..e9bfaf2e9677 100644
--- a/clang/test/lit.cfg.py
+++ b/clang/test/lit.cfg.py
@@ -284,10 +284,6 @@ def exclude_unsupported_files_for_aix(dirname):
 config.substitutions.append(('llvm-nm', 'env OBJECT_MODE=any llvm-nm'))
 config.substitutions.append(('llvm-ar', 'env OBJECT_MODE=any llvm-ar'))
 
-# Pass the crash diagnostic dir set in the os environment to LIT.
-if 'CLANG_CRASH_DIAGNOSTICS_DIR' in os.environ:
-config.environment['CLANG_CRASH_DIAGNOSTICS_DIR'] = 
os.environ['CLANG_CRASH_DIAGNOSTICS_DIR']
-
 # It is not realistically possible to account for all options that could
 # possibly be present in system and user configuration files, so disable
 # default configs for the test runs.



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


[PATCH] D146376: Update static_assert message for redundant cases

2023-04-05 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 511181.
Krishna-13-cyber added a comment.

- Updated with the diagnostic messages (comments for test cases)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146376

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/static-assert.cpp


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
-  static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{static 
assertion failed due to requirement 'invert(true) || invert(true)'}}
+  static_assert(invert(true) == invert(false), ""); // expected-error {{static 
assertion failed due to requirement 'invert(true) == invert(false)'}} \
 // expected-note 
{{evaluates to 'false == true'}}
+  static_assert(true && false, ""); // expected-error {{static assertion 
failed due to requirement 'true && false'}}
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error 
{{static assertion failed due to requirement 'invert(true) || invert(true) || 
false'}}
+  static_assert((true && invert(true)) || false, ""); // expected-error 
{{static assertion failed due to requirement '(true && invert(true)) || false'}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error 
{{static assertion failed due to requirement 'invert(true)'}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,8 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);
+  Op && Op->getOpcode() != BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -179,6 +179,9 @@
 - Clang now avoids duplicate warnings on unreachable ``[[fallthrough]];`` 
statements
   previously issued from ``-Wunreachable-code`` and 
``-Wunreachable-code-fallthrough``
   by prioritizing ``-Wunreachable-code-fallthrough``.
+- Clang now avoids unnecessary diagnostic warnings for obvious expressions in
+  the case of binary operators with logical OR operations.
+  (`#57906 `_)
 
 Bug Fixes in This Version
 -


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
-  static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{static assertion failed due to requirement 'invert(true) || invert(true)'}}
+  static_assert(invert(true) == invert(false), ""); // expected-error {{static assertion failed due to requirement 'invert(true) == invert(false)'}} \
 // expected-note {{evaluates to 'false == true'}}
+  static_assert(true && false, ""); // expected-error {{static assertion failed due to requirement 'true && false'}}
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error {{static assertion failed due to requirement 'invert(true) || invert(true) || false'}}
+  static_assert((true && invert(true)) || false, ""); // expected-error {{static assertion failed due to requirement '(true && invert(true)) || false'}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error {{static assertion failed due to requirement 'invert(true)'}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,8 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAsser

[clang] 34f1439 - [clang][deps] NFC: Don't collect PCH input files

2023-04-05 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2023-04-05T12:29:03-07:00
New Revision: 34f143988f3f18dcca6d26a7a9817d8523300440

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

LOG: [clang][deps] NFC: Don't collect PCH input files

Since b4c83a13, PCH input files are no longer necessary.

Added: 


Modified: 
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Removed: 




diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index 5869418b98dfe..937f39ba3bffa 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -66,30 +66,19 @@ using PrebuiltModuleFilesT = 
decltype(HeaderSearchOptions::PrebuiltModuleFiles);
 class PrebuiltModuleListener : public ASTReaderListener {
 public:
   PrebuiltModuleListener(PrebuiltModuleFilesT &PrebuiltModuleFiles,
- llvm::StringSet<> &InputFiles, bool VisitInputFiles,
  llvm::SmallVector &NewModuleFiles)
-  : PrebuiltModuleFiles(PrebuiltModuleFiles), InputFiles(InputFiles),
-VisitInputFiles(VisitInputFiles), NewModuleFiles(NewModuleFiles) {}
+  : PrebuiltModuleFiles(PrebuiltModuleFiles),
+NewModuleFiles(NewModuleFiles) {}
 
   bool needsImportVisitation() const override { return true; }
-  bool needsInputFileVisitation() override { return VisitInputFiles; }
-  bool needsSystemInputFileVisitation() override { return VisitInputFiles; }
 
   void visitImport(StringRef ModuleName, StringRef Filename) override {
 if (PrebuiltModuleFiles.insert({ModuleName.str(), Filename.str()}).second)
   NewModuleFiles.push_back(Filename.str());
   }
 
-  bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden,
-  bool isExplicitModule) override {
-InputFiles.insert(Filename);
-return true;
-  }
-
 private:
   PrebuiltModuleFilesT &PrebuiltModuleFiles;
-  llvm::StringSet<> &InputFiles;
-  bool VisitInputFiles;
   llvm::SmallVector &NewModuleFiles;
 };
 
@@ -97,13 +86,10 @@ class PrebuiltModuleListener : public ASTReaderListener {
 /// transitively imports and contributing input files.
 static void visitPrebuiltModule(StringRef PrebuiltModuleFilename,
 CompilerInstance &CI,
-PrebuiltModuleFilesT &ModuleFiles,
-llvm::StringSet<> &InputFiles,
-bool VisitInputFiles) {
+PrebuiltModuleFilesT &ModuleFiles) {
   // List of module files to be processed.
   llvm::SmallVector Worklist{PrebuiltModuleFilename.str()};
-  PrebuiltModuleListener Listener(ModuleFiles, InputFiles, VisitInputFiles,
-  Worklist);
+  PrebuiltModuleListener Listener(ModuleFiles, Worklist);
 
   while (!Worklist.empty())
 ASTReader::readASTFileControlBlock(
@@ -204,15 +190,13 @@ class DependencyScanningAction : public 
tooling::ToolAction {
 
 ScanInstance.createSourceManager(*FileMgr);
 
-llvm::StringSet<> PrebuiltModulesInputFiles;
 // Store the list of prebuilt module files into header search options. This
 // will prevent the implicit build to create duplicate modules and will
 // force reuse of the existing prebuilt module files instead.
 if (!ScanInstance.getPreprocessorOpts().ImplicitPCHInclude.empty())
   visitPrebuiltModule(
   ScanInstance.getPreprocessorOpts().ImplicitPCHInclude, ScanInstance,
-  ScanInstance.getHeaderSearchOpts().PrebuiltModuleFiles,
-  PrebuiltModulesInputFiles, /*VisitInputFiles=*/DepFS != nullptr);
+  ScanInstance.getHeaderSearchOpts().PrebuiltModuleFiles);
 
 // Use the dependency scanning optimized file system if requested to do so.
 if (DepFS) {



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


[clang] 65c0134 - [clang][deps] NFC: Make PCH test more debuggable

2023-04-05 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2023-04-05T12:29:05-07:00
New Revision: 65c0134872c1e298ade176b5c84d86b4a058a85c

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

LOG: [clang][deps] NFC: Make PCH test more debuggable

Overwriting CDB files made it difficult to debug earlier clang-scan-deps 
invocations. This commit creates separate files for each.

Added: 


Modified: 
clang/test/ClangScanDeps/modules-pch.c

Removed: 




diff  --git a/clang/test/ClangScanDeps/modules-pch.c 
b/clang/test/ClangScanDeps/modules-pch.c
index 0e1e72225cb4a..aa568e5aaab4d 100644
--- a/clang/test/ClangScanDeps/modules-pch.c
+++ b/clang/test/ClangScanDeps/modules-pch.c
@@ -7,8 +7,8 @@
 
 // Scan dependencies of the PCH:
 //
-// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_pch.json > %t/cdb.json
-// RUN: clang-scan-deps -compilation-database %t/cdb.json -format 
experimental-full \
+// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_pch.json > %t/cdb_pch.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_pch.json -format 
experimental-full \
 // RUN:   -module-files-dir %t/build > %t/result_pch.json
 // RUN: cat %t/result_pch.json | sed 's:\?:/:g' | FileCheck %s 
-DPREFIX=%/t -check-prefix=CHECK-PCH
 //
@@ -94,8 +94,8 @@
 
 // Scan dependencies of the TU:
 //
-// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu.json > %t/cdb.json
-// RUN: clang-scan-deps -compilation-database %t/cdb.json -format 
experimental-full \
+// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu.json > %t/cdb_tu.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_tu.json -format 
experimental-full \
 // RUN:   -module-files-dir %t/build > %t/result_tu.json
 // RUN: cat %t/result_tu.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t 
-check-prefix=CHECK-TU
 //
@@ -142,8 +142,8 @@
 
 // Scan dependencies of the TU that has common modules with the PCH:
 //
-// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu_with_common.json > 
%t/cdb.json
-// RUN: clang-scan-deps -compilation-database %t/cdb.json -format 
experimental-full \
+// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu_with_common.json > 
%t/cdb_tu_with_common.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_tu_with_common.json 
-format experimental-full \
 // RUN:   -module-files-dir %t/build > %t/result_tu_with_common.json
 // RUN: cat %t/result_tu_with_common.json | sed 's:\?:/:g' | FileCheck %s 
-DPREFIX=%/t -check-prefix=CHECK-TU-WITH-COMMON
 //



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


[PATCH] D146042: [clang-format] Fix numerous issues with "LambdaBodyIndentation: OuterScope" option

2023-04-05 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added a comment.

Thanks for accepting!

Commit details as follows as per previous diff:

Name: Jon Phillips
Email: jonap2...@gmail.com

If someone could commit for me that would be much appreciated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146042

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


[PATCH] D147655: Implement mangling rules for C++20 concepts and requires-expressions.

2023-04-05 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Here's the diff to `test_demangle.pass.cpp`:

  --- a/libcxxabi/test/test_demangle.pass.cpp
  +++ b/libcxxabi/test/test_demangle.pass.cpp
  @@ -29995,10 +29995,10 @@ const char* cases[][2] =
   {"_Z15test_uuidofTypeI10TestStructEvDTu8__uuidofT_EE", "void 
test_uuidofType(decltype(__uuidof(TestStruct)))"},
   {"_Z15test_uuidofExprI9HasMemberEvDTu8__uuidofXsrT_6memberEEE", "void 
test_uuidofExpr(decltype(__uuidof(HasMember::member)))"},
   
  -// C++2a char8_t:
  +// C++20 char8_t:
   {"_ZTSPDu", "typeinfo name for char8_t*"},
   
  -// C++2a lambda-expressions:
  +// C++20 lambda-expressions:
   {"_ZNK1xMUlTyT_E_clIiEEDaS_", "auto x::'lambda'($T)::operator()(x) const"},
   {"_ZNK1xMUlTnPA3_ivE_clILS0_0EEEDav", "auto x::'lambda'()::operator()<(int [3])0>() const"},
   {"_ZNK1xMUlTyTtTyTnT_TpTnPA3_TL0__ETpTyvE_clIi1XJfEEEDav", "auto 
x::'lambda' 
typename $TT, typename ...$T1>()::operator()() const"},
  @@ -30015,8 +30015,10 @@ const char* cases[][2] =
   // See https://github.com/itanium-cxx-abi/cxx-abi/issues/106.
   {"_ZN1XIZ1fIiEvOT_EUlS2_DpT0_E_EclIJEEEvDpT_", "void X(int&&)::'lambda'(int&&, auto...)>::operator()<>()"},
   
{"_N6abcdef9abcdefghi29abcdefabcdefabcdefabcefabcdef27xxxEN4absl8DurationERKNSt3__u12basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcPNS1_19yyyEENK3$_5clEvENKUlvE_clEvE6zz",
 
"abcdef::abcdefghi::abcdefabcdefabcdefabcefabcdef::xxx(absl::Duration,
 std::__u::basic_string, 
std::__u::allocator> const&, 
abcdef::abcdefghi::abcdefabcdefabcdefabcefabcdef::yyy*)::$_5::operator()()
 const::'lambda'()::operator()() const::zz"},
  +// See https://github.com/itanium-cxx-abi/cxx-abi/issues/165.
  +{"_ZN1C1fIiEEvDTtlNS_UlT_TL0__E_EEE", "void 
C::f(decltype(C::'lambda'(int, auto){}))"},
   
  -// C++2a class type non-type template parameters:
  +// C++20 class type non-type template parameters:
   {"_Z1fIXtl1BLPi0ELi1vv", "void f()"},
   {"_Z1fIXtl1BLPi32vv", "void f()"},
   {"_Z1fIXtl1BrcPiLi0vv", "void f(0)}>()"},
  @@ -30089,6 +30091,51 @@ const char* cases[][2] =
   {"_ZW1ML4Oink", "Oink@M"},
   {"_ZW1ML1fi", "f@M(int)"},
   
  +// C++20 concepts, see 
https://github.com/itanium-cxx-abi/cxx-abi/issues/24.
  +{"_Z2f0IiE1SIX1CIT_EEEv", "S> f0()"},
  +{"_ZN5test21AIiEF1fEzQ4TrueIT_E", "test2::A::friend f(...) requires 
True"},
  +{"_ZN5test2F1gIvEEvzQaa4TrueIT_E4TrueITL0__E", "void test2::friend 
g(...) requires True && True"},
  +{"_ZN5test21hIvEEvzQ4TrueITL0__E", "void test2::h(...) requires 
True"},
  +{"_ZN5test2F1iIvQaa4TrueIT_E4TrueITL0__EEEvz", "void test2::friend 
i(...)"},
  +{"_ZN5test21jIvQ4TrueITL0__EEEvz", "void test2::j(...)"},
  +{"_ZN5test2F1kITk4TruevQ4TrueIT_EEEvz", "void test2::friend 
k(...)"},
  +{"_ZN5test21lITk4TruevEEvz", "void test2::l(...)"},
  +{"_ZN5test31dITnDaLi0EEEvv", "void test3::d<0>()"},
  +{"_ZN5test31eITnDcLi0EEEvv", "void test3::e<0>()"},
  +{"_ZN5test31fITnDk1CLi0EEEvv", "void test3::f<0>()"},
  +{"_ZN5test31gITnDk1DIiELi0EEEvv", "void test3::g<0>()"},
  +{"_ZN5test31hIiTnDk1DIT_ELi0EEEvv", "void test3::h()"},
  +{"_ZN5test31iIiEEvDTnw_Dk1CpicvT__EEE", "void test3::i(decltype(new 
C auto((int)("},
  +{"_ZN5test31jIiEEvDTnw_DK1CpicvT__EEE", "void test3::j(decltype(new 
C decltype(auto)((int)("},
  +{"_ZN5test41fITk1CiEEvv", "void test4::f()"},
  +{"_ZN5test41gITk1DIiEiEEvv", "void test4::g()"},
  +{"_ZN5test51fINS_1XEEEvv", "void test5::f()"},
  +{"_ZN5test51fITtTyTnTL0__ENS_1YEEEvv", "void test5::f()"},
  +{"_ZN5test51fITtTyTnTL0__ENS_1ZEEEvv", "void test5::f()"},
  +{"_ZN5test51gITtTyTnTL0__Q1CIS1_EENS_1XEEEvv", "void 
test5::g()"},
  +{"_ZN5test51gINS_1YEEEvv", "void test5::g()"},
  +{"_ZN5test51gITtTyTnTL0__Q1CIS1_EENS_1ZEEEvv", "void 
test5::g()"},
  +{"_ZN5test51hITtTk1CTnTL0__ENS_1XEEEvv", "void test5::h()"},
  +{"_ZN5test51hITtTk1CTnTL0__ENS_1YEEEvv", "void test5::h()"},
  +{"_ZN5test51hINS_1ZEEEvv", "void test5::h()"},
  +{"_ZN5test51iITpTtTk1CTnTL0__EJNS_1XENS_1YENS_1Zvv", "void 
test5::i()"},
  +{"_ZN5test51iITpTtTk1CTnTL0__EJNS_1YENS_1ZENS_1Xvv", "void 
test5::i()"},
  +{"_ZN5test51iIJNS_1ZENS_1XENS_1Yvv", "void test5::i()"},
  +{"_ZN5test51pINS_1AEEEvv", "void test5::p()"},
  +{"_ZN5test51pITtTpTyENS_1BEEEvv", "void test5::p()"},
  +{"_ZN5test51qITtTyTyENS_1AEEEvv", "void test5::q()"},
  +{"_ZN5test51qINS_1BEEEvv", "void test5::q()"},
  +{"_ZN5test61fITk1CiEEvT_", "void test6::f(int)"},
  +{"_ZN5test61gIiTk1DIT_EiEEvT0_", "void test6::g(int)"},
  +
{"_ZZN5test71fIiEEvvENKUlTyQaa1CIT_E1CITL0__ET0_E_clIiiEEDaS3_Q1CIDtfp_EE", 
"auto void test7::f()::'lambda' requires C && C 
(auto)::operator()(auto) const requires C"},
  +
{"_ZZN5test71fIiEEvvENKUlTyQaa1CIT_E1C

[PATCH] D147655: Implement mangling rules for C++20 concepts and requires-expressions.

2023-04-05 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I can't really review the libcxxabi parts, or the llvm-demangler parts, but 
everything looks right to me.  I've got a pair of quick questions, otherwise I 
think this is going to be fine for me.

Note the extra paren changes are something I think are valuable, but I'm trying 
to figure out their meaning in thsi patch.




Comment at: clang/include/clang/AST/ExprConcepts.h:502
ArrayRef LocalParameters,
+   SourceLocation RParenLoc,
ArrayRef Requirements,

Is this an unrelated change?  Are paren locations required for mangling?



Comment at: clang/lib/AST/ItaniumMangle.cpp:5180
+NotPrimaryExpr();
+if (RE->getLParenLoc().isValid()) {
+  Out << "rQ";

What is happening here? What are we deriving from the validity of the paren?  
Or is this differentiating:

`requires (something)` vs `requires C` sorta thing?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147655

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


[PATCH] D146090: [Clang] Updating handling of defaulted comparison operators to reflect changes from P2448R2

2023-04-05 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

I'm happy whenever Aaron is.




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:8809
+  //
+  // We will support P2448R2 in language modes earlier than C++23 as an 
extenion
+  // The concept of constexpr-compatible was removed.





Comment at: clang/lib/Sema/SemaDeclCXX.cpp:8826-8827
+  getLangOpts().CPlusPlus2b
+  ? 
diag::warn_cxx2b_compat_incorrect_defaulted_comparison_constexpr
+  : diag::ext_incorrect_defaulted_comparison_constexpr)
   << FD->isImplicit() << (int)DCK << FD->isConsteval();

I wonder if `incorrect_` is the best way to spell the diagnostic ID given the 
new rule. Suggested an alternative.


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

https://reviews.llvm.org/D146090

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


[clang] c37b95b - [PS4][clang] Fix the format of the LTO debug options passed to orbis-ld

2023-04-05 Thread Matthew Voss via cfe-commits

Author: Matthew Voss
Date: 2023-04-05T12:57:21-07:00
New Revision: c37b95b515a5c69b2050c8fd50f076368742c6cb

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

LOG: [PS4][clang] Fix the format of the LTO debug options passed to orbis-ld

Currently, we pass multiple LTO debug options to orbis-ld like this:

orbis-ld --lto=thin --lto-thin-debug-options= 
--lto-thin-debug-options= ...

When it should be like this:

orbis-ld --lto=thin "--lto-thin-debug-options=  " ...

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/test/Driver/ps4-ps5-linker.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 8c8b7c73c1bf5..71c6b650e1f52 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -160,18 +160,12 @@ void tools::PScpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   const bool IsPS5 = TC.getTriple().isPS5();
   assert(IsPS4 || IsPS5);
 
+  const char *PS4LTOArgs = "";
   auto AddCodeGenFlag = [&](Twine Flag) {
-const char *Prefix = nullptr;
-if (IsPS4 && D.getLTOMode() == LTOK_Thin)
-  Prefix = "-lto-thin-debug-options=";
-else if (IsPS4 && D.getLTOMode() == LTOK_Full)
-  Prefix = "-lto-debug-options=";
+if (IsPS4)
+  PS4LTOArgs = Args.MakeArgString(Twine(PS4LTOArgs) + " " + Flag);
 else if (IsPS5)
-  Prefix = "-plugin-opt=";
-else
-  llvm_unreachable("new LTO mode?");
-
-CmdArgs.push_back(Args.MakeArgString(Twine(Prefix) + Flag));
+  CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=") + Flag));
   };
 
   if (UseLTO) {
@@ -185,6 +179,18 @@ void tools::PScpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 
 if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
   AddCodeGenFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
+
+if (IsPS4) {
+  const char *Prefix = nullptr;
+  if (D.getLTOMode() == LTOK_Thin)
+Prefix = "-lto-thin-debug-options=";
+  else if (D.getLTOMode() == LTOK_Full)
+Prefix = "-lto-debug-options=";
+  else
+llvm_unreachable("new LTO mode?");
+
+  CmdArgs.push_back(Args.MakeArgString(Twine(Prefix) + PS4LTOArgs));
+}
   }
 
   if (IsPS5 && UseLTO) {

diff  --git a/clang/test/Driver/ps4-ps5-linker.c 
b/clang/test/Driver/ps4-ps5-linker.c
index ee8e96bbfbd02..8aae94c838834 100644
--- a/clang/test/Driver/ps4-ps5-linker.c
+++ b/clang/test/Driver/ps4-ps5-linker.c
@@ -7,8 +7,8 @@
 // RUN: %clang --target=x86_64-scei-ps5 -flto -fjmc %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PS5-LTO,CHECK-PS5-LIB %s
 
 // CHECK-PS4-NOT: -enable-jmc-instrument
-// CHECK-PS4-THIN-LTO: -lto-thin-debug-options=-enable-jmc-instrument
-// CHECK-PS4-FULL-LTO: -lto-debug-options=-enable-jmc-instrument
+// CHECK-PS4-THIN-LTO: "-lto-thin-debug-options= -generate-arange-section 
-enable-jmc-instrument"
+// CHECK-PS4-FULL-LTO: "-lto-debug-options= -generate-arange-section 
-enable-jmc-instrument"
 // CHECK-PS5-NOT: -plugin-opt=-enable-jmc-instrument
 // CHECK-PS5-LTO: -plugin-opt=-enable-jmc-instrument
 
@@ -23,7 +23,7 @@
 // RUN: %clang --target=x86_64-scei-ps5 -fcrash-diagnostics-dir=mydumps %s 
-### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG-PS5 %s
 // RUN: %clang --target=x86_64-scei-ps5 -flto -fcrash-diagnostics-dir=mydumps 
%s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG-PS5-LTO %s
 
-// CHECK-DIAG-PS4-THIN-LTO: 
-lto-thin-debug-options=-crash-diagnostics-dir=mydumps
-// CHECK-DIAG-PS4-FULL-LTO: -lto-debug-options=-crash-diagnostics-dir=mydumps
+// CHECK-DIAG-PS4-THIN-LTO: "-lto-thin-debug-options= -generate-arange-section 
-crash-diagnostics-dir=mydumps"
+// CHECK-DIAG-PS4-FULL-LTO: "-lto-debug-options= -generate-arange-section 
-crash-diagnostics-dir=mydumps"
 // CHECK-DIAG-PS5-NOT: -plugin-opt=-crash-diagnostics-dir=mydumps
 // CHECK-DIAG-PS5-LTO: -plugin-opt=-crash-diagnostics-dir=mydumps



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


[PATCH] D147546: [PS4][clang] Fix the format of the LTO debug options passed to orbis-ld

2023-04-05 Thread Matthew Voss 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 rGc37b95b515a5: [PS4][clang] Fix the format of the LTO debug 
options passed to orbis-ld (authored by ormris).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147546

Files:
  clang/lib/Driver/ToolChains/PS4CPU.cpp
  clang/test/Driver/ps4-ps5-linker.c


Index: clang/test/Driver/ps4-ps5-linker.c
===
--- clang/test/Driver/ps4-ps5-linker.c
+++ clang/test/Driver/ps4-ps5-linker.c
@@ -7,8 +7,8 @@
 // RUN: %clang --target=x86_64-scei-ps5 -flto -fjmc %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PS5-LTO,CHECK-PS5-LIB %s
 
 // CHECK-PS4-NOT: -enable-jmc-instrument
-// CHECK-PS4-THIN-LTO: -lto-thin-debug-options=-enable-jmc-instrument
-// CHECK-PS4-FULL-LTO: -lto-debug-options=-enable-jmc-instrument
+// CHECK-PS4-THIN-LTO: "-lto-thin-debug-options= -generate-arange-section 
-enable-jmc-instrument"
+// CHECK-PS4-FULL-LTO: "-lto-debug-options= -generate-arange-section 
-enable-jmc-instrument"
 // CHECK-PS5-NOT: -plugin-opt=-enable-jmc-instrument
 // CHECK-PS5-LTO: -plugin-opt=-enable-jmc-instrument
 
@@ -23,7 +23,7 @@
 // RUN: %clang --target=x86_64-scei-ps5 -fcrash-diagnostics-dir=mydumps %s 
-### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG-PS5 %s
 // RUN: %clang --target=x86_64-scei-ps5 -flto -fcrash-diagnostics-dir=mydumps 
%s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG-PS5-LTO %s
 
-// CHECK-DIAG-PS4-THIN-LTO: 
-lto-thin-debug-options=-crash-diagnostics-dir=mydumps
-// CHECK-DIAG-PS4-FULL-LTO: -lto-debug-options=-crash-diagnostics-dir=mydumps
+// CHECK-DIAG-PS4-THIN-LTO: "-lto-thin-debug-options= -generate-arange-section 
-crash-diagnostics-dir=mydumps"
+// CHECK-DIAG-PS4-FULL-LTO: "-lto-debug-options= -generate-arange-section 
-crash-diagnostics-dir=mydumps"
 // CHECK-DIAG-PS5-NOT: -plugin-opt=-crash-diagnostics-dir=mydumps
 // CHECK-DIAG-PS5-LTO: -plugin-opt=-crash-diagnostics-dir=mydumps
Index: clang/lib/Driver/ToolChains/PS4CPU.cpp
===
--- clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -160,18 +160,12 @@
   const bool IsPS5 = TC.getTriple().isPS5();
   assert(IsPS4 || IsPS5);
 
+  const char *PS4LTOArgs = "";
   auto AddCodeGenFlag = [&](Twine Flag) {
-const char *Prefix = nullptr;
-if (IsPS4 && D.getLTOMode() == LTOK_Thin)
-  Prefix = "-lto-thin-debug-options=";
-else if (IsPS4 && D.getLTOMode() == LTOK_Full)
-  Prefix = "-lto-debug-options=";
+if (IsPS4)
+  PS4LTOArgs = Args.MakeArgString(Twine(PS4LTOArgs) + " " + Flag);
 else if (IsPS5)
-  Prefix = "-plugin-opt=";
-else
-  llvm_unreachable("new LTO mode?");
-
-CmdArgs.push_back(Args.MakeArgString(Twine(Prefix) + Flag));
+  CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=") + Flag));
   };
 
   if (UseLTO) {
@@ -185,6 +179,18 @@
 
 if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
   AddCodeGenFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
+
+if (IsPS4) {
+  const char *Prefix = nullptr;
+  if (D.getLTOMode() == LTOK_Thin)
+Prefix = "-lto-thin-debug-options=";
+  else if (D.getLTOMode() == LTOK_Full)
+Prefix = "-lto-debug-options=";
+  else
+llvm_unreachable("new LTO mode?");
+
+  CmdArgs.push_back(Args.MakeArgString(Twine(Prefix) + PS4LTOArgs));
+}
   }
 
   if (IsPS5 && UseLTO) {


Index: clang/test/Driver/ps4-ps5-linker.c
===
--- clang/test/Driver/ps4-ps5-linker.c
+++ clang/test/Driver/ps4-ps5-linker.c
@@ -7,8 +7,8 @@
 // RUN: %clang --target=x86_64-scei-ps5 -flto -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PS5-LTO,CHECK-PS5-LIB %s
 
 // CHECK-PS4-NOT: -enable-jmc-instrument
-// CHECK-PS4-THIN-LTO: -lto-thin-debug-options=-enable-jmc-instrument
-// CHECK-PS4-FULL-LTO: -lto-debug-options=-enable-jmc-instrument
+// CHECK-PS4-THIN-LTO: "-lto-thin-debug-options= -generate-arange-section -enable-jmc-instrument"
+// CHECK-PS4-FULL-LTO: "-lto-debug-options= -generate-arange-section -enable-jmc-instrument"
 // CHECK-PS5-NOT: -plugin-opt=-enable-jmc-instrument
 // CHECK-PS5-LTO: -plugin-opt=-enable-jmc-instrument
 
@@ -23,7 +23,7 @@
 // RUN: %clang --target=x86_64-scei-ps5 -fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG-PS5 %s
 // RUN: %clang --target=x86_64-scei-ps5 -flto -fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG-PS5-LTO %s
 
-// CHECK-DIAG-PS4-THIN-LTO: -lto-thin-debug-options=-crash-diagnostics-dir=mydumps
-// CHECK-DIAG-PS4-FULL-LTO: -lto-debug-options=-crash-diagnostics-dir=mydumps
+// CHECK-DIA

[clang] 59cb470 - [NFC][clang] Fix Coverity static analyzer tool concerns about auto_causes_copy

2023-04-05 Thread via cfe-commits

Author: Manna, Soumi
Date: 2023-04-05T16:00:45-04:00
New Revision: 59cb47015a184862f3709a7ab084ccd086816176

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

LOG: [NFC][clang] Fix Coverity static analyzer tool concerns about 
auto_causes_copy

Reported by Coverity:

AUTO_CAUSES_COPY
Unnecessary object copies can affect performance

Inside FrontendActions.cpp file,
In clang::DumpModuleInfoAction::ExecuteAction(): Using the auto keyword 
without an & causes the copy of an object of type pair.

Inside ComputeDependence.cpp file,
In clang::computeDependence(clang::OverloadExpr *, bool, bool, bool): Using 
the auto keyword without an & causes the copy of an object of type 
TemplateArgumentLoc.

Reviewed By: erichkeane, aaron.ballman

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

Added: 


Modified: 
clang/lib/AST/ComputeDependence.cpp
clang/lib/Frontend/FrontendActions.cpp

Removed: 




diff  --git a/clang/lib/AST/ComputeDependence.cpp 
b/clang/lib/AST/ComputeDependence.cpp
index eb9afbdb1c879..cd204ed62b5dd 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -750,7 +750,7 @@ clang::computeDependence(OverloadExpr *E, bool 
KnownDependent,
   // If we have explicit template arguments, check for dependent
   // template arguments and whether they contain any unexpanded pack
   // expansions.
-  for (auto A : E->template_arguments())
+  for (const auto &A : E->template_arguments())
 Deps |= toExprDependence(A.getArgument().getDependence());
   return Deps;
 }

diff  --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 0349e769595dd..c947772ec3e70 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -882,7 +882,7 @@ void DumpModuleInfoAction::ExecuteAction() {
 }
 
 // Now let's print out any modules we did not see as part of the Primary.
-for (auto SM : SubModMap) {
+for (const auto &SM : SubModMap) {
   if (!SM.second.Seen && SM.second.Mod) {
 Out << "  " << ModuleKindName(SM.second.Kind) << " '" << SM.first
 << "' at index #" << SM.second.Idx



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


[PATCH] D147657: [Sema] Fix reporting of invalid shader attribute on HLSL entry function

2023-04-05 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm created this revision.
rsandifo-arm added reviewers: python3kgae, erichkeane.
Herald added a subscriber: Anastasia.
Herald added a project: All.
rsandifo-arm requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If the HLSL entry function had a shader attribute that conflicted
with the pipeline stage specified in the target triple, Clang
would emit:

  error: (null) attribute parameters do not match the previous declaration
  conflicting attribute is here

(where the second line doesn't reference an attribute).

This was because the code constructed a dummy attribute that had
only a source location, but no kind or syntax.

Noticed while doing some changes to the attribute handling.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147657

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaHLSL/entry_shader.hlsl


Index: clang/test/SemaHLSL/entry_shader.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/entry_shader.hlsl
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"anyHit"' -verify
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"compute"'
+
+// expected-error@+1 {{'shader' attribute on entry function does not match the 
pipeline stage}}
+[numthreads(1,1,1), shader(SHADER)]
+void foo() {
+
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -10205,14 +10205,19 @@
   CheckHLSLEntryPoint(NewFD);
   if (!NewFD->isInvalidDecl()) {
 auto Env = TargetInfo.getTriple().getEnvironment();
-AttributeCommonInfo AL(NewFD->getBeginLoc());
 HLSLShaderAttr::ShaderType ShaderType =
 static_cast(
 hlsl::getStageFromEnvironment(Env));
 // To share code with HLSLShaderAttr, add HLSLShaderAttr to entry
 // function.
-if (HLSLShaderAttr *Attr = mergeHLSLShaderAttr(NewFD, AL, ShaderType))
-  NewFD->addAttr(Attr);
+if (HLSLShaderAttr *NT = NewFD->getAttr()) {
+  if (NT->getType() != ShaderType)
+Diag(NT->getLocation(), diag::err_hlsl_entry_shader_attr_mismatch)
+<< NT;
+} else {
+  NewFD->addAttr(HLSLShaderAttr::Create(Context, ShaderType,
+NewFD->getBeginLoc()));
+}
   }
 }
 // HLSL does not support specifying an address space on a function return
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11752,6 +11752,8 @@
"attribute %0 only applies to a field or parameter of type '%1'">;
 def err_hlsl_attr_invalid_ast_node : Error<
"attribute %0 only applies to %1">;
+def err_hlsl_entry_shader_attr_mismatch : Error<
+   "%0 attribute on entry function does not match the pipeline stage">;
 def err_hlsl_numthreads_argument_oor : Error<"argument '%select{X|Y|Z}0' to 
numthreads attribute cannot exceed %1">;
 def err_hlsl_numthreads_invalid : Error<"total number of threads cannot exceed 
%0">;
 def err_hlsl_missing_numthreads : Error<"missing numthreads attribute for %0 
shader entry">;


Index: clang/test/SemaHLSL/entry_shader.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/entry_shader.hlsl
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry foo  -o - %s -DSHADER='"anyHit"' -verify
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry foo  -o - %s -DSHADER='"compute"'
+
+// expected-error@+1 {{'shader' attribute on entry function does not match the pipeline stage}}
+[numthreads(1,1,1), shader(SHADER)]
+void foo() {
+
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -10205,14 +10205,19 @@
   CheckHLSLEntryPoint(NewFD);
   if (!NewFD->isInvalidDecl()) {
 auto Env = TargetInfo.getTriple().getEnvironment();
-AttributeCommonInfo AL(NewFD->getBeginLoc());
 HLSLShaderAttr::ShaderType ShaderType =
 static_cast(
 hlsl::getStageFromEnvironment(Env));
 // To share code with HLSLShaderAttr, add HLSLShaderAttr to entry
 // function.
-if (HLSLShaderAttr *Attr = mergeHLSLShaderAttr(NewFD, AL, ShaderType))
-  NewFD->addAttr(Attr);
+if (HLSLShaderAttr *NT = NewFD->getAttr()) {
+  if (NT->getType() != ShaderType)
+Diag(NT->getLocation(), diag::

[PATCH] D146101: [clang-format] Add BracedInitializerIndentWidth option.

2023-04-05 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added a comment.

Following on from our discussion about new options needing motivation from 
public style guides, I've updated the KJ style guide to clarify its stance on 
braced init lists: 
https://github.com/capnproto/capnproto/blob/master/style-guide.md#spacing-and-bracing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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


[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-04-05 Thread Felipe de Azevedo Piovezan via Phabricator via cfe-commits
fdeazeve added a comment.

I can check out a copy of this patch and help test it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144651

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


[clang] c61f45f - Update clang :: Driver/debug-options.c to fix the buildbots

2023-04-05 Thread Matthew Voss via cfe-commits

Author: Matthew Voss
Date: 2023-04-05T13:27:17-07:00
New Revision: c61f45fc3e041606c5b94c468a5c092e8a6e5601

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

LOG: Update clang :: Driver/debug-options.c to fix the buildbots

The format of the LTO debug options generated for orbis-ld changed,
breaking this test.

https://lab.llvm.org/buildbot/#/builders/230/builds/11367

Added: 


Modified: 
clang/test/Driver/debug-options.c

Removed: 




diff  --git a/clang/test/Driver/debug-options.c 
b/clang/test/Driver/debug-options.c
index dedd96c82da96..8617949cea1c8 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -390,8 +390,8 @@
 // LDGARANGE: {{".*ld.*"}} {{.*}}
 // LDGARANGE-NOT: "-plugin-opt=-generate-arange-section"
 // LLDGARANGE: {{".*lld.*"}} {{.*}} "-plugin-opt=-generate-arange-section"
-// SNLDTLTOGARANGE: {{".*orbis-ld.*"}} {{.*}} 
"-lto-thin-debug-options=-generate-arange-section"
-// SNLDFLTOGARANGE: {{".*orbis-ld.*"}} {{.*}} 
"-lto-debug-options=-generate-arange-section"
+// SNLDTLTOGARANGE: {{".*orbis-ld.*"}} {{.*}} "-lto-thin-debug-options= 
-generate-arange-section"
+// SNLDFLTOGARANGE: {{".*orbis-ld.*"}} {{.*}} "-lto-debug-options= 
-generate-arange-section"
 
 // PUB: -gpubnames
 //



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


[PATCH] D147574: [NFC][clang] Fix Coverity static analyzer tool concerns about auto_causes_copy

2023-04-05 Thread Soumi Manna via Phabricator via cfe-commits
Manna added a comment.

I have committed the patch here: https://reviews.llvm.org/rG59cb47015a18


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147574

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


[PATCH] D147626: [clang] Do not crash when initializing union with flexible array member

2023-04-05 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a subscriber: rsmith.
shafik added a comment.

Thank you for this fix.




Comment at: clang/lib/Sema/SemaInit.cpp:808
   unsigned NumElems = numStructUnionElements(ILE->getType());
-  if (RDecl->hasFlexibleArrayMember())
+  if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember())
 ++NumElems;

Fznamznon wrote:
> Just for some context, numStructUnionElements checks that there is a flexible 
> array member and returns number_of_initializable_fields-1 for structs. For 
> unions it just returns 1 or 0, so flexible array member caused adding one 
> more element to initlistexpr that was never properly handled.
> 
> Instead of doing this change, we could probably never enter initialization 
> since the record (union) declaration is not valid, but that is not the case 
> even for other types of errors in code, for example, I've tried declaring 
> field of struct with a typo:
> 
> ```
> struct { cha x[]; } r = {1}; 
> ```
> Initialization is still performed by clang.
> Also, it seems MSVC considers flexible array member inside union as valid, so 
> the test code is probably not always invalid.
I am not sure what to think here, looking at gcc documentation for this 
extension: https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html 

and using the following code:

```
struct f1 {
  int x; int y[];
} f1 = { 1, { 2, 3, 4 } }; // #1

struct f2 {
  struct f1 f1; int data[3];
} f2 = { { 1 }, { 2, 3, 4 } }; // #2

struct { char x[]; } r = {1};  // #3
```

gcc rejects 2 and 3 even though 2 comes from their documentation. Clang warns 
on 2 and MSVC rejects 2

CC @aaron.ballman @rsmith 


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] D146399: [AIX][Clang][K] Create `-K` Option for AIX.

2023-04-05 Thread Michael Francis via Phabricator via cfe-commits
francii updated this revision to Diff 511208.
francii added a comment.

Add -c test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146399

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/aix-ld.c


Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -1077,3 +1077,27 @@
 // RUN:-fopenmp=libfoo \
 // RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP-FOO %s
 // CHECK-FOPENMP-FOO: error: unsupported argument 'libfoo' to option 
'-fopenmp='
+
+// Check powerpc-ibm-aix7.1.0.0. -K is a passthrough linker option.
+// RUN: %clang %s 2>&1 -### \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:-K \
+// RUN:   | FileCheck --check-prefixes=CHECK-K %s
+// CHECK-K: "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-K: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-K: "{{.*}}ld{{(.exe)?}}"
+// CHECK-K: "[[SYSROOT]]/usr/lib{{/|}}crt0.o"
+// CHECK-K: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
+// CHECK-K: "-K"
+
+// Check powerpc-ibm-aix7.1.0.0. -K unused when not linking.
+// RUN: %clang %s 2>&1 -### \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:-K \
+// RUN:-c \
+// RUN:   | FileCheck --check-prefixes=CHECK-K-UNUSED %s
+// CHECK-K-UNUSED: clang: warning: -K: 'linker' input unused 
[-Wunused-command-line-argument]
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6328,6 +6328,10 @@
 }
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_K); A && !TC.getTriple().isOSAIX())
+D.Diag(diag::err_drv_unsupported_opt_for_target)
+<< A->getAsString(Args) << TripleStr;
+
   if (Args.getLastArg(options::OPT_fapple_kext) ||
   (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))
 CmdArgs.push_back("-fapple-kext");
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3405,6 +3405,7 @@
   HelpText<"Overlay the virtual filesystem described by file over the real 
file system. "
"Additionally, pass this overlay file to the linker if it supports 
it">;
 def imultilib : Separate<["-"], "imultilib">, Group;
+def K : Flag<["-"], "K">, Flags<[LinkerInput]>;
 def keep__private__externs : Flag<["-"], "keep_private_externs">;
 def l : JoinedOrSeparate<["-"], "l">, Flags<[LinkerInput, RenderJoined]>,
 Group;


Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -1077,3 +1077,27 @@
 // RUN:-fopenmp=libfoo \
 // RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP-FOO %s
 // CHECK-FOPENMP-FOO: error: unsupported argument 'libfoo' to option '-fopenmp='
+
+// Check powerpc-ibm-aix7.1.0.0. -K is a passthrough linker option.
+// RUN: %clang %s 2>&1 -### \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:-K \
+// RUN:   | FileCheck --check-prefixes=CHECK-K %s
+// CHECK-K: "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-K: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-K: "{{.*}}ld{{(.exe)?}}"
+// CHECK-K: "[[SYSROOT]]/usr/lib{{/|}}crt0.o"
+// CHECK-K: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
+// CHECK-K: "-K"
+
+// Check powerpc-ibm-aix7.1.0.0. -K unused when not linking.
+// RUN: %clang %s 2>&1 -### \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:-K \
+// RUN:-c \
+// RUN:   | FileCheck --check-prefixes=CHECK-K-UNUSED %s
+// CHECK-K-UNUSED: clang: warning: -K: 'linker' input unused [-Wunused-command-line-argument]
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6328,6 +6328,10 @@
 }
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_K); A && !TC.getTriple().isOSAIX())
+D.Diag(diag::err_drv_unsupported_opt_for_target)
+<< A->getAsString(Args) << TripleStr;
+
   if (Args.getLastArg(options::OPT_fapple_kext) ||
   (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))
 CmdArgs.push_back("-fapple-kext");
Index: clang/include/clang/Driver/Options.td
===

[PATCH] D147661: [Sema] Tweak merging of availability attributes

2023-04-05 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm created this revision.
rsandifo-arm added reviewers: arphaman, erichkeane.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
rsandifo-arm requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Two calls to mergeAvailabilityAttr dropped the original
AttributeCommonInfo and created a new one from just the range.
This new attribute would have a 0 kind (rather than AT_Availability)
and a 0 syntax (GNU).  I don't have any proof that this makes a
difference in practice.

Noticed while doing some changes to the attribute handling.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147661

Files:
  clang/lib/Sema/SemaDeclAttr.cpp


Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2775,7 +2775,7 @@
 return V;
   };
   AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
-  ND, AL.getRange(), NewII, true /*Implicit*/,
+  ND, AL, NewII, true /*Implicit*/,
   MinMacCatalystVersion(Introduced.Version),
   MinMacCatalystVersion(Deprecated.Version),
   MinMacCatalystVersion(Obsoleted.Version), IsUnavailable, Str,
@@ -2817,7 +2817,7 @@
 return V ? *V : VersionTuple();
   };
   AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
-  ND, AL.getRange(), NewII, true /*Implicit*/,
+  ND, AL, NewII, true /*Implicit*/,
   VersionOrEmptyVersion(NewIntroduced),
   VersionOrEmptyVersion(NewDeprecated),
   VersionOrEmptyVersion(NewObsoleted), /*IsUnavailable=*/false, 
Str,


Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2775,7 +2775,7 @@
 return V;
   };
   AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
-  ND, AL.getRange(), NewII, true /*Implicit*/,
+  ND, AL, NewII, true /*Implicit*/,
   MinMacCatalystVersion(Introduced.Version),
   MinMacCatalystVersion(Deprecated.Version),
   MinMacCatalystVersion(Obsoleted.Version), IsUnavailable, Str,
@@ -2817,7 +2817,7 @@
 return V ? *V : VersionTuple();
   };
   AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
-  ND, AL.getRange(), NewII, true /*Implicit*/,
+  ND, AL, NewII, true /*Implicit*/,
   VersionOrEmptyVersion(NewIntroduced),
   VersionOrEmptyVersion(NewDeprecated),
   VersionOrEmptyVersion(NewObsoleted), /*IsUnavailable=*/false, Str,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146463: [CodeGen][RISCV] Change Shadow Call Stack Register to X3

2023-04-05 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth added a comment.

@asb, @craig.topper, @jrtc27  Are there any remaining considerations for us 
here? From the discussions in psABI and sig-toolchain, I think we have a 
consensus that this is the approach we'll be taking for RISC-V. We'd prefer to 
correct this ASAP, so as to prevent future incompatibility/continuing to use a 
non-standard register.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146463

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


[clang] 5c614bd - [clang-format] Fix bugs with "LambdaBodyIndentation: OuterScope"

2023-04-05 Thread Owen Pan via cfe-commits

Author: Jon Phillips
Date: 2023-04-05T14:38:38-07:00
New Revision: 5c614bd88f1252927ca1f9d9f8e802ef5e1eebe2

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

LOG: [clang-format] Fix bugs with "LambdaBodyIndentation: OuterScope"

The previous implementation of the option corrupted the parenthesis
state stack. (See https://reviews.llvm.org/D102706.)

Fixes #55708.
Fixes #53212.
Fixes #52846.
Fixes #59954.

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 527bdff5f5b56..f8ab42f46ba81 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3540,11 +3540,7 @@ the configuration (without a prefix: ``Auto``).
   causes the lambda body to be indented one additional level relative to
   the indentation level of the signature. ``OuterScope`` forces the lambda
   body to be indented one additional level relative to the parent scope
-  containing the lambda signature. For callback-heavy code, it may improve
-  readability to have the signature indented two levels and to use
-  ``OuterScope``. The KJ style guide requires ``OuterScope``.
-  `KJ style guide
-  `_
+  containing the lambda signature.
 
   Possible values:
 
@@ -3569,6 +3565,11 @@ the configuration (without a prefix: ``Auto``).
  return;
});
 
+   someMethod(someOtherMethod(
+   [](SomeReallyLongLambdaSignatureArgument foo) {
+ return;
+   }));
+
 
 
 .. _Language:

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 03d14fc89be4c..c07f23af4a629 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -427,6 +427,7 @@ clang-format
   put the initializers on the next line only.
 - Add additional Qualifier Ordering support for special cases such
   as templates, requires clauses, long qualified names.
+- Fix all known issues associated with ``LambdaBodyIndentation: OuterScope``.
 
 libclang
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 755621ec53d63..0dfa052822458 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2670,6 +2670,11 @@ struct FormatStyle {
 ///[](SomeReallyLongLambdaSignatureArgument foo) {
 ///  return;
 ///});
+///
+///someMethod(someOtherMethod(
+///[](SomeReallyLongLambdaSignatureArgument foo) {
+///  return;
+///}));
 /// \endcode
 LBI_OuterScope,
   };
@@ -2678,11 +2683,7 @@ struct FormatStyle {
   /// causes the lambda body to be indented one additional level relative to
   /// the indentation level of the signature. ``OuterScope`` forces the lambda
   /// body to be indented one additional level relative to the parent scope
-  /// containing the lambda signature. For callback-heavy code, it may improve
-  /// readability to have the signature indented two levels and to use
-  /// ``OuterScope``. The KJ style guide requires ``OuterScope``.
-  /// `KJ style guide
-  /// `_
+  /// containing the lambda signature.
   /// \version 13
   LambdaBodyIndentationKind LambdaBodyIndentation;
 

diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 6b33ab0a76650..f5748cfc50890 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1125,8 +1125,14 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Style.IndentWidth;
   }
 
-  if (NextNonComment->is(tok::l_brace) && NextNonComment->is(BK_Block))
-return Current.NestingLevel == 0 ? State.FirstIndent : CurrentState.Indent;
+  if (NextNonComment->is(tok::l_brace) && NextNonComment->is(BK_Block)) {
+if (Current.NestingLevel == 0 ||
+(Style.LambdaBodyIndentation == FormatStyle::LBI_OuterScope &&
+ State.NextToken->is(TT_LambdaLBrace))) {
+  return State.FirstIndent;
+}
+return CurrentState.Indent;
+  }
   if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
(Current.is(tok::greater) &&
 (Style.Language == FormatStyle::LK_Proto ||
@@ -1830,6 +1836,10 @@ void 
ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
 }
 
 void ContinuationIndenter::moveState

[PATCH] D146042: [clang-format] Fix numerous issues with "LambdaBodyIndentation: OuterScope" option

2023-04-05 Thread Owen Pan 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 rG5c614bd88f12: [clang-format] Fix bugs with 
"LambdaBodyIndentation: OuterScope" (authored by jp4a50, committed by 
owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146042

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22009,9 +22009,9 @@
   verifyFormat("void test() {\n"
"  (\n"
"  []() -> auto {\n"
-   "int b = 32;\n"
-   "return 3;\n"
-   "  },\n"
+   "int b = 32;\n"
+   "return 3;\n"
+   "  },\n"
"  foo, bar)\n"
"  .foo();\n"
"}",
@@ -22025,17 +22025,82 @@
"  .bar();\n"
"}",
Style);
-  Style = getGoogleStyle();
-  Style.LambdaBodyIndentation = FormatStyle::LBI_OuterScope;
-  verifyFormat("#define A   \\\n"
-   "  [] {  \\\n"
-   "xxx(\\\n"
-   "x); \\\n"
-   "  }",
-   Style);
-  // TODO: The current formatting has a minor issue that's not worth fixing
-  // right now whereby the closing brace is indented relative to the signature
-  // instead of being aligned. This only happens with macros.
+  verifyFormat("#define A  \\\n"
+   "  [] { \\\n"
+   "xxx(   \\\n"
+   "x);\\\n"
+   "  }",
+   Style);
+  verifyFormat("void foo() {\n"
+   "  aFunction(1, b(c(foo, bar, baz, [](d) {\n"
+   "auto f = e(d);\n"
+   "return f;\n"
+   "  })));\n"
+   "}",
+   Style);
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  verifyFormat("void foo() {\n"
+   "  aFunction(\n"
+   "  1, b(c(\n"
+   " [](d) -> Foo {\n"
+   "auto f = e(d);\n"
+   "return f;\n"
+   "  },\n"
+   " foo, Bar{},\n"
+   " [] {\n"
+   "auto g = h();\n"
+   "return g;\n"
+   "  },\n"
+   " baz)));\n"
+   "}",
+   Style);
+  verifyFormat("void foo() {\n"
+   "  aFunction(1, b(c(foo, Bar{}, baz, [](d) -> Foo {\n"
+   "auto f = e(\n"
+   "foo,\n"
+   "[&] {\n"
+   "  auto g = h();\n"
+   "  return g;\n"
+   "},\n"
+   "qux,\n"
+   "[&] -> Bar {\n"
+   "  auto i = j();\n"
+   "  return i;\n"
+   "});\n"
+   "return f;\n"
+   "  })));\n"
+   "}",
+   Style);
+  verifyFormat("Namespace::Foo::Foo(\n"
+   "LongClassName bar, AnotherLongClassName baz)\n"
+   ": baz{baz}, func{[&] {\n"
+   "  auto qux = bar;\n"
+   "  return aFunkyFunctionCall(qux);\n"
+   "}} {}",
+   Style);
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.BeforeLambdaBody = true;
+  verifyFormat("void foo() {\n"
+   "  aFunction(\n"
+   "  1, b(c(foo, Bar{}, baz,\n"
+   " [](d) -> Foo\n"
+   "  {\n"
+   "auto f = e(\n"
+   "[&]\n"
+   "{\n"
+   "  auto g = h();\n"
+   "  return g;\n"
+   "},\n"
+   "qux,\n"
+   "[&] -> Bar\n"
+   "{\n"
+   "  auto i = j();\n"
+   "  return i;\n"
+   "});\n"
+   "return f;\n"
+   "  })));\n"
+   "}",
+   Style);
 }
 
 TEST_F(FormatTest, LambdaWithLineComments) {
Index: clang/lib/Format/UnwrappedLineFormatte

[PATCH] D147580: [Clang] Refactor "Designators" to be more similar [NFC]

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

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147580

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Sema/Designator.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Parse/ParseInit.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp

Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -1098,13 +1098,13 @@
   Record.AddSourceLocation(D.getFieldLoc());
 } else if (D.isArrayDesignator()) {
   Record.push_back(serialization::DESIG_ARRAY);
-  Record.push_back(D.getFirstExprIndex());
+  Record.push_back(D.getArrayIndex());
   Record.AddSourceLocation(D.getLBracketLoc());
   Record.AddSourceLocation(D.getRBracketLoc());
 } else {
   assert(D.isArrayRangeDesignator() && "Unknown designator");
   Record.push_back(serialization::DESIG_ARRAY_RANGE);
-  Record.push_back(D.getFirstExprIndex());
+  Record.push_back(D.getArrayIndex());
   Record.AddSourceLocation(D.getLBracketLoc());
   Record.AddSourceLocation(D.getEllipsisLoc());
   Record.AddSourceLocation(D.getRBracketLoc());
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -1216,8 +1216,8 @@
   auto *Field = readDeclAs();
   SourceLocation DotLoc = readSourceLocation();
   SourceLocation FieldLoc = readSourceLocation();
-  Designators.push_back(Designator(Field->getIdentifier(), DotLoc,
-   FieldLoc));
+  Designators.push_back(Designator::CreateFieldDesignator(
+  Field->getIdentifier(), DotLoc, FieldLoc));
   Designators.back().setField(Field);
   break;
 }
@@ -1226,7 +1226,8 @@
   const IdentifierInfo *Name = Record.readIdentifier();
   SourceLocation DotLoc = readSourceLocation();
   SourceLocation FieldLoc = readSourceLocation();
-  Designators.push_back(Designator(Name, DotLoc, FieldLoc));
+  Designators.push_back(Designator::CreateFieldDesignator(Name, DotLoc,
+  FieldLoc));
   break;
 }
 
@@ -1234,7 +1235,9 @@
   unsigned Index = Record.readInt();
   SourceLocation LBracketLoc = readSourceLocation();
   SourceLocation RBracketLoc = readSourceLocation();
-  Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc));
+  Designators.push_back(Designator::CreateArrayDesignator(Index,
+  LBracketLoc,
+  RBracketLoc));
   break;
 }
 
@@ -1243,8 +1246,8 @@
   SourceLocation LBracketLoc = readSourceLocation();
   SourceLocation EllipsisLoc = readSourceLocation();
   SourceLocation RBracketLoc = readSourceLocation();
-  Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc,
-   RBracketLoc));
+  Designators.push_back(Designator::CreateArrayRangeDesignator(
+  Index, LBracketLoc, EllipsisLoc, RBracketLoc));
   break;
 }
 }
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -11661,9 +11661,8 @@
   bool ExprChanged = false;
   for (const DesignatedInitExpr::Designator &D : E->designators()) {
 if (D.isFieldDesignator()) {
-  Desig.AddDesignator(Designator::getField(D.getFieldName(),
-   D.getDotLoc(),
-   D.getFieldLoc()));
+  Desig.AddDesignator(Designator::CreateFieldDesignator(
+  D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
   if (D.getField()) {
 FieldDecl *Field = cast_or_null(
 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
@@ -11686,7 +11685,7 @@
 return ExprError();
 
   Desig.AddDesignator(
-  Designator::getArray(Index.get(), D.getLBracketLoc()));
+  Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
 
   ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
   ArrayExprs.push_back(Index.get());
@@ -11703,10 +11702,8 @@
 if (End.isInvalid())
   return ExprError();
 
-Desig.AddDesignator(Designator::getArrayRange(Start.get(),
- 

cfe-commits@lists.llvm.org

2023-04-05 Thread Ziqing Luo via cfe-commits

Author: Ziqing Luo
Date: 2023-04-05T14:54:03-07:00
New Revision: ca6ceeb0d6cd5b8545410d878c8d7bcce9538a3a

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

LOG: Reland "[-Wunsafe-buffer-usage] Fix-Its transforming `&DRE[any]` to 
`&DRE.data()[any]`"

This commit relands 87b5807d3802b932c06d83c4287014872aa2caab, where a
test fails on a few specific targets.  Now hard-code a target
for the test.

Added: 

clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-addressof-arraysubscript.cpp

Modified: 
clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
clang/lib/Analysis/UnsafeBufferUsage.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index 8957ab664ed93..f78cf2c57689c 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -43,7 +43,7 @@ class UnsafeBufferUsageHandler {
 
   /// Returns the text indicating that the user needs to provide input there:
   virtual std::string
-  getUserFillPlaceHolder(StringRef HintTextToUser = "placeholder") {
+  getUserFillPlaceHolder(StringRef HintTextToUser = "placeholder") const {
 std::string s = std::string("<# ");
 s += HintTextToUser;
 s += " #>";

diff  --git 
a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
index a8485682c1d1f..f0c99a767071f 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
@@ -30,9 +30,10 @@ WARNING_GADGET(Decrement)
 WARNING_GADGET(ArraySubscript)
 WARNING_GADGET(PointerArithmetic)
 WARNING_GADGET(UnsafeBufferUsageAttr)
-FIXABLE_GADGET(ULCArraySubscript)
+FIXABLE_GADGET(ULCArraySubscript)  // `DRE[any]` in an Unspecified 
Lvalue Context
 FIXABLE_GADGET(DerefSimplePtrArithFixable)
 FIXABLE_GADGET(PointerDereference)
+FIXABLE_GADGET(UPCAddressofArraySubscript) // '&DRE[any]' in an Unspecified 
Pointer Context
 
 #undef FIXABLE_GADGET
 #undef WARNING_GADGET

diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 4a8358af68ec5..1ef276ab90444 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -15,6 +15,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include 
 #include 
+#include 
 
 using namespace llvm;
 using namespace clang;
@@ -112,6 +113,15 @@ class MatchDescendantVisitor
   bool Matches;
 };
 
+// Because we're dealing with raw pointers, let's define what we mean by that.
+static auto hasPointerType() {
+return hasType(hasCanonicalType(pointerType()));
+}
+
+static auto hasArrayType() {
+return hasType(hasCanonicalType(arrayType()));
+}
+  
 AST_MATCHER_P(Stmt, forEveryDescendant, internal::Matcher, innerMatcher) 
{
   const DynTypedMatcher &DTM = static_cast(innerMatcher);
 
@@ -145,6 +155,30 @@ static auto 
isInUnspecifiedLvalueContext(internal::Matcher innerMatcher) {
 ));
 // clang-format off
 }
+
+
+// Returns a matcher that matches any expression `e` such that `InnerMatcher`
+// matches `e` and `e` is in an Unspecified Pointer Context (UPC).
+static internal::Matcher
+isInUnspecifiedPointerContext(internal::Matcher InnerMatcher) {
+  // A UPC can be
+  // 1. an argument of a function call (except the callee has [[unsafe_...]]
+  // attribute), or
+  // 2. the operand of a cast operation; or
+  // ...
+  auto CallArgMatcher =
+  callExpr(hasAnyArgument(allOf(
+   hasPointerType() /* array also decays to pointer type*/,
+   InnerMatcher)),
+   unless(callee(functionDecl(hasAttr(attr::UnsafeBufferUsage);
+  auto CastOperandMatcher =
+  explicitCastExpr(hasCastKind(CastKind::CK_PointerToIntegral),
+   castSubExpr(allOf(hasPointerType(), InnerMatcher)));
+
+ return stmt(anyOf(CallArgMatcher, CastOperandMatcher));
+  // FIXME: any more cases? (UPC excludes the RHS of an assignment.  For now we
+  // don't have to check that.)
+}
 } // namespace clang::ast_matchers
 
 namespace {
@@ -159,15 +193,6 @@ using FixItList = SmallVector;
 class Strategy;
 } // namespace
 
-// Because we're dealing with raw pointers, let's define what we mean by that.
-static auto hasPointerType() {
-return hasType(hasCanonicalType(pointerType()));
-}
-
-static auto hasArrayType() {
-return hasType(hasCanonicalType(arrayType()));
-}
-
 namespace {
 /// Gadget is an individual operation in the code that may be of interest to
 /// this analysis. Each (non-abstract) subclass corresponds to a 

  1   2   >