[PATCH] D95168: [clang-format] Add InsertBraces option

2021-10-04 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D95168#3039033 , @owenpan wrote:

> In D95168#3038531 , @MyDeveloperDay 
> wrote:
>
>> @tiagoma are you still interested in pursuing this? I have some suggestions
>>
>> 1. I'd like to move the BraceInserter Into its own .cpp and .h files (like I 
>> did with the QualifierAlignmentFixer)
>> 2. I'd like to move the unit tests into their own .cpp file  (because I 
>> think we need to actually unit tests their functions of BraceInserter more 
>> than just testing if via verfiyFormat and I think its cleaner as 
>> FormatTest.cpp is very large)
>> 3. I'd like to see what it would take to remove braces, (eliding the braces 
>> on small ifs and control statements is about the number one review comments 
>> in LLVM)
>
> Eliding braces would be much more complicated and should be tackled 
> separately. Below are just some examples:
>
>   

I agree with that, to be honest I work in an organization where we'd only ever 
be inserting them, but I think anyone conforming to LLVM style could appreciate 
a removal option, but yes lets do that separately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95168

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-10-04 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki added a comment.

In D110618#3032899 , @Anastasia wrote:

> Considering that SPIR-V translation step is also required for other languages 
> would it make sense to add `llvm-spirv` as a common tool like for example 
> C/C++ linkers and create a bit of common infrastructure? It might be 
> something we can do as a separate step too but it would be good to make sure 
> nothing prevents us from doing this in the future... We should probably also 
> think about the command line interface unification as it probably doesn't 
> make sense for every language to add their own flags for locating SPIR-V 
> translator.

I don’t think it would work out well. llvm-spirv (or other tool relying on LLVM 
bitcode input) and LLVM may have version differences that cause obscure error 
cases - like newer LLVM producing bitcode with new features the tools are not 
expecting and ready for them. The usage of llvm-spirv tool in the HIPSPV tool 
chain is not intended to be a longer term solution due to this shortcoming.

> Another question I have is whether `--hipspv-pass-plugin` would be needed 
> when we switch to SPIR-V backend or is this something that would be 
> integrated fully upstream eventually. Then we might need to think more of the 
> suitable transition path.

It’s too early to say if we can integrate --hipspv-pass-plugin fully in the 
future. It would be the preferred outcome. We are not finished with the HIP 
expanders we need for supporting various HIP features so we don’t know for 
certain what will be the outcome for the integration. It’s possible that some 
of the solutions are going to be tightly coupled with runtimes (HIPLZ, HIPCL) 
and others that may not generalize for different SPIR-V execution environments.




Comment at: clang/include/clang/Driver/Options.td:3701
   " do not include the default CUDA/HIP wrapper headers">;
+def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">,
+  HelpText<"Do not include the default HIP wrapper headers">;

tra wrote:
> Is the idea to still add relevant include paths to the wrappers and SDK 
> headers, but not `-include` the wrapper?
> 
> If that's the case, it should probably be generalized into `-nogpuwrapperinc` 
> and apply to both CUDA and HIP.
> 
> Is the idea to still add relevant include paths to the wrappers and SDK 
> headers, but not `-include` the wrapper?
> 
Include paths are meant to be excluded too. I’ll fix the option description.

> If that's the case, it should probably be generalized into `-nogpuwrapperinc` 
> and apply to both CUDA and HIP.
> 
I don’t see an immediate need to generalize the option as I don’t think there 
will be a need for it in the CUDA path. The option could be generalized later 
if the need comes (add generalized option, set -nohipwrapperinc to be alias to 
it).



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110618

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


[PATCH] D110622: [HIPSPV][3/4] Enable SPIR-V emission for HIP

2021-10-04 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki added a comment.

In D110622#3030792 , @tra wrote:

>> A Cuda GPU architecture ‘generic’ is added. The name is picked from the LLVM 
>> SPIR-V Backend. In the HIPSPV code path the architecture name is inserted to 
>> the bundle entry ID as target ID. Target ID is expected to be always present 
>> so a component in the target triple is not mistaken as target ID.
>
> How generic is 'generic'? If I understand the statement above correctly, it 
> should probably reflect that it's specific to spir-v.
> If it's the only possible spir-v variant, then calling it`spir-v` might be 
> more meaningful.
> If we expect to see other spir-v variants in the future it would allow us to 
> clearly differentiate between them later. 
> E.g. `--offload=spirv-a,spirv-b`. It would be rather odd if we had to use 
> `--offload=generic, spirv-b`.

In this patch the ‘generic’ is meant to be a processor model defined in the 
SPIR-V backend. Now to come to think of it a bit more, I think it should not be 
specific to the SPIR-V target but the target at hand if its backend defines 
one. What I’m seeing is that each entry in the CudaArch has a processor by the 
same name in the NVPTX and AMGPU backends.

If I need to set different processor other from the SPIR-V backend than what is 
set as the default in HIP compilation, I thought from the [1] it could be 
carried out with something like:

  --offload=spirv64 -Xoffload=spirv64 -march=other-spirv-cpu

[1]: https://lists.llvm.org/pipermail/cfe-dev/2020-December/067362.html

In D110622#3031010 , @tra wrote:

>> --offload’ option, which is envisioned in [1], is added for specifying 
>> offload targets. This option is used to override default device target 
>> (amdgcn-amd-amdhsa) for HIP compilation for emitting device code as SPIR-V 
>> binary. The option is handled in getHIPOffloadTargetTriple().
>
> Can you elaborate on what exactly this option does and how it's intended to 
> interact with the existing `--offload-arch`?

I think that the --offload-arch interaction question is for @yaxunl. What is 
being contributed here is a partial implementation for the unified offloading 
options. The --offload option in this patch is used to supply the offload 
device target triple (in HIP compilation mode) for retargeting the device code 
emission to SPIR-V instead of emitting HSA.

> In general a list of values, combined with the `getLastArg` will potentially 
> be an issue if/when more than one list value will be supported.
> In a large build it's fairly common for the build infrastructure to set the 
> default options and allowing users to extend/override them with *additional* 
> options. `getLastArg` works great for scalar options, not so much for the 
> lists.
> If an option is a list, modifying it requires prior knowledge of preceding 
> values and that may not always be easy.
> E.g. a build configuration may be set to  target gfx900 and gfx908. If I want 
> to *add* an option to target gfx1030, I would need to dig out the options for 
> the currently-enabled architectures and specify all of them again. It's 
> doable once, manually, but it does not scale if this option is expected to be 
> regularly tweaked by the end user, as is the case with `--offload-arch`. If 
> `--offload` is expected to have similar use patterns, you may need to 
> consider allowing it to be adjusted per-list-element.

The use of getLastArg() is an oversight. I’ll fix it with getAllArgValues().




Comment at: clang/include/clang/Basic/Cuda.h:106
 static inline bool IsAMDGpuArch(CudaArch A) {
   return A >= CudaArch::GFX600 && A < CudaArch::LAST;
 }

tra wrote:
> Does this need to be adjusted to exclude SPIR-V? If so, you may want to add 
> another enum range for SPIR-V.
> 
Didn't notice this. I'll fix this.



Comment at: clang/include/clang/Driver/Options.td:1136
+def offload_EQ : CommaJoined<["--"], "offload=">, Flags<[NoXarchOption]>,
+  HelpText<"Specify comma-separated list of offloading targets.">;
+

tra wrote:
> `comma-separated list of offloading targets.` is, unfortunately, somewhat 
> ambiguous.
> Does it mean "how the offload will be done". I.e. HSA, OpenMP, SPIRV, CUDA? 
> Or does it mean specific hardware we need to generate the code for? 
> The code suggests it's a variant of the former, but the option description 
> does not. 
> 
> E.g. `offload_arch_EQ ` also uses the term "offloading target" but with a 
> different meaning.
> 
I’m not sure how to rephrase the option description to be more clear. In the 
[1] the `--offload` option is envisioned to be quite flexible/expressive - it 
can take in target triples, offload kinds, processors, aliases for processor 
sets, etc.

FYI, I have imagined that the `--offload` option would take in explicit offload 
kind and target triple combinations as the basis. For example, something like 
this:


```
--offl

[clang-tools-extra] d933ade - [APInt] Stop using soft-deprecated constructors and methods in clang. NFC.

2021-10-04 Thread Jay Foad via cfe-commits

Author: Jay Foad
Date: 2021-10-04T09:38:11+01:00
New Revision: d933adeaca7b9c2aa27e7ca35f7dd4ccc6b5985d

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

LOG: [APInt] Stop using soft-deprecated constructors and methods in clang. NFC.

Stop using APInt constructors and methods that were soft-deprecated in
D109483. This fixes all the uses I found in clang.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/OpenMPClause.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/Lex/LiteralSupport.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/StaticAnalyzer/Core/MemRegion.cpp
clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
index 6b23f7cd4a9c8..beca3933bcd23 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -165,7 +165,7 @@ void StringConstructorCheck::check(const 
MatchFinder::MatchResult &Result) {
 Expr::EvalResult ConstPtr;
 if (!Ptr->isInstantiationDependent() &&
 Ptr->EvaluateAsRValue(ConstPtr, Ctx) &&
-((ConstPtr.Val.isInt() && ConstPtr.Val.getInt().isNullValue()) ||
+((ConstPtr.Val.isInt() && ConstPtr.Val.getInt().isZero()) ||
  (ConstPtr.Val.isLValue() && ConstPtr.Val.isNullPointer( {
   diag(Loc, "constructing string from nullptr is undefined behaviour");
 }

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 0ac36708f0774..3cfbfb670403b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2757,8 +2757,8 @@ static bool handleIntIntBinOp(EvalInfo &Info, const Expr 
*E, const APSInt &LHS,
 Result = (Opcode == BO_Rem ? LHS % RHS : LHS / RHS);
 // Check for overflow case: INT_MIN / -1 or INT_MIN % -1. APSInt supports
 // this operation and gives the two's complement result.
-if (RHS.isNegative() && RHS.isAllOnesValue() &&
-LHS.isSigned() && LHS.isMinSignedValue())
+if (RHS.isNegative() && RHS.isAllOnes() && LHS.isSigned() &&
+LHS.isMinSignedValue())
   return HandleOverflow(Info, E, -LHS.extend(LHS.getBitWidth() + 1),
 E->getType());
 return true;
@@ -15324,7 +15324,7 @@ static ICEDiag CheckICE(const Expr* E, const ASTContext 
&Ctx) {
   llvm::APSInt REval = Exp->getRHS()->EvaluateKnownConstInt(Ctx);
   if (REval == 0)
 return ICEDiag(IK_ICEIfUnevaluated, E->getBeginLoc());
-  if (REval.isSigned() && REval.isAllOnesValue()) {
+  if (REval.isSigned() && REval.isAllOnes()) {
 llvm::APSInt LEval = Exp->getLHS()->EvaluateKnownConstInt(Ctx);
 if (LEval.isMinSignedValue())
   return ICEDiag(IK_ICEIfUnevaluated, E->getBeginLoc());

diff  --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index caf938a5b9582..176c040727831 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -2313,9 +2313,8 @@ void OMPTraitInfo::getAsVariantMatchInfo(ASTContext 
&ASTCtx,
 
 if (Optional CondVal =
 Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx))
-  VMI.addTrait(CondVal->isNullValue()
-   ? TraitProperty::user_condition_false
-   : TraitProperty::user_condition_true,
+  VMI.addTrait(CondVal->isZero() ? TraitProperty::user_condition_false
+ : TraitProperty::user_condition_true,
"");
 else
   VMI.addTrait(TraitProperty::user_condition_false, "");

diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 6bef004987828..ed485ed6f5d15 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1647,7 +1647,7 @@ Value 
*ScalarExprEmitter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
   for (unsigned i = 2; i < E->getNumSubExprs(); ++i) {
 llvm::APSInt Idx = E->getShuffleMaskIdx(CGF.getContext(), i-2);
 // Check for -1 and output it as undef in the IR.
-if (Idx.isSigned() && Idx.isAllOnesValue())
+if (Idx.isSigned() && Idx.isAllOnes())
   Indices.push_back(-1);
 else
   Indices.push_back(Idx.getZExtValue());

diff  --git a/clang/lib/Lex/LiteralSupport.cpp 
b/clang/lib/Lex/LiteralSup

[PATCH] D110808: [APInt] Stop using soft-deprecated constructors and methods in clang. NFC.

2021-10-04 Thread Jay Foad 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 rGd933adeaca7b: [APInt] Stop using soft-deprecated 
constructors and methods in clang. NFC. (authored by foad).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110808

Files:
  clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -128,14 +128,14 @@
 // a&0 and a&(~0)
 if (RHS == 0)
   return makeIntVal(0, resultTy);
-else if (RHS.isAllOnesValue())
+else if (RHS.isAllOnes())
   isIdempotent = true;
 break;
   case BO_Or:
 // a|0 and a|(~0)
 if (RHS == 0)
   isIdempotent = true;
-else if (RHS.isAllOnesValue()) {
+else if (RHS.isAllOnes()) {
   const llvm::APSInt &Result = BasicVals.Convert(resultTy, RHS);
   return nonloc::ConcreteInt(Result);
 }
@@ -509,7 +509,7 @@
 continue;
   case BO_Shr:
 // (~0)>>a
-if (LHSValue.isAllOnesValue() && LHSValue.isSigned())
+if (LHSValue.isAllOnes() && LHSValue.isSigned())
   return evalCast(lhs, resultTy, QualType{});
 LLVM_FALLTHROUGH;
   case BO_Shl:
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1568,7 +1568,7 @@
 assert(!Constraint.isEmpty() && "Empty ranges shouldn't get here");
 
 if (Constraint.getConcreteValue())
-  return !Constraint.getConcreteValue()->isNullValue();
+  return !Constraint.getConcreteValue()->isZero();
 
 APSIntType T{Constraint.getMinValue()};
 Const Zero = T.getZeroValue();
Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -794,7 +794,7 @@
 
 const AnalyzerOptions &Opts = SVB.getAnalyzerOptions();
 if (Opts.ShouldConsiderSingleElementArraysAsFlexibleArrayMembers &&
-Size.isOneValue())
+Size.isOne())
   return true;
   }
   return false;
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -18895,7 +18895,7 @@
   Expr::EvalResult ResultL;
   if (!OASE->getLength()->isValueDependent() &&
   OASE->getLength()->EvaluateAsInt(ResultR, SemaRef.getASTContext()) &&
-  !ResultR.Val.getInt().isOneValue()) {
+  !ResultR.Val.getInt().isOne()) {
 SemaRef.Diag(OASE->getLength()->getExprLoc(),
  diag::err_omp_invalid_map_this_expr);
 SemaRef.Diag(OASE->getLength()->getExprLoc(),
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -3813,7 +3813,7 @@
 
 llvm::APInt Val(bit_width, 0, isSigned);
 bool Overflowed = Literal.GetFixedPointValue(Val, scale);
-bool ValIsZero = Val.isNullValue() && !Overflowed;
+bool ValIsZero = Val.isZero() && !Overflowed;
 
 auto MaxVal = Context.getFixedPointMax(Ty).getValue();
 if (Literal.isFract && Val == MaxVal + 1 && !ValIsZero)
@@ -5254,7 +5254,7 @@
   // OpenMP 5.0, 2.1.6 Iterators, Restrictions
   // If the step expression of a range-specification equals zero, the
   // behavior is unspecified.
-  if (Result && Result->isNullValue()) {
+  if (Result && Result->isZero()) {
 Diag(Step->getExprLoc(), diag::err_omp_iterator_step_constant_zero)
 << Step << Step->getSourceRange();
 IsCorrect = false;
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1729,7 +1729,7 @@
 // value so we bail out.
 if (SizeOp->isValueDependent())
   break;
-if (!SizeOp->EvaluateKnownConstInt(Context).isNullValue()) {
+if (!SizeOp->EvaluateKnownConstInt(Context).isZero()) {
   CheckNonNullArgument(*th

[PATCH] D111039: [clangd] Include refs of base method in refs for derived method.

2021-10-04 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/XRefs.cpp:1395
   if (CMD->isVirtual())
-if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) ==
-  IdentifierAtCursor->location()) {

it's important to note that this doesn't only suppress xrefs behaviour outside 
of the declaration, but it also suppresses xrefs on parts of the declaration 
apart from the function's name (like override/virtual keywords). it's 
unfortunate that we don't have tests to explicitly point out that fact.
I am not sure why the decision was to exclude them in the first place, I am 
definitely in favor of the new behaviour (we already provide go-to-def on 
`override` keyword for example, not having xrefs on it seems surprising). I 
suppose @hokein can tell if there are any other concerns I am missing.



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:1993
 public:
   void $decl[[fu^nc]]() override;
 };

can we instead turn this test into a multi point check? (e.g. check that 
references in `virt^ual void fu^nc() over^ride;` ... `D->fu^nc();` are all the 
same?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111039

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-10-04 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki updated this revision to Diff 376822.
linjamaki added a comment.

Update option description.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110618

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h

Index: clang/lib/Driver/ToolChains/HIPSPV.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.h
@@ -0,0 +1,99 @@
+//===--- HIPSPV.h - HIP ToolChain Implementations ---*- C++ -*-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace HIPSPV {
+
+// Runs llvm-link/opt/llc/lld, which links multiple LLVM bitcode, together with
+// device library, then compiles it to SPIR-V in a shared object.
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain &TC) : Tool("HIPSPV::Linker", "hipspv-link", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation &C, const JobAction &JA,
+const InputInfo &Output, const InputInfoList &Inputs,
+const llvm::opt::ArgList &TCArgs,
+const char *LinkingOutput) const override;
+
+private:
+  void constructEmitSpirvCommand(Compilation &C, const JobAction &JA,
+ const InputInfoList &Inputs,
+ const InputInfo &Output,
+ const llvm::opt::ArgList &Args) const;
+};
+
+} // namespace HIPSPV
+} // namespace tools
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
+public:
+  HIPSPVToolChain(const Driver &D, const llvm::Triple &Triple,
+  const ToolChain &HostTC, const llvm::opt::ArgList &Args);
+
+  const llvm::Triple *getAuxTriple() const override {
+return &HostTC.getTriple();
+  }
+
+  void
+  addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const override;
+  void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
+  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList &Args,
+  llvm::opt::ArgStringList &CC1Args) const override;
+  void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+   llvm::opt::ArgStringList &CC1Args) const override;
+  void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args) const override;
+  llvm::SmallVector
+  getHIPDeviceLibs(const llvm::opt::ArgList &Args) const override;
+
+  SanitizerMask getSupportedSanitizers() const override;
+
+  VersionTuple
+  computeMSVCVersion(const Driver *D,
+ const llvm::opt::ArgList &Args) const override;
+
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
+  bool useIntegratedAs() const override { return true; }
+  bool isCrossCompiling() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return false; }
+  bool isPICDefaultForced() const override { return false; }
+  bool SupportsProfiling() const override { return false; }
+
+  const ToolChain &HostTC;
+
+protected:
+  Tool *buildLinker() const override;
+};
+
+} // end namespace toolchains
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -0,0 +1,290 @@
+//===--- HIPSPV.cpp - HIPSPV ToolChain Implementation ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.

[PATCH] D110927: [analyzer] Access stored value of a constant array through a pointer to another type

2021-10-04 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 376823.
ASDenysPetrov added a comment.

Fixed a comment.


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

https://reviews.llvm.org/D110927

Files:
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/initialization.cpp

Index: clang/test/Analysis/initialization.cpp
===
--- clang/test/Analysis/initialization.cpp
+++ clang/test/Analysis/initialization.cpp
@@ -2,6 +2,10 @@
 
 void clang_analyzer_eval(int);
 
+namespace std {
+enum class byte : unsigned char {};
+};
+
 struct S {
   int a = 3;
 };
@@ -48,6 +52,46 @@
   auto x = ptr[idx]; // expected-warning{{garbage or undefined}}
 }
 
+void glob_cast_same() {
+  auto *ptr = (int *)glob_arr2;
+  auto x1 = ptr[0]; // no-warning
+  auto x2 = ptr[1]; // no-warning
+}
+
+void glob_cast_char() {
+  const auto *ptr = (char *)glob_arr2;
+  auto x1 = ptr[0]; // no-warning
+  auto x2 = ptr[1]; // expected-warning{{garbage or undefined}}
+}
+
+void glob_cast_uchar() {
+  auto *ptr = (unsigned char *)glob_arr2;
+  auto x1 = ptr[0]; // no-warning
+  auto x2 = ptr[1]; // expected-warning{{garbage or undefined}}
+}
+
+void glob_cast_byte() {
+  auto *ptr = (const std::byte *)glob_arr2;
+  auto x1 = ptr[0]; // no-warning
+  auto x2 = ptr[1]; // expected-warning{{garbage or undefined}}
+}
+
+void glob_cast_opposite_sign() {
+  auto *ptr = (unsigned int *)glob_arr2;
+  auto x1 = ptr[0]; // no-warning
+  auto x2 = ptr[1]; // expected-warning{{garbage or undefined}}
+}
+
+void glob_cast_invalid1() {
+  auto *ptr = (signed char *)glob_arr2;
+  auto x = ptr[0]; // expected-warning{{garbage or undefined}}
+}
+
+void glob_cast_invalid2() {
+  using T = short *;
+  auto x = ((T)glob_arr2)[0]; // expected-warning{{garbage or undefined}}
+}
+
 const float glob_arr3[] = {
 0., 0.0235, 0.0470, 0.0706, 0.0941, 0.1176};
 float no_warn_garbage_value() {
Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -437,6 +437,8 @@
 
   RegionBindingsRef removeSubRegionBindings(RegionBindingsConstRef B,
 const SubRegion *R);
+  bool canAccessStoredValue(QualType OrigT, QualType ThroughT,
+uint64_t Index) const;
 
 public: // Part of public interface to class.
 
@@ -1625,6 +1627,56 @@
   return Result;
 }
 
+/// Returns true if the stored value can be accessed through the pointer to
+/// another type:
+///  const int arr[42] = {};
+///  auto* pchar = (char*)arr;
+///  auto* punsigned = (unsigned int*)arr;
+///  auto* pshort= (short*)arr;
+///  auto x1 = pchar[0]; // valid
+///  auto x2 = pchar[1]; // invalid
+///  auto x3 = punsigned[0]; // valid
+///  auto x4 = pshort[0];// invalid
+bool RegionStoreManager::canAccessStoredValue(QualType OrigT, QualType ThroughT,
+  uint64_t Index) const {
+  // Remove cv-qualifiers.
+  OrigT = OrigT->getCanonicalTypeUnqualified();
+  ThroughT = ThroughT->getCanonicalTypeUnqualified();
+
+  // C++20 7.2.1.11 [basic.lval] (excerpt):
+  //  A program can access the stored value of an object through:
+  //  - the same type of the object;
+  //  - a signed or unsigned type corresponding to the type of the
+  //object;
+  //  - a char, unsigned char, std::byte. (NOTE:
+  //  Otherwise, the behavior is undefined.
+  return
+  // - is same
+  (OrigT == ThroughT) ||
+  // - is another sign
+  (((OrigT == Ctx.CharTy && ThroughT == Ctx.UnsignedCharTy) ||
+(OrigT == Ctx.SignedCharTy && ThroughT == Ctx.UnsignedCharTy) ||
+(OrigT == Ctx.ShortTy && ThroughT == Ctx.UnsignedShortTy) ||
+(OrigT == Ctx.IntTy && ThroughT == Ctx.UnsignedIntTy) ||
+(OrigT == Ctx.LongTy && ThroughT == Ctx.UnsignedLongTy) ||
+(OrigT == Ctx.LongLongTy && ThroughT == Ctx.UnsignedLongLongTy) ||
+(ThroughT == Ctx.CharTy && OrigT == Ctx.UnsignedCharTy) ||
+(ThroughT == Ctx.SignedCharTy && OrigT == Ctx.UnsignedCharTy) ||
+(ThroughT == Ctx.ShortTy && OrigT == Ctx.UnsignedShortTy) ||
+(ThroughT == Ctx.IntTy && OrigT == Ctx.UnsignedIntTy) ||
+(ThroughT == Ctx.LongTy && OrigT == Ctx.UnsignedLongTy) ||
+(ThroughT == Ctx.LongLongTy && OrigT == Ctx.UnsignedLongLongTy) ||
+// - is char, uchar, std::byte
+(ThroughT == Ctx.CharTy) || (ThroughT == Ctx.UnsignedCharTy) ||
+ThroughT->isStdByteType()) &&
+   // NOTE: C++20 6.8.2(3.4) [basic.compound]:
+   //  An object of type T that is not an array element is considered to
+   //  belong to an array with one element of type T.
+   // Hence, the first element can be retrieved only. At least untill a
+   // paper P1839R0 be considered by the committee.
+   (Index == 0));
+}

[PATCH] D110622: [HIPSPV][3/4] Enable SPIR-V emission for HIP

2021-10-04 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki updated this revision to Diff 376829.
linjamaki added a comment.

Repurpose 'Generic' CudaArch, Use getAllArgValues() for reading
--offload values and fix a enum range.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110622

Files:
  clang/include/clang/Basic/Cuda.h
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Driver.h
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Cuda.cpp
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/Inputs/hipspv-dev-lib/a/a.bc
  clang/test/Driver/Inputs/hipspv-dev-lib/b/b.bc
  clang/test/Driver/Inputs/hipspv-dev-lib/hipspv-spirv64.bc
  clang/test/Driver/Inputs/hipspv/bin/.hipVersion
  clang/test/Driver/Inputs/hipspv/lib/hip-device-lib/hipspv-spirv64.bc
  clang/test/Driver/Inputs/hipspv/lib/libLLVMHipSpvPasses.so
  clang/test/Driver/Inputs/pass-plugin.so
  clang/test/Driver/hipspv-device-libs.hip
  clang/test/Driver/hipspv-pass-plugin.hip
  clang/test/Driver/hipspv-toolchain-rdc.hip
  clang/test/Driver/hipspv-toolchain.hip
  clang/test/Driver/invalid-offload-options.cpp

Index: clang/test/Driver/invalid-offload-options.cpp
===
--- /dev/null
+++ clang/test/Driver/invalid-offload-options.cpp
@@ -0,0 +1,18 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// UNSUPPORTED: system-windows
+
+// RUN: %clang -### -x hip -target x86_64-linux-gnu --offload= \
+// RUN:   --hip-path=%S/Inputs/hipspv -nogpuinc -nogpulib %s \
+// RUN: 2>&1 | FileCheck --check-prefix=INVALID-TARGET %s
+// RUN: %clang -### -x hip -target x86_64-linux-gnu --offload=foo   \
+// RUN:   --hip-path=%S/Inputs/hipspv -nogpuinc -nogpulib %s \
+// RUN: 2>&1 | FileCheck --check-prefix=INVALID-TARGET %s
+
+// INVALID-TARGET: error: Invalid or unsupported offload target: '{{.*}}'
+
+// RUN: %clang -### -x hip -target x86_64-linux-gnu --offload=foo,bar \
+// RUN:   --hip-path=%S/Inputs/hipspv -nogpuinc -nogpulib %s \
+// RUN: 2>&1 | FileCheck --check-prefix=TOO-MANY-TARGETS %s
+
+// TOO-MANY-TARGETS: error: Only one offload target is supported in HIP.
Index: clang/test/Driver/hipspv-toolchain.hip
===
--- /dev/null
+++ clang/test/Driver/hipspv-toolchain.hip
@@ -0,0 +1,37 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// UNSUPPORTED: system-windows
+
+// RUN: %clang -### -target x86_64-linux-gnu --offload=spirv64 \
+// RUN:   --hip-path=%S/Inputs/hipspv -nohipwrapperinc %s \
+// RUN: 2>&1 | FileCheck %s
+
+// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "spirv64"
+// CHECK-SAME: "-aux-triple" "{{.*}}" "-emit-llvm-bc"
+// CHECK-SAME: "-fcuda-is-device"
+// CHECK-SAME: "-fcuda-allow-variadic-functions"
+// CHECK-SAME: "-mlink-builtin-bitcode" {{".*/hipspv/lib/hip-device-lib/hipspv-spirv64.bc"}}
+// CHECK-SAME: "-isystem" {{".*/hipspv/include"}}
+// CHECK-SAME: "-fhip-new-launch-api"
+// CHECK-SAME: "-o" [[DEV_BC:".*bc"]]
+// CHECK-SAME: "-x" "hip"
+
+// CHECK: {{".*llvm-link"}} [[DEV_BC]] "-o" [[LINK_BC:".*bc"]]
+
+// CHECK: {{".*opt"}} [[LINK_BC]] "-load-pass-plugin"
+// CHECK-SAME: {{".*/hipspv/lib/libLLVMHipSpvPasses.so"}}
+// CHECK-SAME: "-passes=hip-post-link-passes" "-o" [[LOWER_BC:".*bc"]]
+
+// CHECK: {{".*llvm-spirv"}} "-spirv-max-version=1.1" "--spirv-ext=+all"
+// CHECK-SAME: [[LOWER_BC]] "-o" "[[SPIRV_OUT:.*out]]"
+
+// CHECK: {{".*clang-offload-bundler"}} "-type=o" "-bundle-align=4096"
+// CHECK-SAME: "-targets=host-x86_64-unknown-linux,hip-spirv64generic"
+// CHECK-SAME: "-inputs={{.*}},[[SPIRV_OUT]]" "-outputs=[[BUNDLE:.*hipfb]]"
+
+// CHECK: [[CLANG]] "-cc1" "-triple" {{".*"}} "-aux-triple" "spirv64"
+// CHECK-SAME: "-emit-obj"
+// CHECK-SAME: "-fcuda-include-gpubinary" "[[BUNDLE]]"
+// CHECK-SAME: "-o" [[OBJ_HOST:".*o"]] "-x" "hip"
+
+// CHECK: {{".*ld.*"}} {{.*}}[[OBJ_HOST]]
Index: clang/test/Driver/hipspv-toolchain-rdc.hip
===
--- /dev/null
+++ clang/test/Driver/hipspv-toolchain-rdc.hip
@@ -0,0 +1,63 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// UNSUPPORTED: system-windows
+
+// RUN: %clang -### -x hip -target x86_64-linux-gnu --offload=spirv64 \
+// RUN:   -fgpu-rdc --hip-path=%S/Inputs/hipspv -nohipwrapperinc \
+// RUN:   %S/Inputs/hip_multiple_inputs/a.cu \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s
+
+// Emit objects for host side path
+// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// CHECK-SAME: "-aux-triple" "spirv64"
+// CHECK-SAME: "-emit-obj"
+// CHECK-SAME: "-fgpu-rdc"
+// CHECK-SAME: {{.*}} "-o" [[A_OBJ_HOST:".*o"]] "-x" "hip"
+// CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]]
+
+// CHECK: [[CLANG]] "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// CHECK-SAME: "-aux-triple

[PATCH] D110910: [analyzer][solver] Fix CmpOpTable handling bug

2021-10-04 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

@ASDenysPetrov Gentle ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110910

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


[PATCH] D97699: [analyzer] Add InvalidPtrChecker

2021-10-04 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Gentle ping, I think we can land this, please do so. Let me know if there is an 
issue with, .e.g missing commit rights, etc...


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

https://reviews.llvm.org/D97699

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


[PATCH] D110685: [HIPSPV][4/4] Add option to use llc to emit SPIR-V

2021-10-04 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki created this revision.
Herald added subscribers: dang, yaxunl.
linjamaki updated this revision to Diff 376838.
linjamaki added a comment.
linjamaki edited the summary of this revision.
linjamaki added a reviewer: Anastasia.
linjamaki updated this revision to Diff 376848.
linjamaki published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Rebase.


linjamaki added a comment.

Remove metavar from --spirv-use-llc.


Add two hidden options for emitting SPIR-V binary via LLC. The options are only 
meant for testing and development.

´--spirv-use-llc´ invokes in-tree llc. Not usable at the moment until the 
SPIR-V backend lands on LLVM.

´--spirv-use-llc=´ invokes llc tool given as path. Meant for 
trying out out-of-tree SPIR-V backend.

The HIPSPV tool chain is the only one responding to these options.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110685

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/test/Driver/hipspv-options.hip


Index: clang/test/Driver/hipspv-options.hip
===
--- /dev/null
+++ clang/test/Driver/hipspv-options.hip
@@ -0,0 +1,12 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// UNSUPPORTED: system-windows
+
+// RUN: %clang -### -target x86_64-linux-gnu --offload=spirv64 \
+// RUN:   --hip-path=%S/Inputs/hipspv -nogpuinc -nogpulib %s \
+// RUN:   --spirv-use-llc=/foo/bar/llc 2>&1 | FileCheck %s
+
+// CHECK-NOT: llvm-spirv
+// CHECK: "/foo/bar/llc" "--mattr=+spirv1.1" "--filetype=obj" "{{.*}}.bc"
+// CHECK-SAME: "-o" "{{.*}}.out"
+
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===
--- clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -97,6 +97,25 @@
 
   // Emit SPIR-V binary.
 
+  // Use llc. Meant for testing out LLVM SPIR-V backend. Eventually HIPSPV will
+  // switch to use in-tree SPIR-V backend for binary emission.
+  if (auto *A = Args.getLastArg(options::OPT_spirv_use_llc,
+options::OPT_spirv_use_llc_EQ)) {
+assert(A->getNumValues() <= 1);
+const char *LlcExe = nullptr;
+if (A->getNumValues() == 1 && !StringRef(A->getValue()).empty())
+  LlcExe = A->getValue();
+else
+  LlcExe = Args.MakeArgString(getToolChain().GetProgramPath("llc"));
+ArgStringList LlcArgs{"--mattr=+spirv1.1", "--filetype=obj", TempFile, 
"-o",
+  Output.getFilename()};
+C.addCommand(std::make_unique(JA, *this,
+   ResponseFileSupport::None(), LlcExe,
+   LlcArgs, Inputs, Output));
+return;
+  }
+
+  // Use SPIRV-LLVM Translator.
   ArgStringList LlvmSpirvArgs{"-spirv-max-version=1.1", "--spirv-ext=+all",
   TempFile, "-o", Output.getFilename()};
   const char *LlvmSpirv =
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1528,6 +1528,12 @@
 Group, Flags<[CC1Option]>, MetaVarName<"">,
 HelpText<"Enable heap memory profiling and dump results into ">;
 
+def spirv_use_llc : Flag<["--"], "spirv-use-llc">, Flags<[HelpHidden]>,
+HelpText<"Use (in-tree) llc to emit SPIR-V. Use for development and 
testing only.">;
+def spirv_use_llc_EQ : Joined<["--"], "spirv-use-llc=">,
+MetaVarName<"">, Flags<[HelpHidden]>,
+HelpText<"Use speficied llc to emit SPIR-V. Use for development and 
testing only.">;
+
 // Begin sanitizer flags. These should all be core options exposed in all 
driver
 // modes.
 let Flags = [CC1Option, CoreOption] in {


Index: clang/test/Driver/hipspv-options.hip
===
--- /dev/null
+++ clang/test/Driver/hipspv-options.hip
@@ -0,0 +1,12 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// UNSUPPORTED: system-windows
+
+// RUN: %clang -### -target x86_64-linux-gnu --offload=spirv64 \
+// RUN:   --hip-path=%S/Inputs/hipspv -nogpuinc -nogpulib %s \
+// RUN:   --spirv-use-llc=/foo/bar/llc 2>&1 | FileCheck %s
+
+// CHECK-NOT: llvm-spirv
+// CHECK: "/foo/bar/llc" "--mattr=+spirv1.1" "--filetype=obj" "{{.*}}.bc"
+// CHECK-SAME: "-o" "{{.*}}.out"
+
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===
--- clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -97,6 +97,25 @@
 
   // Emit SPIR-V binary.
 
+  // Use llc. Meant for testing out LLVM SPIR-V backend. Eventually HIPSPV will
+  // switch to use in-tree SPIR-V backend for binary emission.
+  if (auto *A = Args.getLastArg(options::OPT_spirv_use_llc,
+options::OPT_spirv_use_llc_EQ)) {
+asser

[clang] 566690b - [APFloat] Remove BitWidth argument from getAllOnesValue

2021-10-04 Thread Jay Foad via cfe-commits

Author: Jay Foad
Date: 2021-10-04T11:32:16+01:00
New Revision: 566690b067c8175314fa657b899c99bccf96821c

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

LOG: [APFloat] Remove BitWidth argument from getAllOnesValue

There's no need to pass this in explicitly because it is
trivially available from the semantics.

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
llvm/include/llvm/ADT/APFloat.h
llvm/lib/IR/Constants.cpp
llvm/lib/Support/APFloat.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 55f36611a64f..5e6fa2c8fc4e 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -17208,8 +17208,7 @@ static bool actOnOMPReductionKindClause(
   Type = ComplexTy->getElementType();
 if (Type->isRealFloatingType()) {
   llvm::APFloat InitValue = llvm::APFloat::getAllOnesValue(
-  Context.getFloatTypeSemantics(Type),
-  Context.getTypeSize(Type));
+  Context.getFloatTypeSemantics(Type));
   Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true,
  Type, ELoc);
 } else if (Type->isScalarType()) {

diff  --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index f493a03b4b87..40e0e32c77a8 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -961,9 +961,7 @@ class APFloat : public APFloatBase {
   /// Returns a float which is bitcasted from an all one value int.
   ///
   /// \param Semantics - type float semantics
-  /// \param BitWidth - Select float type
-  static APFloat getAllOnesValue(const fltSemantics &Semantics,
- unsigned BitWidth);
+  static APFloat getAllOnesValue(const fltSemantics &Semantics);
 
   /// Used to insert APFloat objects, or objects that contain APFloat objects,
   /// into FoldingSets.

diff  --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 0f2f76e86600..30a5cae53889 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -408,8 +408,7 @@ Constant *Constant::getAllOnesValue(Type *Ty) {
 APInt::getAllOnes(ITy->getBitWidth()));
 
   if (Ty->isFloatingPointTy()) {
-APFloat FL = APFloat::getAllOnesValue(Ty->getFltSemantics(),
-  Ty->getPrimitiveSizeInBits());
+APFloat FL = APFloat::getAllOnesValue(Ty->getFltSemantics());
 return ConstantFP::get(Ty->getContext(), FL);
   }
 

diff  --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 780d1d0c77b1..fc2b1ae992b5 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -4864,9 +4864,8 @@ APFloat::opStatus APFloat::convert(const fltSemantics 
&ToSemantics,
   llvm_unreachable("Unexpected semantics");
 }
 
-APFloat APFloat::getAllOnesValue(const fltSemantics &Semantics,
- unsigned BitWidth) {
-  return APFloat(Semantics, APInt::getAllOnes(BitWidth));
+APFloat APFloat::getAllOnesValue(const fltSemantics &Semantics) {
+  return APFloat(Semantics, APInt::getAllOnes(Semantics.sizeInBits));
 }
 
 void APFloat::print(raw_ostream &OS) const {

diff  --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index cd605d08d8ff..2ed92c4f7f20 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -12204,8 +12204,8 @@ static SDValue lowerShuffleAsBitMask(const SDLoc &DL, 
MVT VT, SDValue V1,
   MVT LogicVT = VT;
   if (EltVT == MVT::f32 || EltVT == MVT::f64) {
 Zero = DAG.getConstantFP(0.0, DL, EltVT);
-APFloat AllOnesValue = APFloat::getAllOnesValue(
-SelectionDAG::EVTToAPFloatSemantics(EltVT), EltVT.getSizeInBits());
+APFloat AllOnesValue =
+APFloat::getAllOnesValue(SelectionDAG::EVTToAPFloatSemantics(EltVT));
 AllOnes = DAG.getConstantFP(AllOnesValue, DL, EltVT);
 LogicVT =
 MVT::getVectorVT(EltVT == MVT::f64 ? MVT::i64 : MVT::i32, Mask.size());



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


[PATCH] D111047: CUDA/HIP: Allow __int128 on the host side

2021-10-04 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki created this revision.
Herald added a subscriber: yaxunl.
linjamaki edited the summary of this revision.
linjamaki added a reviewer: rsmith.
linjamaki added subscribers: bader, Anastasia.
linjamaki published this revision for review.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Consider case where `__int128` type is supported by the host target but
not by a device target (e.g. spirv*). Clang emits an error message for
unsupported type even if the device code does not use it. This patch
fixes this issue by emitting the error message when the device code
attempts to use the unsupported type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111047

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCUDA/allow-int128.cu
  clang/test/SemaCUDA/spirv-int128.cu


Index: clang/test/SemaCUDA/spirv-int128.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/spirv-int128.cu
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple spirv64 -aux-triple x86_64-unknown-linux-gnu \
+// RUN:   -fcuda-is-device -verify -fsyntax-only %s
+
+#define __device__ __attribute__((device))
+
+__int128 h_glb;
+
+__device__ __int128 d_unused;
+
+// expected-note@+1 {{'d_glb' defined here}}
+__device__ __int128 d_glb;
+
+__device__ __int128 bar() {
+  // expected-error@+1 {{'d_glb' requires 128 bit size '__int128' type 
support, but device 'spirv64' does not support it}}
+  return d_glb;
+}
Index: clang/test/SemaCUDA/allow-int128.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/allow-int128.cu
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa \
+// RUN:   -aux-triple x86_64-unknown-linux-gnu \
+// RUN:   -fcuda-is-device -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple nvptx \
+// RUN:   -aux-triple x86_64-unknown-linux-gnu \
+// RUN:   -fcuda-is-device -verify -fsyntax-only %s
+
+// expected-no-diagnostics
+#define __device__ __attribute__((device))
+
+__int128 h_glb;
+__device__ __int128 d_unused;
+__device__ __int128 d_glb;
+__device__ __int128 bar() {
+  return d_glb;
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1496,7 +1496,7 @@
   }
   case DeclSpec::TST_int128:
 if (!S.Context.getTargetInfo().hasInt128Type() &&
-!S.getLangOpts().SYCLIsDevice &&
+!S.getLangOpts().SYCLIsDevice && !S.getLangOpts().CUDAIsDevice &&
 !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice))
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
 << "__int128";
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -366,7 +366,8 @@
 
   diagnoseUseOfInternalDeclInInlineFunction(*this, D, Loc);
 
-  if (LangOpts.SYCLIsDevice || (LangOpts.OpenMP && LangOpts.OpenMPIsDevice)) {
+  if (LangOpts.SYCLIsDevice || (LangOpts.OpenMP && LangOpts.OpenMPIsDevice) ||
+  LangOpts.CUDAIsDevice) {
 if (auto *VD = dyn_cast(D))
   checkDeviceDecl(VD, Loc);
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -9569,7 +9569,8 @@
 }
   }
 
-  if (LangOpts.SYCLIsDevice || (LangOpts.OpenMP && LangOpts.OpenMPIsDevice))
+  if (LangOpts.SYCLIsDevice || (LangOpts.OpenMP && LangOpts.OpenMPIsDevice) ||
+  LangOpts.CUDAIsDevice)
 checkDeviceDecl(NewFD, D.getBeginLoc());
 
   if (!getLangOpts().CPlusPlus) {


Index: clang/test/SemaCUDA/spirv-int128.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/spirv-int128.cu
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple spirv64 -aux-triple x86_64-unknown-linux-gnu \
+// RUN:   -fcuda-is-device -verify -fsyntax-only %s
+
+#define __device__ __attribute__((device))
+
+__int128 h_glb;
+
+__device__ __int128 d_unused;
+
+// expected-note@+1 {{'d_glb' defined here}}
+__device__ __int128 d_glb;
+
+__device__ __int128 bar() {
+  // expected-error@+1 {{'d_glb' requires 128 bit size '__int128' type support, but device 'spirv64' does not support it}}
+  return d_glb;
+}
Index: clang/test/SemaCUDA/allow-int128.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/allow-int128.cu
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa \
+// RUN:   -aux-triple x86_64-unknown-linux-gnu \
+// RUN:   -fcuda-is-device -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple nvptx \
+// RUN:   -aux-triple x86_64-unknown-linux-gnu \
+// RUN:   -fcuda-is-device -verify -fsyntax-only %s
+
+// expected-no-diagnostics
+#define __device__ __attribute

[PATCH] D110771: [PowerPC] Fix __builtin_ppc_load2r to return short instead of int.

2021-10-04 Thread Stefan Pintilie via Phabricator via cfe-commits
stefanp updated this revision to Diff 376857.
stefanp added a comment.

Rebased and added signext test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110771

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll
===
--- llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll
@@ -52,12 +52,28 @@
 define dso_local zeroext i16 @test_builtin_ppc_load2r() {
 ; CHECK-64B-LABEL: test_builtin_ppc_load2r:
 ; CHECK-64B: lhbrx 3, 0, 3
-; CHECK-64B-NEXT:clrldi 3, 3, 48
 ; CHECK-64B-NEXT:blr
 
 ; CHECK-32B-LABEL: test_builtin_ppc_load2r:
 ; CHECK-32B: lhbrx 3, 0, 3
-; CHECK-32B-NEXT:clrlwi 3, 3, 16
+; CHECK-32B-NEXT:blr
+entry:
+  %0 = load i16*, i16** @us_addr, align 8
+  %1 = bitcast i16* %0 to i8*
+  %2 = call i32 @llvm.ppc.load2r(i8* %1)
+  %conv = trunc i32 %2 to i16
+  ret i16 %conv
+}
+
+define dso_local signext i16 @test_builtin_ppc_load2r_signext() {
+; CHECK-64B-LABEL: test_builtin_ppc_load2r_signext:
+; CHECK-64B: lhbrx 3, 0, 3
+; CHECK-64B-NEXT:extsh 3, 3
+; CHECK-64B-NEXT:blr
+
+; CHECK-32B-LABEL: test_builtin_ppc_load2r_signext:
+; CHECK-32B: lhbrx 3, 0, 3
+; CHECK-32B-NEXT:extsh 3, 3
 ; CHECK-32B-NEXT:blr
 entry:
   %0 = load i16*, i16** @us_addr, align 8
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -15681,6 +15681,18 @@
   Known.Zero = ~1U;  // All bits but the low one are known to be zero.
   break;
 }
+break;
+  }
+  case ISD::INTRINSIC_W_CHAIN: {
+switch (cast(Op.getOperand(1))->getZExtValue()) {
+default:
+  break;
+case Intrinsic::ppc_load2r:
+  // Top bits are cleared for load2r (which is the same as lhbrx).
+  Known.Zero = 0x;
+  break;
+}
+break;
   }
   }
 }
Index: llvm/include/llvm/IR/IntrinsicsPowerPC.td
===
--- llvm/include/llvm/IR/IntrinsicsPowerPC.td
+++ llvm/include/llvm/IR/IntrinsicsPowerPC.td
@@ -1629,8 +1629,7 @@
 Intrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i64_ty, llvm_i64_ty], [IntrNoMem]>;
   // load
   def int_ppc_load2r
-  : GCCBuiltin<"__builtin_ppc_load2r">,
-Intrinsic<[llvm_i32_ty], [llvm_ptr_ty], [IntrReadMem, IntrArgMemOnly]>;
+  : Intrinsic<[llvm_i32_ty], [llvm_ptr_ty], [IntrReadMem, IntrArgMemOnly]>;
   def int_ppc_load4r
   : GCCBuiltin<"__builtin_ppc_load4r">,
 Intrinsic<[llvm_i32_ty], [llvm_ptr_ty], [IntrReadMem, IntrArgMemOnly]>;
Index: clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed.c
@@ -1,4 +1,4 @@
-// REQUIRES: powerpc-registered-target.
+// REQUIRES: powerpc-registered-target
 // RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu \
 // RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
 // RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu \
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -15655,6 +15655,12 @@
 Value *Rotate = Builder.CreateCall(F, {Ops[0], Ops[0], ShiftAmt});
 return Builder.CreateAnd(Rotate, Ops[2]);
   }
+  case PPC::BI__builtin_ppc_load2r: {
+Function *F = CGM.getIntrinsic(Intrinsic::ppc_load2r);
+Ops[0] = Builder.CreateBitCast(Ops[0], Int8PtrTy);
+Value *LoadIntrinsic = Builder.CreateCall(F, Ops);
+return Builder.CreateTrunc(LoadIntrinsic, Int16Ty);
+  }
   // FMA variations
   case PPC::BI__builtin_vsx_xvmaddadp:
   case PPC::BI__builtin_vsx_xvmaddasp:
Index: clang/include/clang/Basic/BuiltinsPPC.def
===
--- clang/include/clang/Basic/BuiltinsPPC.def
+++ clang/include/clang/Basic/BuiltinsPPC.def
@@ -121,7 +121,7 @@
 BUILTIN(__builtin_ppc_rlwimi, "UiUiUiIUiIUi", "")
 BUILTIN(__builtin_ppc_rldimi, "ULLiULLiULLiIUiIULLi", "")
 // load
-BUILTIN(__builtin_ppc_load2r, "UiUs*", "")
+BUILTIN(__builtin_ppc_load2r, "UsUs*", "")
 BUILTIN(__builtin_ppc_load4r, "UiUi*", "")
 BUILTIN(__builtin_ppc_load8r, "ULLiULLi*", "")
 // store
___

[clang] 4fc2f49 - [PowerPC] Fix __builtin_ppc_load2r to return short instead of int.

2021-10-04 Thread Stefan Pintilie via cfe-commits

Author: Stefan Pintilie
Date: 2021-10-04T06:17:02-05:00
New Revision: 4fc2f4979cf56fdc87cbd5ed1b02ef3461916731

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

LOG: [PowerPC] Fix __builtin_ppc_load2r to return short instead of int.

This patch fixes the return value of the builtin __builtin_ppc_load2r to
correctly return short instead of int.

Reviewed By: nemanjai, #powerpc

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsPPC.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed.c
llvm/include/llvm/IR/IntrinsicsPowerPC.td
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsPPC.def 
b/clang/include/clang/Basic/BuiltinsPPC.def
index 65f490a214bcb..3fa5729fc7d03 100644
--- a/clang/include/clang/Basic/BuiltinsPPC.def
+++ b/clang/include/clang/Basic/BuiltinsPPC.def
@@ -121,7 +121,7 @@ BUILTIN(__builtin_ppc_rlwnm, "UiUiIUiIUi", "")
 BUILTIN(__builtin_ppc_rlwimi, "UiUiUiIUiIUi", "")
 BUILTIN(__builtin_ppc_rldimi, "ULLiULLiULLiIUiIULLi", "")
 // load
-BUILTIN(__builtin_ppc_load2r, "UiUs*", "")
+BUILTIN(__builtin_ppc_load2r, "UsUs*", "")
 BUILTIN(__builtin_ppc_load4r, "UiUi*", "")
 BUILTIN(__builtin_ppc_load8r, "ULLiULLi*", "")
 // store

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c7dcde149a157..91d90d7ba5f7f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -15655,6 +15655,12 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 Value *Rotate = Builder.CreateCall(F, {Ops[0], Ops[0], ShiftAmt});
 return Builder.CreateAnd(Rotate, Ops[2]);
   }
+  case PPC::BI__builtin_ppc_load2r: {
+Function *F = CGM.getIntrinsic(Intrinsic::ppc_load2r);
+Ops[0] = Builder.CreateBitCast(Ops[0], Int8PtrTy);
+Value *LoadIntrinsic = Builder.CreateCall(F, Ops);
+return Builder.CreateTrunc(LoadIntrinsic, Int16Ty);
+  }
   // FMA variations
   case PPC::BI__builtin_vsx_xvmaddadp:
   case PPC::BI__builtin_vsx_xvmaddasp:

diff  --git a/clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed.c 
b/clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed.c
index e0ca6fdfe62a5..c95bc473e5d5b 100644
--- a/clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed.c
+++ b/clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed.c
@@ -1,4 +1,4 @@
-// REQUIRES: powerpc-registered-target.
+// REQUIRES: powerpc-registered-target
 // RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu \
 // RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
 // RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu \

diff  --git a/llvm/include/llvm/IR/IntrinsicsPowerPC.td 
b/llvm/include/llvm/IR/IntrinsicsPowerPC.td
index d4f1e5e985b22..e60bad8fd9f0c 100644
--- a/llvm/include/llvm/IR/IntrinsicsPowerPC.td
+++ b/llvm/include/llvm/IR/IntrinsicsPowerPC.td
@@ -1629,8 +1629,7 @@ let TargetPrefix = "ppc" in {
 Intrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i64_ty, llvm_i64_ty], 
[IntrNoMem]>;
   // load
   def int_ppc_load2r
-  : GCCBuiltin<"__builtin_ppc_load2r">,
-Intrinsic<[llvm_i32_ty], [llvm_ptr_ty], [IntrReadMem, IntrArgMemOnly]>;
+  : Intrinsic<[llvm_i32_ty], [llvm_ptr_ty], [IntrReadMem, IntrArgMemOnly]>;
   def int_ppc_load4r
   : GCCBuiltin<"__builtin_ppc_load4r">,
 Intrinsic<[llvm_i32_ty], [llvm_ptr_ty], [IntrReadMem, IntrArgMemOnly]>;

diff  --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp 
b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index 6b0b6397ba609..d9c9930922f70 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -15681,6 +15681,18 @@ void 
PPCTargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
   Known.Zero = ~1U;  // All bits but the low one are known to be zero.
   break;
 }
+break;
+  }
+  case ISD::INTRINSIC_W_CHAIN: {
+switch (cast(Op.getOperand(1))->getZExtValue()) {
+default:
+  break;
+case Intrinsic::ppc_load2r:
+  // Top bits are cleared for load2r (which is the same as lhbrx).
+  Known.Zero = 0x;
+  break;
+}
+break;
   }
   }
 }

diff  --git 
a/llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll 
b/llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll
index 7216c12d41629..ed3a96f8dd4c8 100644
--- a/llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll
+++ b/llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll
@@ -52,12 +52,28 @@ declare void @llvm.ppc.store4r(i32, i8*)
 define dso_local zeroext i16

[PATCH] D110771: [PowerPC] Fix __builtin_ppc_load2r to return short instead of int.

2021-10-04 Thread Stefan Pintilie via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4fc2f4979cf5: [PowerPC] Fix __builtin_ppc_load2r to return 
short instead of int. (authored by stefanp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110771

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll
===
--- llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-load-store-reversed.ll
@@ -52,12 +52,28 @@
 define dso_local zeroext i16 @test_builtin_ppc_load2r() {
 ; CHECK-64B-LABEL: test_builtin_ppc_load2r:
 ; CHECK-64B: lhbrx 3, 0, 3
-; CHECK-64B-NEXT:clrldi 3, 3, 48
 ; CHECK-64B-NEXT:blr
 
 ; CHECK-32B-LABEL: test_builtin_ppc_load2r:
 ; CHECK-32B: lhbrx 3, 0, 3
-; CHECK-32B-NEXT:clrlwi 3, 3, 16
+; CHECK-32B-NEXT:blr
+entry:
+  %0 = load i16*, i16** @us_addr, align 8
+  %1 = bitcast i16* %0 to i8*
+  %2 = call i32 @llvm.ppc.load2r(i8* %1)
+  %conv = trunc i32 %2 to i16
+  ret i16 %conv
+}
+
+define dso_local signext i16 @test_builtin_ppc_load2r_signext() {
+; CHECK-64B-LABEL: test_builtin_ppc_load2r_signext:
+; CHECK-64B: lhbrx 3, 0, 3
+; CHECK-64B-NEXT:extsh 3, 3
+; CHECK-64B-NEXT:blr
+
+; CHECK-32B-LABEL: test_builtin_ppc_load2r_signext:
+; CHECK-32B: lhbrx 3, 0, 3
+; CHECK-32B-NEXT:extsh 3, 3
 ; CHECK-32B-NEXT:blr
 entry:
   %0 = load i16*, i16** @us_addr, align 8
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -15681,6 +15681,18 @@
   Known.Zero = ~1U;  // All bits but the low one are known to be zero.
   break;
 }
+break;
+  }
+  case ISD::INTRINSIC_W_CHAIN: {
+switch (cast(Op.getOperand(1))->getZExtValue()) {
+default:
+  break;
+case Intrinsic::ppc_load2r:
+  // Top bits are cleared for load2r (which is the same as lhbrx).
+  Known.Zero = 0x;
+  break;
+}
+break;
   }
   }
 }
Index: llvm/include/llvm/IR/IntrinsicsPowerPC.td
===
--- llvm/include/llvm/IR/IntrinsicsPowerPC.td
+++ llvm/include/llvm/IR/IntrinsicsPowerPC.td
@@ -1629,8 +1629,7 @@
 Intrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i64_ty, llvm_i64_ty], [IntrNoMem]>;
   // load
   def int_ppc_load2r
-  : GCCBuiltin<"__builtin_ppc_load2r">,
-Intrinsic<[llvm_i32_ty], [llvm_ptr_ty], [IntrReadMem, IntrArgMemOnly]>;
+  : Intrinsic<[llvm_i32_ty], [llvm_ptr_ty], [IntrReadMem, IntrArgMemOnly]>;
   def int_ppc_load4r
   : GCCBuiltin<"__builtin_ppc_load4r">,
 Intrinsic<[llvm_i32_ty], [llvm_ptr_ty], [IntrReadMem, IntrArgMemOnly]>;
Index: clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-load-store-reversed.c
@@ -1,4 +1,4 @@
-// REQUIRES: powerpc-registered-target.
+// REQUIRES: powerpc-registered-target
 // RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu \
 // RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
 // RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu \
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -15655,6 +15655,12 @@
 Value *Rotate = Builder.CreateCall(F, {Ops[0], Ops[0], ShiftAmt});
 return Builder.CreateAnd(Rotate, Ops[2]);
   }
+  case PPC::BI__builtin_ppc_load2r: {
+Function *F = CGM.getIntrinsic(Intrinsic::ppc_load2r);
+Ops[0] = Builder.CreateBitCast(Ops[0], Int8PtrTy);
+Value *LoadIntrinsic = Builder.CreateCall(F, Ops);
+return Builder.CreateTrunc(LoadIntrinsic, Int16Ty);
+  }
   // FMA variations
   case PPC::BI__builtin_vsx_xvmaddadp:
   case PPC::BI__builtin_vsx_xvmaddasp:
Index: clang/include/clang/Basic/BuiltinsPPC.def
===
--- clang/include/clang/Basic/BuiltinsPPC.def
+++ clang/include/clang/Basic/BuiltinsPPC.def
@@ -121,7 +121,7 @@
 BUILTIN(__builtin_ppc_rlwimi, "UiUiUiIUiIUi", "")
 BUILTIN(__builtin_ppc_rldimi, "ULLiULLiULLiIUiIULLi", "")
 // load
-BUILTIN(__builtin_ppc_load2r, "UiUs*", "")
+BUILTIN(__builtin_ppc_load2r, "UsUs*", "")
 BUILTIN(__builtin_ppc_load4r, "UiUi*

[PATCH] D111041: [clang-tidy] Remove 'IgnoreDestructors = true' from cppcoreguidelines-explicit-virtual-functions

2021-10-04 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

I wonder why I'm not getting automated pre-merge builds?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111041

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


[PATCH] D111041: [clang-tidy] Remove 'IgnoreDestructors = true' from cppcoreguidelines-explicit-virtual-functions

2021-10-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

In D111041#3039590 , @carlosgalvezp 
wrote:

> I wonder why I'm not getting automated pre-merge builds?

Huh, that is strange. Usually you get them automatically when you set the 
Repository properly (which it looks like you have).

This change is missing documentation changes, release note mentions, test 
coverage, etc, so it needs a bit of work in those areas. However, more 
importantly, do you have evidence that this option is not being used by users? 
I understand that the core guidelines changed their position on this feature 
and so we may want to change the default value, but removing the option 
entirely feels user-hostile without some evidence that this option is unused in 
practice.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111041

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


[PATCH] D110614: [clang-tidy] Fix false positives in cppcoreguidelines-virtual-class-destructor

2021-10-04 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

In D110614#3038519 , @carlosgalvezp 
wrote:

> Hi! Are there any more issues I should address? It would be nice to get it 
> merged since it fixes quite a few FPs.

I'm not seeing anything immediate to add. I like the proper printing with the 
template parameters. 🙂
Just in case: add another set of tests where the template instantiation (both 
diagnosed and not diagnosed) is behind a `typedef`, just to see how well the 
diagnostic is printed and generated. Otherwise, I'm happy with this.

> `// Fixes https://bugs.llvm.org/show_bug.cgi?id=51912`

I still think that maybe this whole fiasco is worth either a bug report against 
`Sema` on its own, or just a question-phrased mail to `cfe-dev`.


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

https://reviews.llvm.org/D110614

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


[PATCH] D111041: [clang-tidy] Remove 'IgnoreDestructors = true' from cppcoreguidelines-explicit-virtual-functions

2021-10-04 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Thanks for the input!

> release note mentions

Sure thing!

> documentation changes

As we discussed in the separate mail thread, there is no documentation at all 
as to what default values an alias/main check has. Where should I put that? Or 
do you mean that now that all 3 checks (primary + 2 aliases) have identical 
defaults, I should document that in the main check documentation?

> test coverage

I was surprised to not find any unit test for this check, probably because it's 
already done by the unit test of the "main check"? Should add a new unit test, 
pretty much copy-pasting the test for the main check?

> evidence that this option is not being used by users

Not sure how to go about this one :) I guess we can't have a 100% guarantee 
that this won't break things for users, there will always be an edge case. 
Perhaps we should document it very clearly in the Release Notes as well as 
explaining how to revert to the old behavior if needed?

Since we are talking about a "guideline check" 
(cppcoreguidelines-explicit-virtual-functions) and a "good practice check" 
(modernize-use-override), I don't think it's unreasonable that users have 
enabled both checks. If so, the "modernize" check should already have this 
behavior as default and prompted users to make changes - the cppcoreguidelines 
was less strict, and now it would be as strict as the "modernize-use-override" 
check. In that scenario, this patch shouldn't break things for users. The 
scenario that would break things for users is when they only enable the 
cppcoreguidelines check alone.

The guidelines changed in 2019, I think after 2 years users wouldn't mind the 
tooling catching up :)

Since I'm new here and missed quite a few things, do you know if there's a 
checklist somewhere where I can read about what else I should include in the 
patch?

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111041

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


[PATCH] D111049: [Support] Change fatal_error_handler_t to take a const char* instead of std::string

2021-10-04 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon created this revision.
RKSimon added reviewers: ychen, rnk, MaskRay, zturner, chandlerc, lattner.
Herald added subscribers: dexonsmith, hiraditya.
RKSimon requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

https://commondatastorage.googleapis.com/chromium-browser-clang/llvm-include-analysis.html

Excessive use of the  header has a massive impact on compile time; its 
most commonly included via the ErrorHandling.h header, which has to be included 
in many key headers, impacting many source files that have no need for 
std::string.

As an initial step toward removing the  include from ErrorHandling.h, 
this patch proposes to update the fatal_error_handler_t handler to just take a 
raw const char* instead.

The next step will be to remove the report_fatal_error std::string variant, 
which will involve a lot of cleanup and better use of Twine/StringRef.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111049

Files:
  clang/tools/clang-repl/ClangRepl.cpp
  clang/tools/driver/cc1_main.cpp
  clang/tools/driver/cc1as_main.cpp
  clang/tools/libclang/FatalErrorHandler.cpp
  llvm/include/llvm/Support/ErrorHandling.h
  llvm/lib/Support/ErrorHandling.cpp
  llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
  llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp

Index: llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
===
--- llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
+++ llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
@@ -170,7 +170,7 @@
   return 0;
 }
 
-static void handleLLVMFatalError(void *, const std::string &Message, bool) {
+static void handleLLVMFatalError(void *, const char *Message, bool) {
   // TODO: Would it be better to call into the fuzzer internals directly?
   dbgs() << "LLVM ERROR: " << Message << "\n"
  << "Aborting to trigger fuzzer exit handling.\n";
Index: llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
===
--- llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
+++ llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
@@ -107,7 +107,7 @@
   return 0;
 }
 
-static void handleLLVMFatalError(void *, const std::string &Message, bool) {
+static void handleLLVMFatalError(void *, const char *Message, bool) {
   // TODO: Would it be better to call into the fuzzer internals directly?
   dbgs() << "LLVM ERROR: " << Message << "\n"
  << "Aborting to trigger fuzzer exit handling.\n";
Index: llvm/lib/Support/ErrorHandling.cpp
===
--- llvm/lib/Support/ErrorHandling.cpp
+++ llvm/lib/Support/ErrorHandling.cpp
@@ -105,7 +105,7 @@
   }
 
   if (handler) {
-handler(handlerData, Reason.str(), GenCrashDiag);
+handler(handlerData, Reason.str().c_str(), GenCrashDiag);
   } else {
 // Blast the result out to stderr.  We don't try hard to make sure this
 // succeeds (e.g. handling EINTR) and we can't use errs() here because
@@ -218,11 +218,11 @@
 #endif
 }
 
-static void bindingsErrorHandler(void *user_data, const std::string& reason,
+static void bindingsErrorHandler(void *user_data, const char *reason,
  bool gen_crash_diag) {
   LLVMFatalErrorHandler handler =
   LLVM_EXTENSION reinterpret_cast(user_data);
-  handler(reason.c_str());
+  handler(reason);
 }
 
 void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler) {
Index: llvm/include/llvm/Support/ErrorHandling.h
===
--- llvm/include/llvm/Support/ErrorHandling.h
+++ llvm/include/llvm/Support/ErrorHandling.h
@@ -18,12 +18,12 @@
 #include 
 
 namespace llvm {
-class StringRef;
+  class StringRef;
   class Twine;
 
   /// An error handler callback.
   typedef void (*fatal_error_handler_t)(void *user_data,
-const std::string& reason,
+const char *reason,
 bool gen_crash_diag);
 
   /// install_fatal_error_handler - Installs a new error handler to be used
Index: clang/tools/libclang/FatalErrorHandler.cpp
===
--- clang/tools/libclang/FatalErrorHandler.cpp
+++ clang/tools/libclang/FatalErrorHandler.cpp
@@ -11,11 +11,11 @@
 #include "llvm/Support/ErrorHandling.h"
 #include 
 
-static void aborting_fatal_error_handler(void *, const std::string &reason,
+static void aborting_fatal_error_handler(void *, const char *reason,
  bool) {
   // Write the result out to stderr avoiding errs() because raw_ostreams can
   // call report_fatal_error.
-  fprintf(stderr, "LIBCLANG FATAL ERROR: %s\n", reason.c_str());
+  fprintf(stderr, "LIBCLANG FATAL ERROR: %s\n", reason);
   ::abort();
 }
 
Index: clang/tools/driver/cc1as_main.cpp
===

[PATCH] D111039: [clangd] Include refs of base method in refs for derived method.

2021-10-04 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/XRefs.cpp:1395
   if (CMD->isVirtual())
-if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) ==
-  IdentifierAtCursor->location()) {

kadircet wrote:
> it's important to note that this doesn't only suppress xrefs behaviour 
> outside of the declaration, but it also suppresses xrefs on parts of the 
> declaration apart from the function's name (like override/virtual keywords). 
> it's unfortunate that we don't have tests to explicitly point out that fact.
> I am not sure why the decision was to exclude them in the first place, I am 
> definitely in favor of the new behaviour (we already provide go-to-def on 
> `override` keyword for example, not having xrefs on it seems surprising). I 
> suppose @hokein can tell if there are any other concerns I am missing.
yeah, I think the initial design was to return all base-class references when 
xrefs is called at the *declaration* (our previous concern was that base-class 
refs might add a lot of noises to the final results, which might be not what 
users want). Now we have user complains, let's do it for all places (LG the 
change).

Re the behavior on override keyword, this is probably an oversight (xrefs was 
not considered when we extended go-to-def). The implementation of go-to-def is 
ad-hoc, and only works for `override`, and `final` keywords (due to the 
limitation of AST).  not sure it is a really useful feature, for consistency, 
it would be nice to have it in xrefs. I think it can be addressed in a 
follow-up patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111039

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


[PATCH] D111041: [clang-tidy] Remove 'IgnoreDestructors = true' from cppcoreguidelines-explicit-virtual-functions

2021-10-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D111041#3039637 , @carlosgalvezp 
wrote:

> Thanks for the input!
>
>> release note mentions
>
> Sure thing!
>
>> documentation changes
>
> As we discussed in the separate mail thread, there is no documentation at all 
> as to what default values an alias/main check has. Where should I put that? 
> Or do you mean that now that all 3 checks (primary + 2 aliases) have 
> identical defaults, I should document that in the main check documentation?

Ah, I see now -- we failed to mention in `modernize-use-override.rst` that the 
default value for this is `true` in 
`cppcoreguidelines-explicit-virtual-functions`. That's where I'd expect to see 
that documentation. I suppose now that documentation would no longer be 
necessary, so we're good here.

>> test coverage
>
> I was surprised to not find any unit test for this check, probably because 
> it's already done by the unit test of the "main check"? Should add a new unit 
> test, pretty much copy-pasting the test for the main check?

Erf, the lack of initial test coverage also makes me sad -- I would have 
expected `modernize-use-override-no-destructor.cpp` to have an additional `RUN` 
line to test the behavior of this check as well (which would have then failed 
with the changes). I'd say let's go ahead and add that as a test case; add 
another RUN line to run `cppcoreguidelines-explicit-virtual-functions` and give 
it a specific `FileCheck` prefix so that we can test we don't get the warning 
from `modernize` but we do get the warning from `cppcoreguidelines`. For an 
example of the FileCheck prefix I'm talking about, see the RUN lines in 
`cert-static-object-exceptions.cpp`.

>> evidence that this option is not being used by users
>
> Not sure how to go about this one :) I guess we can't have a 100% guarantee 
> that this won't break things for users, there will always be an edge case. 
> Perhaps we should document it very clearly in the Release Notes as well as 
> explaining how to revert to the old behavior if needed?

I think that'll be the best we can do.

> Since we are talking about a "guideline check" 
> (cppcoreguidelines-explicit-virtual-functions) and a "good practice check" 
> (modernize-use-override), I don't think it's unreasonable that users have 
> enabled both checks. If so, the "modernize" check should already have this 
> behavior as default and prompted users to make changes - the 
> cppcoreguidelines was less strict, and now it would be as strict as the 
> "modernize-use-override" check. In that scenario, this patch shouldn't break 
> things for users. The scenario that would break things for users is when they 
> only enable the cppcoreguidelines check alone.

Agreed; I'm worried about the people who enabled only the core guideline check 
getting new diagnostics they weren't expecting. However, that's what the core 
guidelines have decided they want, so I think it's reasonable to make the 
change.

> The guidelines changed in 2019, I think after 2 years users wouldn't mind the 
> tooling catching up :)
>
> Since I'm new here and missed quite a few things, do you know if there's a 
> checklist somewhere where I can read about what else I should include in the 
> patch?

I don't know if we have a checklist like that anywhere, but what reviewers are 
generally going to look for is: functionality of the patch itself, test 
coverage for the changes (unless the change is marked NFC, aka No Functional 
Change), documentation for the changes (if needed).

> but removing the option entirely feels user-hostile without some evidence 
> that this option is unused in practice.

Quoting myself here, but derp, this isn't removing the option entirely, just 
removing the fact that the default value is different, which is fine to do 
here. Sorry for the confusion on that!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111041

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


[PATCH] D110927: [analyzer] Access stored value of a constant array through a pointer to another type

2021-10-04 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

In D110927#3037118 , @shafik wrote:

> IIUC the object is `const int arr[42]` and the `(char *)arr` is an expression 
> of pointer type and adding `1` to this is valid. The case you refer to in 
> D104285  ended up being a pointer to an 
> array of 2 ints and therefore accessing the third element was out of bounds.

You are right. According to http://eel.is/c++draft/expr.add#4, expression `P + 
I` is valid while `0 ≤ I ≤ n`, UB otherwise. This is valid untill we try to 
dereference it. After that it becomes an UB. The UB's you and me are talking 
about have different origin.

My concern is whether we do it correctly considering that dereferencing of type 
**T** through other types are UB in certain cases. Namely, 
http://eel.is/c++draft/basic.lval#11 and 
http://eel.is/c++draft/basic.compound#3.4 paragraphs tell us:

  int arr[42];
  // same type
  auto x = ((int*)arr)[0]; // OK
  auto x = ((int*)arr)[1]; // OK
  auto x = ((int*)arr)[41]; // OK 
  
  // opposite signedness
  auto x = ((unsigned int*)arr)[0]; // OK
  auto x = ((unsigned int*)arr)[1]; // UB
  auto x = ((unsigned int*)arr)[41]; // UB
  
  // for char*, unsigned char* and std::byte*
  auto x = ((char*)arr)[0]; // OK
  auto x = ((char*)arr)[1]; // UB
  auto x = ((char*)arr)[41]; // UB
  
  using T= AllTheRestTypes;
  auto x = ((T*)arr)[0]; // UB
  auto x = ((T*)arr)[1]; // UB
  auto x = ((T*)arr)[41]; // UB


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

https://reviews.llvm.org/D110927

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


[PATCH] D107339: [analyzer] Retrieve a character from StringLiteral as an initializer for constant arrays.

2021-10-04 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1641
+  // FIXME: Take array dimension into account to prevent exceeding its size.
+  const int64_t I = Idx.getExtValue();
+  uint32_t Code =

martong wrote:
> steakhal wrote:
> > You could use the `uint64_t` type here, and spare the subsequent explicit 
> > cast. This operation would be safe since `Idx` must be non-negative here.
> +1 for using `uint64_t` if possible
`SL->getCodeUnit` returns `uint32_t`, so I decided to keep the result value 
consistent if any changes required in the future.


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

https://reviews.llvm.org/D107339

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


[PATCH] D107339: [analyzer] Retrieve a character from StringLiteral as an initializer for constant arrays.

2021-10-04 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1641
+  // FIXME: Take array dimension into account to prevent exceeding its size.
+  const int64_t I = Idx.getExtValue();
+  uint32_t Code =

ASDenysPetrov wrote:
> martong wrote:
> > steakhal wrote:
> > > You could use the `uint64_t` type here, and spare the subsequent explicit 
> > > cast. This operation would be safe since `Idx` must be non-negative here.
> > +1 for using `uint64_t` if possible
> `SL->getCodeUnit` returns `uint32_t`, so I decided to keep the result value 
> consistent if any changes required in the future.
Oh. discard my previous reply. I mistakenly considered a wrong line.
The correct reply:
As you can see, preceding condition `(Idx < 0)` guarantee `Idx` to be 
non-negative. But if you suggest this to be explicitly visible, then OK, I 
don't mind. I've just kept it `int64_t` for consistency with return value as 
well.


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

https://reviews.llvm.org/D107339

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


[clang] bfc8f9e - [clang] Fix computation of number of dependencies using OpenMP iterator,

2021-10-04 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2021-10-04T07:06:51-07:00
New Revision: bfc8f9e9b0bd2279ee3398ee62f255360a89f0e9

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

LOG: [clang] Fix computation of number of dependencies using OpenMP iterator,
by Raul Penacoba.

The size of kmp_depend_info and the number of dependencies are computed 
multiplying the iterator sizes, which not right.
Now size is computed as:

itersize1*numclausedeps1 + itersize2*numclausedeps2 + ... + 
itersizeN*numclausedepsN

where itersizeX is the size of the iterator and numclausedepsX the number of 
dependencies in that depend clause.

Reviewed By: ABataev

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

Added: 
clang/test/OpenMP/depend_iterator_bug.c

Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/task_codegen.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 5276200f47a6d..e51d196b870ff 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -4882,7 +4882,7 @@ std::pair 
CGOpenMPRuntime::emitDependClause(
   bool HasRegularWithIterators = false;
   llvm::Value *NumOfDepobjElements = llvm::ConstantInt::get(CGF.IntPtrTy, 0);
   llvm::Value *NumOfRegularWithIterators =
-  llvm::ConstantInt::get(CGF.IntPtrTy, 1);
+  llvm::ConstantInt::get(CGF.IntPtrTy, 0);
   // Calculate number of depobj dependecies and regular deps with the 
iterators.
   for (const OMPTaskDataTy::DependData &D : Dependencies) {
 if (D.DepKind == OMPC_DEPEND_depobj) {
@@ -4896,12 +4896,15 @@ std::pair 
CGOpenMPRuntime::emitDependClause(
   continue;
 }
 // Include number of iterations, if any.
+
 if (const auto *IE = cast_or_null(D.IteratorExpr)) {
   for (unsigned I = 0, E = IE->numOfIterators(); I < E; ++I) {
 llvm::Value *Sz = CGF.EmitScalarExpr(IE->getHelper(I).Upper);
 Sz = CGF.Builder.CreateIntCast(Sz, CGF.IntPtrTy, /*isSigned=*/false);
+llvm::Value *NumClauseDeps = CGF.Builder.CreateNUWMul(
+Sz, llvm::ConstantInt::get(CGF.IntPtrTy, D.DepExprs.size()));
 NumOfRegularWithIterators =
-CGF.Builder.CreateNUWMul(NumOfRegularWithIterators, Sz);
+CGF.Builder.CreateNUWAdd(NumOfRegularWithIterators, NumClauseDeps);
   }
   HasRegularWithIterators = true;
   continue;

diff  --git a/clang/test/OpenMP/depend_iterator_bug.c 
b/clang/test/OpenMP/depend_iterator_bug.c
new file mode 100644
index 0..b7470f0037616
--- /dev/null
+++ b/clang/test/OpenMP/depend_iterator_bug.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-linux-gnu \
+// RUN:   -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
+
+// expected-no-diagnostics
+
+int x[100];
+int y[100];
+
+// CHECK-LABEL: @many_iterators_single_clause(
+// CHECK:[[VLA:%.*]] = alloca [[STRUCT_KMP_DEPEND_INFO:%.*]], i64 10, 
align 16
+// CHECK:= call i32 @__kmpc_omp_task_with_deps(%struct.ident_t* {{.*}}, 
i32 {{.*}}, i8* {{.*}}, i32 10, i8* {{.*}}, i32 0, i8* null)
+void many_iterators_single_clause() {
+#pragma omp task depend(iterator(j=0:5), in: x[j], y[j])
+{
+}
+}
+
+// CHECK-LABEL: @many_iterators_many_clauses(
+// CHECK:[[VLA:%.*]] = alloca [[STRUCT_KMP_DEPEND_INFO:%.*]], i64 10, 
align 16
+// CHECK:= call i32 @__kmpc_omp_task_with_deps(%struct.ident_t* {{.*}}, 
i32 {{.*}}, i8* {{.*}}, i32 10, i8* {{.*}}, i32 0, i8* null)
+void many_iterators_many_clauses() {
+#pragma omp task depend(iterator(j=0:5), in: x[j]) \
+ depend(iterator(j=0:5), in: y[j])
+{
+}
+}

diff  --git a/clang/test/OpenMP/task_codegen.c 
b/clang/test/OpenMP/task_codegen.c
index f53fd75f67009..d813ba21f8f32 100644
--- a/clang/test/OpenMP/task_codegen.c
+++ b/clang/test/OpenMP/task_codegen.c
@@ -150,10 +150,12 @@ for (int i = 0; i < 10; ++i)
   // CHECK: [[EB_SUB_2_ADD_1_SUB:%.+]] = sub i32 [[EB_SUB_2_ADD]], 1
   // CHECK: [[EB_SUB_2_ADD_1_SUB_2_DIV:%.+]] = udiv i32 
[[EB_SUB_2_ADD_1_SUB]], 2
   // CHECK: [[ELEMS:%.+]] = zext i32 [[EB_SUB_2_ADD_1_SUB_2_DIV]] to i64
-  // CHECK: [[NELEMS:%.+]] = mul nuw i64 1, [[ELEMS]]
+  // CHECK: [[NELEMS:%.+]] = mul nuw i64 [[ELEMS]], 1
 
-  // TOTAL_NUMBER_OF_ELEMENTS = NELEMS + 0;
-  // CHECK: [[TOTAL:%.+]] = add nuw i64 [[NELEMS]], 0
+  // ITERATOR_TOTAL = NELEMS + 0;
+  // CHECK: [[ITERATOR_TOTAL:%.+]] = add nuw i64 0, [[NELEMS]]
+  // NELEMS = ITERATOR_TOTAL + non-iterator-deps (=0)
+  // CHECK: [[TOTAL:%.+]] = add nuw i64 [[ITERATOR_TOTAL]], 0
 
   // %struct.kmp_depend_info DEPS[TOTAL];
   // CHECK: [[DEPS:%.+]] = alloca %struct.kmp_depend_info, i64 [[TOTAL]],



___
cfe-commits mailing list
cfe-c

[PATCH] D111045: [clang] Fix computation of number of dependencies using OpenMP iterator

2021-10-04 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbfc8f9e9b0bd: [clang] Fix computation of number of 
dependencies using OpenMP iterator, (authored by ABataev).
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111045

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/depend_iterator_bug.c
  clang/test/OpenMP/task_codegen.c


Index: clang/test/OpenMP/task_codegen.c
===
--- clang/test/OpenMP/task_codegen.c
+++ clang/test/OpenMP/task_codegen.c
@@ -150,10 +150,12 @@
   // CHECK: [[EB_SUB_2_ADD_1_SUB:%.+]] = sub i32 [[EB_SUB_2_ADD]], 1
   // CHECK: [[EB_SUB_2_ADD_1_SUB_2_DIV:%.+]] = udiv i32 
[[EB_SUB_2_ADD_1_SUB]], 2
   // CHECK: [[ELEMS:%.+]] = zext i32 [[EB_SUB_2_ADD_1_SUB_2_DIV]] to i64
-  // CHECK: [[NELEMS:%.+]] = mul nuw i64 1, [[ELEMS]]
+  // CHECK: [[NELEMS:%.+]] = mul nuw i64 [[ELEMS]], 1
 
-  // TOTAL_NUMBER_OF_ELEMENTS = NELEMS + 0;
-  // CHECK: [[TOTAL:%.+]] = add nuw i64 [[NELEMS]], 0
+  // ITERATOR_TOTAL = NELEMS + 0;
+  // CHECK: [[ITERATOR_TOTAL:%.+]] = add nuw i64 0, [[NELEMS]]
+  // NELEMS = ITERATOR_TOTAL + non-iterator-deps (=0)
+  // CHECK: [[TOTAL:%.+]] = add nuw i64 [[ITERATOR_TOTAL]], 0
 
   // %struct.kmp_depend_info DEPS[TOTAL];
   // CHECK: [[DEPS:%.+]] = alloca %struct.kmp_depend_info, i64 [[TOTAL]],
Index: clang/test/OpenMP/depend_iterator_bug.c
===
--- /dev/null
+++ clang/test/OpenMP/depend_iterator_bug.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-linux-gnu \
+// RUN:   -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
+
+// expected-no-diagnostics
+
+int x[100];
+int y[100];
+
+// CHECK-LABEL: @many_iterators_single_clause(
+// CHECK:[[VLA:%.*]] = alloca [[STRUCT_KMP_DEPEND_INFO:%.*]], i64 10, 
align 16
+// CHECK:= call i32 @__kmpc_omp_task_with_deps(%struct.ident_t* {{.*}}, 
i32 {{.*}}, i8* {{.*}}, i32 10, i8* {{.*}}, i32 0, i8* null)
+void many_iterators_single_clause() {
+#pragma omp task depend(iterator(j=0:5), in: x[j], y[j])
+{
+}
+}
+
+// CHECK-LABEL: @many_iterators_many_clauses(
+// CHECK:[[VLA:%.*]] = alloca [[STRUCT_KMP_DEPEND_INFO:%.*]], i64 10, 
align 16
+// CHECK:= call i32 @__kmpc_omp_task_with_deps(%struct.ident_t* {{.*}}, 
i32 {{.*}}, i8* {{.*}}, i32 10, i8* {{.*}}, i32 0, i8* null)
+void many_iterators_many_clauses() {
+#pragma omp task depend(iterator(j=0:5), in: x[j]) \
+ depend(iterator(j=0:5), in: y[j])
+{
+}
+}
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -4882,7 +4882,7 @@
   bool HasRegularWithIterators = false;
   llvm::Value *NumOfDepobjElements = llvm::ConstantInt::get(CGF.IntPtrTy, 0);
   llvm::Value *NumOfRegularWithIterators =
-  llvm::ConstantInt::get(CGF.IntPtrTy, 1);
+  llvm::ConstantInt::get(CGF.IntPtrTy, 0);
   // Calculate number of depobj dependecies and regular deps with the 
iterators.
   for (const OMPTaskDataTy::DependData &D : Dependencies) {
 if (D.DepKind == OMPC_DEPEND_depobj) {
@@ -4896,12 +4896,15 @@
   continue;
 }
 // Include number of iterations, if any.
+
 if (const auto *IE = cast_or_null(D.IteratorExpr)) {
   for (unsigned I = 0, E = IE->numOfIterators(); I < E; ++I) {
 llvm::Value *Sz = CGF.EmitScalarExpr(IE->getHelper(I).Upper);
 Sz = CGF.Builder.CreateIntCast(Sz, CGF.IntPtrTy, /*isSigned=*/false);
+llvm::Value *NumClauseDeps = CGF.Builder.CreateNUWMul(
+Sz, llvm::ConstantInt::get(CGF.IntPtrTy, D.DepExprs.size()));
 NumOfRegularWithIterators =
-CGF.Builder.CreateNUWMul(NumOfRegularWithIterators, Sz);
+CGF.Builder.CreateNUWAdd(NumOfRegularWithIterators, NumClauseDeps);
   }
   HasRegularWithIterators = true;
   continue;


Index: clang/test/OpenMP/task_codegen.c
===
--- clang/test/OpenMP/task_codegen.c
+++ clang/test/OpenMP/task_codegen.c
@@ -150,10 +150,12 @@
   // CHECK: [[EB_SUB_2_ADD_1_SUB:%.+]] = sub i32 [[EB_SUB_2_ADD]], 1
   // CHECK: [[EB_SUB_2_ADD_1_SUB_2_DIV:%.+]] = udiv i32 [[EB_SUB_2_ADD_1_SUB]], 2
   // CHECK: [[ELEMS:%.+]] = zext i32 [[EB_SUB_2_ADD_1_SUB_2_DIV]] to i64
-  // CHECK: [[NELEMS:%.+]] = mul nuw i64 1, [[ELEMS]]
+  // CHECK: [[NELEMS:%.+]] = mul nuw i64 [[ELEMS]], 1
 
-  // TOTAL_NUMBER_OF_ELEMENTS = NELEMS + 0;
-  // CHECK: [[TOTAL:%.+]] = add nuw i64 [[NELEMS]], 0
+  // ITERATOR_TOTAL = NELEMS + 0;
+  // CHECK: [[ITERATOR_TOTAL:%.+]] = add nuw i64 0, [[NELEMS]]
+  // NELEMS = ITERATOR_TOTAL + non-iterator-deps (=0)
+  // CHECK: [[TOTAL:%.+]] = add nuw i64 [[ITERATOR_TOTAL

[clang-tools-extra] a90d57b - [clangd] Improve PopulateSwitch tweak

2021-10-04 Thread David Goldman via cfe-commits

Author: David Goldman
Date: 2021-10-04T10:15:37-04:00
New Revision: a90d57b6cc5f1237199fa6974eeb1cb168a7aed3

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

LOG: [clangd] Improve PopulateSwitch tweak

- Support enums in C and ObjC as their
  AST representations differ slightly.

- Add support for typedef'ed enums.

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

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
index 40af43fef4aaf..4e2b15b8f22af 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
@@ -113,7 +113,8 @@ bool PopulateSwitch::prepare(const Selection &Sel) {
 return false;
   // Ignore implicit casts, since enums implicitly cast to integer types.
   Cond = Cond->IgnoreParenImpCasts();
-  EnumT = Cond->getType()->getAsAdjusted();
+  // Get the canonical type to handle typedefs.
+  EnumT = Cond->getType().getCanonicalType()->getAsAdjusted();
   if (!EnumT)
 return false;
   EnumD = EnumT->getDecl();
@@ -152,14 +153,30 @@ bool PopulateSwitch::prepare(const Selection &Sel) {
 if (CS->caseStmtIsGNURange())
   return false;
 
+// Support for direct references to enum constants. This is required to
+// support C and ObjC which don't contain values in their ConstantExprs.
+// The general way to get the value of a case is EvaluateAsRValue, but we'd
+// rather not deal with that in case the AST is broken.
+if (auto *DRE = dyn_cast(CS->getLHS()->IgnoreParenCasts())) {
+  if (auto *Enumerator = dyn_cast(DRE->getDecl())) {
+auto Iter = ExpectedCases.find(Normalize(Enumerator->getInitVal()));
+if (Iter != ExpectedCases.end())
+  Iter->second.setCovered();
+continue;
+  }
+}
+
+// ConstantExprs with values are expected for C++, otherwise the storage
+// kind will be None.
+
 // Case expression is not a constant expression or is value-dependent,
 // so we may not be able to work out which cases are covered.
 const ConstantExpr *CE = dyn_cast(CS->getLHS());
 if (!CE || CE->isValueDependent())
   return false;
 
-// Unsure if this case could ever come up, but prevents an unreachable
-// executing in getResultAsAPSInt.
+// We need a stored value in order to continue; currently both C and ObjC
+// enums won't have one.
 if (CE->getResultStorageKind() == ConstantExpr::RSK_None)
   return false;
 auto Iter = ExpectedCases.find(Normalize(CE->getResultAsAPSInt()));

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
index 13277c99cc314..05833736f3113 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
@@ -23,6 +23,7 @@ TEST_F(PopulateSwitchTest, Test) {
 CodeContext Context;
 llvm::StringRef TestSource;
 llvm::StringRef ExpectedSource;
+llvm::StringRef FileName = "TestTU.cpp";
   };
 
   Case Cases[]{
@@ -206,10 +207,43 @@ TEST_F(PopulateSwitchTest, Test) {
   R""(template void f() {enum Enum {A}; ^switch (A) {}})"",
   "unavailable",
   },
+  {// C: Only filling in missing enumerators
+   Function,
+   R""(
+enum CEnum {A,B,C};
+enum CEnum val = A;
+^switch (val) {case B:break;}
+  )"",
+   R""(
+enum CEnum {A,B,C};
+enum CEnum val = A;
+switch (val) {case B:break;case A:case C:break;}
+  )"",
+   "TestTU.c"},
+  {// C: Only filling in missing enumerators w/ typedefs
+   Function,
+   R""(
+typedef unsigned long UInteger;
+enum ControlState : UInteger;
+typedef enum ControlState ControlState;
+enum ControlState : UInteger {A,B,C};
+ControlState controlState = A;
+switch (^controlState) {case A:break;}
+  )"",
+   R""(
+typedef unsigned long UInteger;
+enum ControlState : UInteger;
+typedef enum ControlState ControlState;
+enum ControlState : UInteger {A,B,C};
+ControlState controlState = A;
+switch (controlState) {case A:break;case B:case C:break;}
+  )"",
+   "TestTU.c"},
   };
 
   for (const auto &Case : Cases) {
 Context = Case.Context;
+FileName = Case.FileName;
 EXPECT_EQ(apply(Case.T

[PATCH] D110954: [clangd] Improve PopulateSwitch tweak

2021-10-04 Thread David Goldman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa90d57b6cc5f: [clangd] Improve PopulateSwitch tweak 
(authored by dgoldman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110954

Files:
  clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
  clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
@@ -23,6 +23,7 @@
 CodeContext Context;
 llvm::StringRef TestSource;
 llvm::StringRef ExpectedSource;
+llvm::StringRef FileName = "TestTU.cpp";
   };
 
   Case Cases[]{
@@ -206,10 +207,43 @@
   R""(template void f() {enum Enum {A}; ^switch (A) {}})"",
   "unavailable",
   },
+  {// C: Only filling in missing enumerators
+   Function,
+   R""(
+enum CEnum {A,B,C};
+enum CEnum val = A;
+^switch (val) {case B:break;}
+  )"",
+   R""(
+enum CEnum {A,B,C};
+enum CEnum val = A;
+switch (val) {case B:break;case A:case C:break;}
+  )"",
+   "TestTU.c"},
+  {// C: Only filling in missing enumerators w/ typedefs
+   Function,
+   R""(
+typedef unsigned long UInteger;
+enum ControlState : UInteger;
+typedef enum ControlState ControlState;
+enum ControlState : UInteger {A,B,C};
+ControlState controlState = A;
+switch (^controlState) {case A:break;}
+  )"",
+   R""(
+typedef unsigned long UInteger;
+enum ControlState : UInteger;
+typedef enum ControlState ControlState;
+enum ControlState : UInteger {A,B,C};
+ControlState controlState = A;
+switch (controlState) {case A:break;case B:case C:break;}
+  )"",
+   "TestTU.c"},
   };
 
   for (const auto &Case : Cases) {
 Context = Case.Context;
+FileName = Case.FileName;
 EXPECT_EQ(apply(Case.TestSource), Case.ExpectedSource);
   }
 }
Index: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
@@ -113,7 +113,8 @@
 return false;
   // Ignore implicit casts, since enums implicitly cast to integer types.
   Cond = Cond->IgnoreParenImpCasts();
-  EnumT = Cond->getType()->getAsAdjusted();
+  // Get the canonical type to handle typedefs.
+  EnumT = Cond->getType().getCanonicalType()->getAsAdjusted();
   if (!EnumT)
 return false;
   EnumD = EnumT->getDecl();
@@ -152,14 +153,30 @@
 if (CS->caseStmtIsGNURange())
   return false;
 
+// Support for direct references to enum constants. This is required to
+// support C and ObjC which don't contain values in their ConstantExprs.
+// The general way to get the value of a case is EvaluateAsRValue, but we'd
+// rather not deal with that in case the AST is broken.
+if (auto *DRE = dyn_cast(CS->getLHS()->IgnoreParenCasts())) {
+  if (auto *Enumerator = dyn_cast(DRE->getDecl())) {
+auto Iter = ExpectedCases.find(Normalize(Enumerator->getInitVal()));
+if (Iter != ExpectedCases.end())
+  Iter->second.setCovered();
+continue;
+  }
+}
+
+// ConstantExprs with values are expected for C++, otherwise the storage
+// kind will be None.
+
 // Case expression is not a constant expression or is value-dependent,
 // so we may not be able to work out which cases are covered.
 const ConstantExpr *CE = dyn_cast(CS->getLHS());
 if (!CE || CE->isValueDependent())
   return false;
 
-// Unsure if this case could ever come up, but prevents an unreachable
-// executing in getResultAsAPSInt.
+// We need a stored value in order to continue; currently both C and ObjC
+// enums won't have one.
 if (CE->getResultStorageKind() == ConstantExpr::RSK_None)
   return false;
 auto Iter = ExpectedCases.find(Normalize(CE->getResultAsAPSInt()));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107339: [analyzer] Retrieve a character from StringLiteral as an initializer for constant arrays.

2021-10-04 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/test/Analysis/initialization.cpp:132
+
+char const glob_arr6[5] = "123";
+void glob_array_index4() {

steakhal wrote:
> Ah, it's somewhat confusing.
> At first, when I looked at it, I assumed that this array has `6` elements as 
> its name suggests.
> But it has actually 5 elements.
`6` in `glob_arr6` is like a serial number. Means that there are `glob_arr5` 
and `glob_arr4` and so for above.



Comment at: clang/test/Analysis/initialization.cpp:156-157
+void glob_invalid_index7() {
+  int idx = -42;
+  auto x = glob_arr6[idx]; // expected-warning{{garbage or undefined}}
+}

steakhal wrote:
> You could inline the `-42` without changing any expected behavior.
> It would make the test terser IMO. The same applies to the other case.
`glob_arr6[-42]` this provokes AST parser to emit a warning before reaching to 
CSA checks. Separate variable allows to avoid AST parser checks to let CSA be 
engaged.



Comment at: clang/test/Analysis/initialization.cpp:160-166
+// TODO: Support multidimensional array.
+void glob_invalid_index8() {
+  const char *ptr = glob_arr6;
+  int idx = 42;
+  // FIXME: Should warn {{garbage or undefined}}.
+  auto x = ptr[idx]; // no-warning
+}

steakhal wrote:
> I'm not sure if I follow. The `TODO` implies to me that this case is about 
> //multidimensional  array//s, but it's actually not.
> `glob_arr6` is of type `const char[5]`
> Could you clarify this?
> BTW, at first glance, the gist of this case is the same as the 
> `glob_invalid_index7`.
> Why does this behave differently? I'm puzzled.
Correct. Thanks! The consequence of copy-paste. I'll fix.


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

https://reviews.llvm.org/D107339

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


[PATCH] D110684: [RISCV] Define _m intrinsics as builtins, instead of macros.

2021-10-04 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai updated this revision to Diff 376890.
HsiangKai added a comment.

Update test cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110684

Files:
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Basic/riscv_vector.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vaadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vamoadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vamoand.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vamomax.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vamomin.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vamoor.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vamoswap.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vamoxor.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vand.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vasub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vcompress.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vdiv.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfabs.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfclass.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfcvt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfdiv.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfirst.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmax.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmin.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmul.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmv.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfncvt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfneg.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfrdiv.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfrec7.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfrsqrt7.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfrsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfsgnj.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfslide1down.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfslide1up.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfsqrt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwcvt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwmul.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vget.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vle.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vlmul.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vloxei.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vloxseg.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vlse.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vlseg.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vlsseg.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vluxei.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vluxseg.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmand.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmax.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfeq.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfge.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfgt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfle.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmflt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmfne.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmin.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmmv.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmnand.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmnor.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmnot.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmor.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsbc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsbf.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmseq.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsge.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsgt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsif.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsle.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmslt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsne.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsof.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmul.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmxnor.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmxor.c
  clang/test/C

[PATCH] D108301: [MSP430][Clang] Update hard-coded MCU data

2021-10-04 Thread Jozef Lawrynowicz via Phabricator via cfe-commits
jozefl added a comment.

Ping.

Thanks,
Jozef


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108301

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


[PATCH] D107339: [analyzer] Retrieve a character from StringLiteral as an initializer for constant arrays.

2021-10-04 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 376896.
ASDenysPetrov added a comment.

Updated according to suggestions.


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

https://reviews.llvm.org/D107339

Files:
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/initialization.cpp

Index: clang/test/Analysis/initialization.cpp
===
--- clang/test/Analysis/initialization.cpp
+++ clang/test/Analysis/initialization.cpp
@@ -128,3 +128,38 @@
   // FIXME: Should warn {{garbage or undefined}}.
   auto x = ptr[idx]; // // no-warning
 }
+
+char const glob_arr6[5] = "123";
+void glob_array_index4() {
+  clang_analyzer_eval(glob_arr6[0] == '1');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr6[1] == '2');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr6[2] == '3');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr6[3] == '\0'); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr6[4] == '\0'); // expected-warning{{TRUE}}
+}
+
+void glob_ptr_index3() {
+  char const *ptr = glob_arr6;
+  clang_analyzer_eval(ptr[-42] == '\0'); // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[0] == '1');// expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == '2');// expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == '3');// expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[3] == '\0');   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[4] == '\0');   // expected-warning{{TRUE}}
+  // FIXME: Should be UNDEFINED.
+  clang_analyzer_eval(ptr[5] == '\0'); // expected-warning{{TRUE}}
+  // FIXME: Should be UNDEFINED.
+  clang_analyzer_eval(ptr[6] == '\0'); // expected-warning{{TRUE}}
+}
+
+void glob_invalid_index7() {
+  int idx = -42;
+  auto x = glob_arr6[idx]; // expected-warning{{garbage or undefined}}
+}
+
+void glob_invalid_index8() {
+  const char *ptr = glob_arr6;
+  int idx = 42;
+  // FIXME: Ideally should warn {{garbage or undefined}}.
+  auto x = ptr[idx]; // no-warning
+}
Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -573,6 +573,8 @@
   SVal getBindingForFieldOrElementCommon(RegionBindingsConstRef B,
  const TypedValueRegion *R,
  QualType Ty);
+  SVal getSValFromStringLiteralByIndex(const StringLiteral *SL,
+   const llvm::APSInt &Idx, QualType ElemT);
 
   SVal getLazyBinding(const SubRegion *LazyBindingRegion,
   RegionBindingsRef LazyBinding);
@@ -1625,6 +1627,25 @@
   return Result;
 }
 
+SVal RegionStoreManager::getSValFromStringLiteralByIndex(
+const StringLiteral *SL, const llvm::APSInt &Idx, QualType ElemT) {
+  assert(SL && "StringLiteral should not be null");
+  // If index is out of bounds, return Undef.
+  if (Idx < 0)
+return UndefinedVal();
+  // Technically, only i == length is guaranteed to be null.
+  // However, such overflows should be caught before reaching this point;
+  // the only time such an access would be made is if a string literal was
+  // used to initialize a larger array.
+  // FIXME: Take array dimension into account to prevent exceeding its size.
+  //
+  // Previous check for `Idx < 0` guarantee that `Idx` is non-negative.
+  const auto I = static_cast(Idx.getExtValue());
+  uint32_t Code =
+  (static_cast(I) >= SL->getLength()) ? 0 : SL->getCodeUnit(I);
+  return svalBuilder.makeIntVal(Code, ElemT);
+}
+
 SVal RegionStoreManager::getBindingForElement(RegionBindingsConstRef B,
   const ElementRegion* R) {
   // Check if the region has a binding.
@@ -1636,26 +1657,16 @@
   // Check if the region is an element region of a string literal.
   if (const StringRegion *StrR = dyn_cast(superR)) {
 // FIXME: Handle loads from strings where the literal is treated as
-// an integer, e.g., *((unsigned int*)"hello")
+// an integer, e.g., *((unsigned int*)"hello"). Such loads are UB according
+// to C++20 7.2.1.11 [basic.lval].
 QualType T = Ctx.getAsArrayType(StrR->getValueType())->getElementType();
 if (!Ctx.hasSameUnqualifiedType(T, R->getElementType()))
   return UnknownVal();
 
-const StringLiteral *Str = StrR->getStringLiteral();
 SVal Idx = R->getIndex();
 if (Optional CI = Idx.getAs()) {
-  int64_t i = CI->getValue().getSExtValue();
-  // Abort on string underrun.  This can be possible by arbitrary
-  // clients of getBindingForElement().
-  if (i < 0)
-return UndefinedVal();
-  int64_t length = Str->getLength();
-  // Technically, only i == length is guaranteed to be null.
-  // However, such overflows should be caught before reaching this point;
-  // the only time such an acc

[PATCH] D110586: Update `DynTypedNode` to support the conversion of `TypeLoc`s.

2021-10-04 Thread James King via Phabricator via cfe-commits
jcking1034 updated this revision to Diff 376901.
jcking1034 marked an inline comment as done.
jcking1034 added a comment.

Update unit test to better exercise `getNodeAs`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110586

Files:
  clang/include/clang/AST/ASTTypeTraits.h
  clang/lib/AST/ASTTypeTraits.cpp
  clang/unittests/AST/ASTTypeTraitsTest.cpp

Index: clang/unittests/AST/ASTTypeTraitsTest.cpp
===
--- clang/unittests/AST/ASTTypeTraitsTest.cpp
+++ clang/unittests/AST/ASTTypeTraitsTest.cpp
@@ -199,5 +199,40 @@
   EXPECT_FALSE(Node < Node);
 }
 
+TEST(DynTypedNode, TypeLoc) {
+  std::string code = R"cc(void example() { int abc; })cc";
+  auto AST = clang::tooling::buildASTFromCode(code);
+  auto matches =
+  match(traverse(TK_AsIs,
+ varDecl(hasName("abc"), hasTypeLoc(typeLoc().bind("tl",
+AST->getASTContext());
+  EXPECT_EQ(matches.size(), 1u);
+
+  const auto &tl = *matches[0].getNodeAs("tl");
+  DynTypedNode Node = DynTypedNode::create(tl);
+  EXPECT_TRUE(Node == Node);
+  EXPECT_FALSE(Node < Node);
+}
+
+TEST(DynTypedNode, PointerTypeLoc) {
+  std::string code = R"cc(void example() { int* abc; })cc";
+  auto AST = clang::tooling::buildASTFromCode(code);
+  auto matches =
+  match(traverse(TK_AsIs, varDecl(hasName("abc"),
+  hasTypeLoc(typeLoc().bind("ptl",
+AST->getASTContext());
+  EXPECT_EQ(matches.size(), 1u);
+
+  const auto &tl = *matches[0].getNodeAs("ptl");
+  DynTypedNode TypeLocNode = DynTypedNode::create(tl);
+  EXPECT_TRUE(TypeLocNode == TypeLocNode);
+  EXPECT_FALSE(TypeLocNode < TypeLocNode);
+
+  const auto &ptl = *matches[0].getNodeAs("ptl");
+  DynTypedNode PointerTypeLocNode = DynTypedNode::create(ptl);
+  EXPECT_TRUE(PointerTypeLocNode == PointerTypeLocNode);
+  EXPECT_FALSE(PointerTypeLocNode < PointerTypeLocNode);
+}
+
 } // namespace
 }  // namespace clang
Index: clang/lib/AST/ASTTypeTraits.cpp
===
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OpenMPClause.h"
+#include "clang/AST/TypeLoc.h"
 
 using namespace clang;
 
@@ -28,6 +29,8 @@
 {NKI_None, "TemplateName"},
 {NKI_None, "NestedNameSpecifierLoc"},
 {NKI_None, "QualType"},
+#define TYPELOC(CLASS, PARENT) {NKI_##PARENT, #CLASS "TypeLoc"},
+#include "clang/AST/TypeLocNodes.def"
 {NKI_None, "TypeLoc"},
 {NKI_None, "CXXBaseSpecifier"},
 {NKI_None, "CXXCtorInitializer"},
@@ -127,6 +130,17 @@
   llvm_unreachable("invalid type kind");
  }
 
+ ASTNodeKind ASTNodeKind::getFromNode(const TypeLoc &T) {
+   switch (T.getTypeLocClass()) {
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
+#define TYPELOC(CLASS, PARENT) \
+  case TypeLoc::CLASS: \
+return ASTNodeKind(NKI_##CLASS##TypeLoc);
+#include "clang/AST/TypeLocNodes.def"
+   }
+   llvm_unreachable("invalid typeloc kind");
+ }
+
 ASTNodeKind ASTNodeKind::getFromNode(const OMPClause &C) {
   switch (C.getClauseKind()) {
 #define GEN_CLANG_CLAUSE_CLASS
Index: clang/include/clang/AST/ASTTypeTraits.h
===
--- clang/include/clang/AST/ASTTypeTraits.h
+++ clang/include/clang/AST/ASTTypeTraits.h
@@ -63,6 +63,7 @@
   static ASTNodeKind getFromNode(const Decl &D);
   static ASTNodeKind getFromNode(const Stmt &S);
   static ASTNodeKind getFromNode(const Type &T);
+  static ASTNodeKind getFromNode(const TypeLoc &T);
   static ASTNodeKind getFromNode(const OMPClause &C);
   static ASTNodeKind getFromNode(const Attr &A);
   /// \}
@@ -133,6 +134,8 @@
 NKI_TemplateName,
 NKI_NestedNameSpecifierLoc,
 NKI_QualType,
+#define TYPELOC(CLASS, PARENT) NKI_##CLASS##TypeLoc,
+#include "clang/AST/TypeLocNodes.def"
 NKI_TypeLoc,
 NKI_LastKindWithoutPointerIdentity = NKI_TypeLoc,
 NKI_CXXBaseSpecifier,
@@ -198,6 +201,8 @@
 KIND_TO_KIND_ID(NestedNameSpecifier)
 KIND_TO_KIND_ID(NestedNameSpecifierLoc)
 KIND_TO_KIND_ID(QualType)
+#define TYPELOC(CLASS, PARENT) KIND_TO_KIND_ID(CLASS##TypeLoc)
+#include "clang/AST/TypeLocNodes.def"
 KIND_TO_KIND_ID(TypeLoc)
 KIND_TO_KIND_ID(Decl)
 KIND_TO_KIND_ID(Stmt)
@@ -304,7 +309,7 @@
   return getUnchecked().getAsOpaquePtr() <
  Other.getUnchecked().getAsOpaquePtr();
 
-if (ASTNodeKind::getFromNodeKind().isSame(NodeKind)) {
+if (ASTNodeKind::getFromNodeKind().isBaseOf(NodeKind)) {
   auto TLA = getUnchecked();
   auto TLB = Other.getUnchecked();
   return std::make_pair(TLA.getType().getAsOpaquePtr(),
@@ -336,7 +341,7 @@
 if (ASTNodeKind::getFromNodeKind().isSame(NodeKind))
   return

[PATCH] D110586: Update `DynTypedNode` to support the conversion of `TypeLoc`s.

2021-10-04 Thread James King via Phabricator via cfe-commits
jcking1034 marked an inline comment as not done.
jcking1034 added inline comments.



Comment at: clang/unittests/AST/ASTTypeTraitsTest.cpp:212
+  DynTypedNode Node = DynTypedNode::create(tl);
+  EXPECT_TRUE(Node == Node);
+  EXPECT_FALSE(Node < Node);

sbenza wrote:
> I don't know what we are trying to check with this self equivalence.
> Did you mean `Node == tl`?
These two `EXPECT`s are meant to ensure that the overloaded equality and 
less-than operators do function correctly when handling nodes of the `TypeLoc` 
family. In both cases, there is behavior specifically for these nodes, and I've 
made minor updates to both (changing `isSame` to `isBaseOf`). Additionally, 
this may give a little more confidence that template specialization functioned 
correctly. I will note that the `QualType` test performs a similar set of 
checks, presumably for similar reasoning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110586

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


[clang] 811b173 - [analyzer] Add InvalidPtrChecker

2021-10-04 Thread Zurab Tsinadze via cfe-commits

Author: Zurab Tsinadze
Date: 2021-10-04T17:08:34+02:00
New Revision: 811b1736d91b301f59fbaa148ff55c32f90a3947

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

LOG: [analyzer] Add InvalidPtrChecker

This patch introduces a new checker: `alpha.security.cert.env.InvalidPtr`

Checker finds usage of invalidated pointers related to environment.

Based on the following SEI CERT Rules:
ENV34-C: https://wiki.sei.cmu.edu/confluence/x/8tYxBQ
ENV31-C: https://wiki.sei.cmu.edu/confluence/x/5NUxBQ

Reviewed By: martong

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

Added: 
clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
clang/test/Analysis/cert/env31-c.c
clang/test/Analysis/cert/env34-c-cert-examples.c
clang/test/Analysis/cert/env34-c.c

Modified: 
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 89190b54e5a51..a0c207b974678 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2075,10 +2075,63 @@ Finds calls to the ``putenv`` function which pass a 
pointer to an automatic vari
 if (retval < 0 || (size_t)retval >= sizeof(env)) {
 /* Handle error */
 }
- 
+
 return putenv(env); // putenv function should not be called with auto 
variables
   }
-  
+
+alpha.security.cert.env
+^^^
+
+SEI CERT checkers of `POSIX C coding rules 
`_.
+
+.. _alpha-security-cert-env-InvalidPtr:
+
+alpha.security.cert.env.InvalidPtr
+"""
+
+Corresponds to SEI CERT Rules ENV31-C and ENV34-C.
+
+ENV31-C:
+Rule is about the possible problem with `main` function's third argument, 
environment pointer,
+"envp". When enviornment array is modified using some modification function
+such as putenv, setenv or others, It may happen that memory is reallocated,
+however "envp" is not updated to reflect the changes and points to old memory
+region.
+
+ENV34-C:
+Some functions return a pointer to a statically allocated buffer.
+Consequently, subsequent call of these functions will invalidate previous
+pointer. These functions include: getenv, localeconv, asctime, setlocale, 
strerror
+
+.. code-block:: c
+
+  int main(int argc, const char *argv[], const char *envp[]) {
+if (setenv("MY_NEW_VAR", "new_value", 1) != 0) {
+  // setenv call may invalidate 'envp'
+  /* Handle error */
+}
+if (envp != NULL) {
+  for (size_t i = 0; envp[i] != NULL; ++i) {
+puts(envp[i]);
+// envp may no longer point to the current environment
+// this program has unanticipated behavior, since envp
+// does not reflect changes made by setenv function.
+  }
+}
+return 0;
+  }
+
+  void previous_call_invalidation() {
+char *p, *pp;
+
+p = getenv("VAR");
+pp = getenv("VAR2");
+// subsequent call to 'getenv' invalidated previous one
+
+*p;
+// dereferencing invalid pointer
+  }
+
 .. _alpha-security-ArrayBound:
 
 alpha.security.ArrayBound (C)

diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 86513a3e541be..aac111982b235 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -73,6 +73,7 @@ def Taint : Package<"taint">, ParentPackage;
 
 def CERT : Package<"cert">, ParentPackage;
 def POS : Package<"pos">, ParentPackage;
+def ENV : Package<"env">, ParentPackage;
 
 def Unix : Package<"unix">;
 def UnixAlpha : Package<"unix">, ParentPackage;
@@ -947,6 +948,14 @@ let ParentPackage = POS in {
 
 } // end "alpha.cert.pos"
 
+let ParentPackage = ENV in {
+
+  def InvalidPtrChecker : Checker<"InvalidPtr">,
+  HelpText<"Finds usages of possibly invalidated pointers">,
+  Documentation;
+
+} // end "alpha.cert.env"
+
 let ParentPackage = SecurityAlpha in {
 
 def ArrayBoundChecker : Checker<"ArrayBound">,

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index eb4f301377325..e7d424ae91504 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -49,6 +49,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   IdenticalExprChecker.cpp
   InnerPointerChecker.cpp
   InvalidatedIteratorChecker.cpp
+  cert/InvalidPtrChecker.cpp
   Iterator.cpp
   IteratorModeling.cpp
   IteratorRangeChecker.cpp

diff  --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChec

[PATCH] D97699: [analyzer] Add InvalidPtrChecker

2021-10-04 Thread Zurab Tsinadze via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
zukatsinadze marked an inline comment as done.
Closed by commit rG811b1736d91b: [analyzer] Add InvalidPtrChecker (authored by 
zukatsinadze).

Changed prior to commit:
  https://reviews.llvm.org/D97699?vs=372237&id=376902#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97699

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
  clang/test/Analysis/cert/env31-c.c
  clang/test/Analysis/cert/env34-c-cert-examples.c
  clang/test/Analysis/cert/env34-c.c

Index: clang/test/Analysis/cert/env34-c.c
===
--- /dev/null
+++ clang/test/Analysis/cert/env34-c.c
@@ -0,0 +1,331 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=alpha.security.cert.env.InvalidPtr\
+// RUN:  -analyzer-output=text -verify -Wno-unused %s
+
+#include "../Inputs/system-header-simulator.h"
+char *getenv(const char *name);
+char *setlocale(int category, const char *locale);
+char *strerror(int errnum);
+
+typedef struct {
+  char * field;
+} lconv;
+lconv *localeconv(void);
+
+typedef struct {
+} tm;
+char *asctime(const tm *timeptr);
+
+int strcmp(const char*, const char*);
+extern void foo(char *e);
+extern char* bar();
+
+
+void getenv_test1() {
+  char *p;
+
+  p = getenv("VAR");
+  *p; // no-warning
+
+  p = getenv("VAR2");
+  *p; // no-warning, getenv result was assigned to the same pointer
+}
+
+void getenv_test2() {
+  char *p, *p2;
+
+  p = getenv("VAR");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  p2 = getenv("VAR2");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test3() {
+  char *p, *p2, *p3;
+
+  p = getenv("VAR");
+  *p; // no-warning
+
+  p = getenv("VAR2");
+  // expected-note@-1{{previous function call was here}}
+  p2 = getenv("VAR2");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  p3 = getenv("VAR3");
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test4() {
+  char *p, *p2, *p3;
+
+  p = getenv("VAR");
+  // expected-note@-1{{previous function call was here}}
+  p2 = getenv("VAR2");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+  p3 = getenv("VAR3");
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test5() {
+  char *p, *p2, *p3;
+
+  p = getenv("VAR");
+  p2 = getenv("VAR2");
+  // expected-note@-1{{previous function call was here}}
+  p3 = getenv("VAR3");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *p2;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test6() {
+  char *p, *p2;
+  p = getenv("VAR");
+  *p; // no-warning
+
+  p = getenv("VAR2");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  p2 = getenv("VAR3");
+  // expected-note@-1{{previous function call was here}}
+  // expected-note@-2{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+
+  *p2; // no-warning
+
+  p = getenv("VAR4");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *p; // no-warning
+  *p2;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test7() {
+  char *p, *p2;
+  p = getenv("VAR");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  p2 = getenv("VAR2");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  foo(p);
+  // expected-warning@-1{{use of invalidated pointer 'p' in a function call}}
+  // expected-note@-2{{use of invalidated pointer 'p' in a function call}}
+}
+
+void getenv_test8() {
+  static const char *array[] = {
+ 0,
+ 0,
+ "/var/tmp",
+ "/usr/tmp",
+ "/tmp",
+ "."
+  };
+
+  if( !array[0] )
+  // expected-note@-1{{Taking true branch}}
+array[0] = getenv("TEMPDIR");
+// expected-note@-1{{previous function call was here}}
+
+  if( !array[1] )
+  // expected-note@-1{{Taking true branch}}
+array[1] = getenv("TMPDIR");
+// expected-note@

[PATCH] D97874: [analyzer] Improve SVal cast from integer to bool using known RangeSet

2021-10-04 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov abandoned this revision.
ASDenysPetrov added a comment.

In D97874#3014922 , @martong wrote:

> @ASDenysPetrov I think the dependent patch https://reviews.llvm.org/D97296 is 
> too much and contains unnecessary things for this change.
>
> If you could you please incorporate the minimum needed changes from that 
> patch to here then this patch could land.
> If I am not mistaken then we need only the below changes:
>
>   SVal evalCastKind(ProgramStateRef State, UndefinedVal V, QualType CastTy,
>   SVal evalCastSubKind(ProgramStateRef State, nonloc::SymbolVal V,

This patch is an old one. I believe it is already irrelevant and has to be 
reviewed once again by me as an author, since it were a lot of improvements 
made for `ConstraintManager`. Indeed it has a big parent revision, which also 
need a revision. There was my idea about adding a `ProgramState` inside 
`evalCast` to make symbolic values more transparent for casts. Let me mark it 
as //Abandoned// for now. I'll return back to it ASAP. Thank you for attention 
to this.


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

https://reviews.llvm.org/D97874

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


[PATCH] D99436: [OPENMP]Fix PR49366: crash on VLAs in task untied regions.

2021-10-04 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 376914.
ABataev added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99436

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/OpenMP/task_messages.cpp
  clang/test/OpenMP/taskloop_loop_messages.cpp

Index: clang/test/OpenMP/taskloop_loop_messages.cpp
===
--- clang/test/OpenMP/taskloop_loop_messages.cpp
+++ clang/test/OpenMP/taskloop_loop_messages.cpp
@@ -691,7 +691,7 @@
 
 void test_loop_eh() {
   const int N = 100;
-  float a[N], b[N], c[N];
+  float a[N], b[N], c[N]; // expected-note {{declared here}}
 #pragma omp parallel
 #pragma omp taskloop
   for (int i = 0; i < 10; i++) {
@@ -729,6 +729,13 @@
   void g() { throw 0; }
 };
   }
+// expected-error@+5 {{variable length arrays are not supported in OpenMP tasking regions with 'untied' clause}}
+// expected-note@+4 {{read of non-constexpr variable 'c' is not allowed in a constant expression}}
+#pragma omp taskloop untied
+  {
+  for (int i = 0; i < 10; ++i)
+int array[(int)c[0]];
+  }
 }
 
 void test_loop_firstprivate_lastprivate() {
Index: clang/test/OpenMP/task_messages.cpp
===
--- clang/test/OpenMP/task_messages.cpp
+++ clang/test/OpenMP/task_messages.cpp
@@ -173,7 +173,7 @@
   int &b = a;
   S sa;
   S &sb = sa;
-  int r;
+  int r; // expected-note {{declared here}}
 #pragma omp task { // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
   foo();
 #pragma omp task( // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
@@ -330,6 +330,12 @@
 // expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
 #pragma omp task mergeable mergeable
   ++r;
+// expected-error@+4 {{variable length arrays are not supported in OpenMP tasking regions with 'untied' clause}}
+// expected-note@+3 {{read of non-const variable 'r' is not allowed in a constant expression}}
+#pragma omp task untied
+  {
+int array[r];
+  }
   volatile omp_event_handle_t evt;
   omp_event_handle_t sevt;
   const omp_event_handle_t cevt = evt;
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2457,6 +2457,9 @@
   } else if (isSFINAEContext()) {
 VLADiag = diag::err_vla_in_sfinae;
 VLAIsError = true;
+  } else if (getLangOpts().OpenMP && isInOpenMPTaskUntiedContext()) {
+VLADiag = diag::err_openmp_vla_in_task_untied;
+VLAIsError = true;
   } else {
 VLADiag = diag::ext_vla;
 VLAIsError = false;
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -174,6 +174,7 @@
 bool HasMutipleLoops = false;
 const Decl *PossiblyLoopCounter = nullptr;
 bool NowaitRegion = false;
+bool UntiedRegion = false;
 bool CancelRegion = false;
 bool LoopStart = false;
 bool BodyComplete = false;
@@ -859,6 +860,15 @@
   return Parent->NowaitRegion;
 return false;
   }
+  /// Marks current region as untied (it has a 'untied' clause).
+  void setUntiedRegion(bool IsUntied = true) {
+getTopOfStack().UntiedRegion = IsUntied;
+  }
+  /// Return true if current region is untied.
+  bool isUntiedRegion() const {
+const SharingMapTy *Top = getTopOfStackOrNull();
+return Top ? Top->UntiedRegion : false;
+  }
   /// Marks parent region as cancel region.
   void setParentCancelRegion(bool Cancel = true) {
 if (SharingMapTy *Parent = getSecondOnStackOrNull())
@@ -2172,6 +2182,11 @@
   return DSAStack->getNestingLevel();
 }
 
+bool Sema::isInOpenMPTaskUntiedContext() const {
+  return isOpenMPTaskingDirective(DSAStack->getCurrentDirective()) &&
+ DSAStack->isUntiedRegion();
+}
+
 bool Sema::isInOpenMPTargetExecutionDirective() const {
   return (isOpenMPTargetExecutionDirective(DSAStack->getCurrentDirective()) &&
   !DSAStack->isClauseParsingMode()) ||
@@ -15146,6 +15161,7 @@
 
 OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc,
  SourceLocation EndLoc) {
+  DSAStack->setUntiedRegion();
   return new (Context) OMPUntiedClause(StartLoc, EndLoc);
 }
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10583,6 +10583,10 @@
   void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller,
  const FunctionDecl *Callee,
  SourceLocation Loc);
+
+  /// Return tru

[PATCH] D99350: [OPENMP]Fix PR49649: The introduction of $ref globals is not always valid.

2021-10-04 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 376920.
ABataev added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99350

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_target_codegen.cpp
  openmp/libomptarget/test/offloading/ref_to_shared.cpp


Index: openmp/libomptarget/test/offloading/ref_to_shared.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/offloading/ref_to_shared.cpp
@@ -0,0 +1,17 @@
+// RUN: %libomptarget-compilexx-run-and-check-nvptx64-nvidia-cuda
+// REQUIRES: nvptx64-nvidia-cuda
+
+#include 
+#include 
+#pragma omp declare target
+
+static int X;
+#pragma omp allocate(X) allocator(omp_pteam_mem_alloc)
+
+int main() {
+  // CHECK: PASS
+  std::cout << "PASS\n";
+  return 0;
+}
+
+#pragma omp end declare target
Index: clang/test/OpenMP/declare_target_codegen.cpp
===
--- clang/test/OpenMP/declare_target_codegen.cpp
+++ clang/test/OpenMP/declare_target_codegen.cpp
@@ -43,10 +43,10 @@
 // CHECK-DAG: @c = external global i32,
 // CHECK-DAG: @globals ={{ hidden | }}global %struct.S zeroinitializer,
 // CHECK-DAG: [[STAT:@.+stat]] = internal global %struct.S zeroinitializer,
-// CHECK-DAG: [[STAT_REF:@.+]] = internal constant %struct.S* [[STAT]]
+// CHECK-DAG: [[STAT_REF:@.+]] = internal constant i8* bitcast (%struct.S* 
[[STAT]] to i8*)
 // CHECK-DAG: @out_decl_target ={{ hidden | }}global i32 0,
 // CHECK-DAG: @llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* 
@__omp_offloading__{{.+}}_globals_l[[@LINE+84]]_ctor to i8*), i8* bitcast (void 
()* @__omp_offloading__{{.+}}_stat_l[[@LINE+85]]_ctor to i8*)],
-// CHECK-DAG: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast 
(%struct.S** [[STAT_REF]] to i8*)],
+// CHECK-DAG: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast 
(i8** [[STAT_REF]] to i8*)],
 
 // CHECK-DAG: define {{.*}}i32 @{{.*}}{{foo|bar|baz2|baz3|FA|f_method}}{{.*}}()
 // CHECK-DAG: define {{.*}}void 
@{{.*}}TemplateClass{{.*}}(%class.TemplateClass* {{[^,]*}} %{{.*}})
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -10880,11 +10880,13 @@
   std::string RefName = getName({VarName, "ref"});
   if (!CGM.GetGlobalValue(RefName)) {
 llvm::Constant *AddrRef =
-getOrCreateInternalVariable(Addr->getType(), RefName);
+getOrCreateInternalVariable(CGM.VoidPtrTy, RefName);
 auto *GVAddrRef = cast(AddrRef);
 GVAddrRef->setConstant(/*Val=*/true);
 GVAddrRef->setLinkage(llvm::GlobalValue::InternalLinkage);
-GVAddrRef->setInitializer(Addr);
+GVAddrRef->setInitializer(
+llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
+Addr, CGM.VoidPtrTy));
 CGM.addCompilerUsedGlobal(GVAddrRef);
   }
 }


Index: openmp/libomptarget/test/offloading/ref_to_shared.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/offloading/ref_to_shared.cpp
@@ -0,0 +1,17 @@
+// RUN: %libomptarget-compilexx-run-and-check-nvptx64-nvidia-cuda
+// REQUIRES: nvptx64-nvidia-cuda
+
+#include 
+#include 
+#pragma omp declare target
+
+static int X;
+#pragma omp allocate(X) allocator(omp_pteam_mem_alloc)
+
+int main() {
+  // CHECK: PASS
+  std::cout << "PASS\n";
+  return 0;
+}
+
+#pragma omp end declare target
Index: clang/test/OpenMP/declare_target_codegen.cpp
===
--- clang/test/OpenMP/declare_target_codegen.cpp
+++ clang/test/OpenMP/declare_target_codegen.cpp
@@ -43,10 +43,10 @@
 // CHECK-DAG: @c = external global i32,
 // CHECK-DAG: @globals ={{ hidden | }}global %struct.S zeroinitializer,
 // CHECK-DAG: [[STAT:@.+stat]] = internal global %struct.S zeroinitializer,
-// CHECK-DAG: [[STAT_REF:@.+]] = internal constant %struct.S* [[STAT]]
+// CHECK-DAG: [[STAT_REF:@.+]] = internal constant i8* bitcast (%struct.S* [[STAT]] to i8*)
 // CHECK-DAG: @out_decl_target ={{ hidden | }}global i32 0,
 // CHECK-DAG: @llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* @__omp_offloading__{{.+}}_globals_l[[@LINE+84]]_ctor to i8*), i8* bitcast (void ()* @__omp_offloading__{{.+}}_stat_l[[@LINE+85]]_ctor to i8*)],
-// CHECK-DAG: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (%struct.S** [[STAT_REF]] to i8*)],
+// CHECK-DAG: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i8** [[STAT_REF]] to i8*)],
 
 // CHECK-DAG: define {{.*}}i32 @{{.*}}{{foo|bar|baz2|baz3|FA|f_method}}{{.*}}()
 // CHECK-DAG: define {{.*}}void @{{.*}}TemplateClass{{.*}}(%class.TemplateClass* {{[^,]*}} %{{.*}})
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===

[PATCH] D111009: Update inline builtin handling to honor gnu inline attribute

2021-10-04 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers accepted this revision.
nickdesaulniers added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/CodeGen/CGExpr.cpp:4901
+  llvm::Function *Fn = llvm::cast(CalleePtr);
+  llvm::Module &M = CGF.CGM.getModule();
+  llvm::Function *Clone = M.getFunction(FDInlineName);

llvm::Module *M = Fn->getParent();


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

https://reviews.llvm.org/D111009

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


[PATCH] D110586: Update `DynTypedNode` to support the conversion of `TypeLoc`s.

2021-10-04 Thread Samuel Benzaquen via Phabricator via cfe-commits
sbenza accepted this revision.
sbenza added inline comments.



Comment at: clang/unittests/AST/ASTTypeTraitsTest.cpp:234
+  EXPECT_TRUE(PointerTypeLocNode == PointerTypeLocNode);
+  EXPECT_FALSE(PointerTypeLocNode < PointerTypeLocNode);
+}

Maybe also check

```
EXPECT_EQ(&tl, &ptl);
```

?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110586

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


[PATCH] D110670: [Sema] Allow comparisons between different ms ptr size address space types.

2021-10-04 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 376936.
akhuang added a comment.

add test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110670

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CodeGen/ms-mixed-ptr-sizes.c
  clang/test/Sema/MicrosoftExtensions.cpp


Index: clang/test/Sema/MicrosoftExtensions.cpp
===
--- /dev/null
+++ clang/test/Sema/MicrosoftExtensions.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wmicrosoft -verify 
-fms-extensions
+// RUN: %clang_cc1 -triple x86_64-windows %s -fsyntax-only -Wmicrosoft -verify 
-fms-extensions
+// expected-no-diagnostics
+
+// Check that __ptr32/__ptr64 can be compared.
+int test_ptr_comparison(int *__ptr32 __uptr p32u, int *__ptr32 __sptr p32s,
+int *__ptr64 p64) {
+  return (p32u == p32s) +
+ (p32u == p64) +
+ (p32s == p64);
+}
Index: clang/test/CodeGen/ms-mixed-ptr-sizes.c
===
--- clang/test/CodeGen/ms-mixed-ptr-sizes.c
+++ clang/test/CodeGen/ms-mixed-ptr-sizes.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -O2 
< %s | FileCheck %s --check-prefix=X64
-// RUN: %clang_cc1 -triple i386-pc-win32 -fms-extensions -emit-llvm -O2 < %s | 
FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -O2 
< %s | FileCheck %s --check-prefixes=X64,ALL
+// RUN: %clang_cc1 -triple i386-pc-win32 -fms-extensions -emit-llvm -O2 < %s | 
FileCheck %s --check-prefixes=X86,ALL
 
 struct Foo {
   int * __ptr32 p32;
@@ -47,3 +47,39 @@
   f->p32 = (int * __ptr32)i;
   use_foo(f);
 }
+
+int test_compare1(int *__ptr32 __uptr i, int *__ptr64 j) {
+  // ALL-LABEL: define dso_local i32 @test_compare1
+  // X64: %{{.+}} = addrspacecast i32* %j to i32 addrspace(271)*
+  // X64: %cmp = icmp eq i32 addrspace(271)* %{{.+}}, %i
+  // X86: %{{.+}} = addrspacecast i32 addrspace(272)* %j to i32 addrspace(271)*
+  // X86: %cmp = icmp eq i32 addrspace(271)* %{{.+}}, %i
+  return (i == j);
+}
+
+int test_compare2(int *__ptr32 __sptr i, int *__ptr64 j) {
+  // ALL-LABEL: define dso_local i32 @test_compare2
+  // X64: %{{.+}} = addrspacecast i32* %j to i32 addrspace(270)*
+  // X64: %cmp = icmp eq i32 addrspace(270)* %{{.+}}, %i
+  // X86: %{{.+}} = addrspacecast i32 addrspace(272)* %j to i32*
+  // X86: %cmp = icmp eq i32* %{{.+}}, %i
+  return (i == j);
+}
+
+int test_compare3(int *__ptr32 __uptr i, int *__ptr64 j) {
+  // ALL-LABEL: define dso_local i32 @test_compare3
+  // X64: %{{.+}} = addrspacecast i32 addrspace(271)* %i to i32*
+  // X64: %cmp = icmp eq i32* %{{.+}}, %j
+  // X86: %{{.+}} = addrspacecast i32 addrspace(271)* %i to i32 addrspace(272)*
+  // X86: %cmp = icmp eq i32 addrspace(272)* %{{.+}}, %j
+  return (j == i);
+}
+
+int test_compare4(int *__ptr32 __sptr i, int *__ptr64 j) {
+  // ALL-LABEL: define dso_local i32 @test_compare4
+  // X64: %{{.+}} = addrspacecast i32 addrspace(270)* %i to i32*
+  // X64: %cmp = icmp eq i32* %{{.+}}, %j
+  // X86: %{{.+}} = addrspacecast i32* %i to i32 addrspace(272)*
+  // X86: %cmp = icmp eq i32 addrspace(272)* %{{.+}}, %j
+  return (j == i);
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -6674,8 +6674,15 @@
   } else if (Steps.size() == 1) {
 bool MaybeQ1 = Q1.isAddressSpaceSupersetOf(Q2);
 bool MaybeQ2 = Q2.isAddressSpaceSupersetOf(Q1);
-if (MaybeQ1 == MaybeQ2)
-  return QualType(); // No unique best address space.
+if (MaybeQ1 == MaybeQ2) {
+  // Exception for ptr size address spaces. Should be able to choose
+  // either address space during comparison.
+  if (isPtrSizeAddressSpace(Q1.getAddressSpace()) ||
+  isPtrSizeAddressSpace(Q2.getAddressSpace()))
+MaybeQ1 = true;
+  else
+return QualType(); // No unique best address space.
+}
 Quals.setAddressSpace(MaybeQ1 ? Q1.getAddressSpace()
   : Q2.getAddressSpace());
   } else {


Index: clang/test/Sema/MicrosoftExtensions.cpp
===
--- /dev/null
+++ clang/test/Sema/MicrosoftExtensions.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
+// RUN: %clang_cc1 -triple x86_64-windows %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
+// expected-no-diagnostics
+
+// Check that __ptr32/__ptr64 can be compared.
+int test_ptr_comparison(int *__ptr32 __uptr p32u, int *__ptr32 __sptr p32s,
+int *__ptr64 p64) {
+  return (p32u == p32s) +
+ (p32u == p64) +
+ (p32s == p64)

[PATCH] D110586: Update `DynTypedNode` to support the conversion of `TypeLoc`s.

2021-10-04 Thread James King via Phabricator via cfe-commits
jcking1034 updated this revision to Diff 376939.
jcking1034 added a comment.

Include additional expectation in unit test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110586

Files:
  clang/include/clang/AST/ASTTypeTraits.h
  clang/lib/AST/ASTTypeTraits.cpp
  clang/unittests/AST/ASTTypeTraitsTest.cpp

Index: clang/unittests/AST/ASTTypeTraitsTest.cpp
===
--- clang/unittests/AST/ASTTypeTraitsTest.cpp
+++ clang/unittests/AST/ASTTypeTraitsTest.cpp
@@ -199,5 +199,41 @@
   EXPECT_FALSE(Node < Node);
 }
 
+TEST(DynTypedNode, TypeLoc) {
+  std::string code = R"cc(void example() { int abc; })cc";
+  auto AST = clang::tooling::buildASTFromCode(code);
+  auto matches =
+  match(traverse(TK_AsIs,
+ varDecl(hasName("abc"), hasTypeLoc(typeLoc().bind("tl",
+AST->getASTContext());
+  EXPECT_EQ(matches.size(), 1u);
+
+  const auto &tl = *matches[0].getNodeAs("tl");
+  DynTypedNode Node = DynTypedNode::create(tl);
+  EXPECT_TRUE(Node == Node);
+  EXPECT_FALSE(Node < Node);
+}
+
+TEST(DynTypedNode, PointerTypeLoc) {
+  std::string code = R"cc(void example() { int* abc; })cc";
+  auto AST = clang::tooling::buildASTFromCode(code);
+  auto matches =
+  match(traverse(TK_AsIs, varDecl(hasName("abc"),
+  hasTypeLoc(typeLoc().bind("ptl",
+AST->getASTContext());
+  EXPECT_EQ(matches.size(), 1u);
+
+  const auto &tl = *matches[0].getNodeAs("ptl");
+  DynTypedNode TypeLocNode = DynTypedNode::create(tl);
+  EXPECT_TRUE(TypeLocNode == TypeLocNode);
+  EXPECT_FALSE(TypeLocNode < TypeLocNode);
+
+  const auto &ptl = *matches[0].getNodeAs("ptl");
+  EXPECT_EQ(&tl, &ptl);
+  DynTypedNode PointerTypeLocNode = DynTypedNode::create(ptl);
+  EXPECT_TRUE(PointerTypeLocNode == PointerTypeLocNode);
+  EXPECT_FALSE(PointerTypeLocNode < PointerTypeLocNode);
+}
+
 } // namespace
 }  // namespace clang
Index: clang/lib/AST/ASTTypeTraits.cpp
===
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OpenMPClause.h"
+#include "clang/AST/TypeLoc.h"
 
 using namespace clang;
 
@@ -28,6 +29,8 @@
 {NKI_None, "TemplateName"},
 {NKI_None, "NestedNameSpecifierLoc"},
 {NKI_None, "QualType"},
+#define TYPELOC(CLASS, PARENT) {NKI_##PARENT, #CLASS "TypeLoc"},
+#include "clang/AST/TypeLocNodes.def"
 {NKI_None, "TypeLoc"},
 {NKI_None, "CXXBaseSpecifier"},
 {NKI_None, "CXXCtorInitializer"},
@@ -127,6 +130,17 @@
   llvm_unreachable("invalid type kind");
  }
 
+ ASTNodeKind ASTNodeKind::getFromNode(const TypeLoc &T) {
+   switch (T.getTypeLocClass()) {
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
+#define TYPELOC(CLASS, PARENT) \
+  case TypeLoc::CLASS: \
+return ASTNodeKind(NKI_##CLASS##TypeLoc);
+#include "clang/AST/TypeLocNodes.def"
+   }
+   llvm_unreachable("invalid typeloc kind");
+ }
+
 ASTNodeKind ASTNodeKind::getFromNode(const OMPClause &C) {
   switch (C.getClauseKind()) {
 #define GEN_CLANG_CLAUSE_CLASS
Index: clang/include/clang/AST/ASTTypeTraits.h
===
--- clang/include/clang/AST/ASTTypeTraits.h
+++ clang/include/clang/AST/ASTTypeTraits.h
@@ -63,6 +63,7 @@
   static ASTNodeKind getFromNode(const Decl &D);
   static ASTNodeKind getFromNode(const Stmt &S);
   static ASTNodeKind getFromNode(const Type &T);
+  static ASTNodeKind getFromNode(const TypeLoc &T);
   static ASTNodeKind getFromNode(const OMPClause &C);
   static ASTNodeKind getFromNode(const Attr &A);
   /// \}
@@ -133,6 +134,8 @@
 NKI_TemplateName,
 NKI_NestedNameSpecifierLoc,
 NKI_QualType,
+#define TYPELOC(CLASS, PARENT) NKI_##CLASS##TypeLoc,
+#include "clang/AST/TypeLocNodes.def"
 NKI_TypeLoc,
 NKI_LastKindWithoutPointerIdentity = NKI_TypeLoc,
 NKI_CXXBaseSpecifier,
@@ -198,6 +201,8 @@
 KIND_TO_KIND_ID(NestedNameSpecifier)
 KIND_TO_KIND_ID(NestedNameSpecifierLoc)
 KIND_TO_KIND_ID(QualType)
+#define TYPELOC(CLASS, PARENT) KIND_TO_KIND_ID(CLASS##TypeLoc)
+#include "clang/AST/TypeLocNodes.def"
 KIND_TO_KIND_ID(TypeLoc)
 KIND_TO_KIND_ID(Decl)
 KIND_TO_KIND_ID(Stmt)
@@ -304,7 +309,7 @@
   return getUnchecked().getAsOpaquePtr() <
  Other.getUnchecked().getAsOpaquePtr();
 
-if (ASTNodeKind::getFromNodeKind().isSame(NodeKind)) {
+if (ASTNodeKind::getFromNodeKind().isBaseOf(NodeKind)) {
   auto TLA = getUnchecked();
   auto TLB = Other.getUnchecked();
   return std::make_pair(TLA.getType().getAsOpaquePtr(),
@@ -336,7 +341,7 @@
 if (ASTNodeKind::getFromNodeKind().isSame(NodeKind))
   return getUnchecked() == Other

[PATCH] D111049: [Support] Change fatal_error_handler_t to take a const char* instead of std::string

2021-10-04 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen accepted this revision.
ychen added a comment.
This revision is now accepted and ready to land.

Sounds good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111049

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


[PATCH] D110586: Update `DynTypedNode` to support the conversion of `TypeLoc`s.

2021-10-04 Thread James King via Phabricator via cfe-commits
jcking1034 updated this revision to Diff 376944.
jcking1034 added a comment.

Fix pointer style


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110586

Files:
  clang/include/clang/AST/ASTTypeTraits.h
  clang/lib/AST/ASTTypeTraits.cpp
  clang/unittests/AST/ASTTypeTraitsTest.cpp

Index: clang/unittests/AST/ASTTypeTraitsTest.cpp
===
--- clang/unittests/AST/ASTTypeTraitsTest.cpp
+++ clang/unittests/AST/ASTTypeTraitsTest.cpp
@@ -199,5 +199,41 @@
   EXPECT_FALSE(Node < Node);
 }
 
+TEST(DynTypedNode, TypeLoc) {
+  std::string code = R"cc(void example() { int abc; })cc";
+  auto AST = clang::tooling::buildASTFromCode(code);
+  auto matches =
+  match(traverse(TK_AsIs,
+ varDecl(hasName("abc"), hasTypeLoc(typeLoc().bind("tl",
+AST->getASTContext());
+  EXPECT_EQ(matches.size(), 1u);
+
+  const auto &tl = *matches[0].getNodeAs("tl");
+  DynTypedNode Node = DynTypedNode::create(tl);
+  EXPECT_TRUE(Node == Node);
+  EXPECT_FALSE(Node < Node);
+}
+
+TEST(DynTypedNode, PointerTypeLoc) {
+  std::string code = R"cc(void example() { int *abc; })cc";
+  auto AST = clang::tooling::buildASTFromCode(code);
+  auto matches =
+  match(traverse(TK_AsIs, varDecl(hasName("abc"),
+  hasTypeLoc(typeLoc().bind("ptl",
+AST->getASTContext());
+  EXPECT_EQ(matches.size(), 1u);
+
+  const auto &tl = *matches[0].getNodeAs("ptl");
+  DynTypedNode TypeLocNode = DynTypedNode::create(tl);
+  EXPECT_TRUE(TypeLocNode == TypeLocNode);
+  EXPECT_FALSE(TypeLocNode < TypeLocNode);
+
+  const auto &ptl = *matches[0].getNodeAs("ptl");
+  EXPECT_EQ(&tl, &ptl);
+  DynTypedNode PointerTypeLocNode = DynTypedNode::create(ptl);
+  EXPECT_TRUE(PointerTypeLocNode == PointerTypeLocNode);
+  EXPECT_FALSE(PointerTypeLocNode < PointerTypeLocNode);
+}
+
 } // namespace
 }  // namespace clang
Index: clang/lib/AST/ASTTypeTraits.cpp
===
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OpenMPClause.h"
+#include "clang/AST/TypeLoc.h"
 
 using namespace clang;
 
@@ -28,6 +29,8 @@
 {NKI_None, "TemplateName"},
 {NKI_None, "NestedNameSpecifierLoc"},
 {NKI_None, "QualType"},
+#define TYPELOC(CLASS, PARENT) {NKI_##PARENT, #CLASS "TypeLoc"},
+#include "clang/AST/TypeLocNodes.def"
 {NKI_None, "TypeLoc"},
 {NKI_None, "CXXBaseSpecifier"},
 {NKI_None, "CXXCtorInitializer"},
@@ -127,6 +130,17 @@
   llvm_unreachable("invalid type kind");
  }
 
+ ASTNodeKind ASTNodeKind::getFromNode(const TypeLoc &T) {
+   switch (T.getTypeLocClass()) {
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
+#define TYPELOC(CLASS, PARENT) \
+  case TypeLoc::CLASS: \
+return ASTNodeKind(NKI_##CLASS##TypeLoc);
+#include "clang/AST/TypeLocNodes.def"
+   }
+   llvm_unreachable("invalid typeloc kind");
+ }
+
 ASTNodeKind ASTNodeKind::getFromNode(const OMPClause &C) {
   switch (C.getClauseKind()) {
 #define GEN_CLANG_CLAUSE_CLASS
Index: clang/include/clang/AST/ASTTypeTraits.h
===
--- clang/include/clang/AST/ASTTypeTraits.h
+++ clang/include/clang/AST/ASTTypeTraits.h
@@ -63,6 +63,7 @@
   static ASTNodeKind getFromNode(const Decl &D);
   static ASTNodeKind getFromNode(const Stmt &S);
   static ASTNodeKind getFromNode(const Type &T);
+  static ASTNodeKind getFromNode(const TypeLoc &T);
   static ASTNodeKind getFromNode(const OMPClause &C);
   static ASTNodeKind getFromNode(const Attr &A);
   /// \}
@@ -133,6 +134,8 @@
 NKI_TemplateName,
 NKI_NestedNameSpecifierLoc,
 NKI_QualType,
+#define TYPELOC(CLASS, PARENT) NKI_##CLASS##TypeLoc,
+#include "clang/AST/TypeLocNodes.def"
 NKI_TypeLoc,
 NKI_LastKindWithoutPointerIdentity = NKI_TypeLoc,
 NKI_CXXBaseSpecifier,
@@ -198,6 +201,8 @@
 KIND_TO_KIND_ID(NestedNameSpecifier)
 KIND_TO_KIND_ID(NestedNameSpecifierLoc)
 KIND_TO_KIND_ID(QualType)
+#define TYPELOC(CLASS, PARENT) KIND_TO_KIND_ID(CLASS##TypeLoc)
+#include "clang/AST/TypeLocNodes.def"
 KIND_TO_KIND_ID(TypeLoc)
 KIND_TO_KIND_ID(Decl)
 KIND_TO_KIND_ID(Stmt)
@@ -304,7 +309,7 @@
   return getUnchecked().getAsOpaquePtr() <
  Other.getUnchecked().getAsOpaquePtr();
 
-if (ASTNodeKind::getFromNodeKind().isSame(NodeKind)) {
+if (ASTNodeKind::getFromNodeKind().isBaseOf(NodeKind)) {
   auto TLA = getUnchecked();
   auto TLB = Other.getUnchecked();
   return std::make_pair(TLA.getType().getAsOpaquePtr(),
@@ -336,7 +341,7 @@
 if (ASTNodeKind::getFromNodeKind().isSame(NodeKind))
   return getUnchecked() == Other.getUnchecked();
 
-if

[PATCH] D107613: [Clang][DiagnosticSemaKinds] combine diagnostic texts

2021-10-04 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added a comment.

It looks like this error is intended to catch mismatches for attributes that 
can affect codegen such as noreturn (in which case it makes sense to have it as 
an error) but it also now fires for cases such as `__attribute__(warning())` 
which often do not duplicate the attribute on the definition. Is that intended?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107613

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


[PATCH] D110065: [AArch64] Add support for the 'R' architecture profile.

2021-10-04 Thread Alexandros Lamprineas via Phabricator via cfe-commits
labrinea updated this revision to Diff 376942.
labrinea edited the summary of this revision.
labrinea added a comment.

Change from last revision: The driver implicitly enables the 'A' profile 
features (as if -march=armv8-a was specified on the command line) when only the 
target triple is specified in order to maintain backwards compatibility.


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

https://reviews.llvm.org/D110065

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/test/Driver/aarch64-cpus.c
  clang/test/Preprocessor/aarch64-target-features.c
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/AArch64/AArch64SystemOperands.td
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp
  llvm/test/CodeGen/AArch64/arm64-crc32.ll
  llvm/test/MC/AArch64/arm64-branch-encoding.s
  llvm/test/MC/AArch64/arm64-system-encoding.s
  llvm/test/MC/AArch64/armv8.1a-lse.s
  llvm/test/MC/AArch64/armv8.1a-pan.s
  llvm/test/MC/AArch64/armv8.1a-rdma.s
  llvm/test/MC/AArch64/armv8.2a-at.s
  llvm/test/MC/AArch64/armv8.2a-crypto.s
  llvm/test/MC/AArch64/armv8.2a-dotprod-errors.s
  llvm/test/MC/AArch64/armv8.2a-dotprod.s
  llvm/test/MC/AArch64/armv8.2a-persistent-memory.s
  llvm/test/MC/AArch64/armv8.2a-uao.s
  llvm/test/MC/AArch64/armv8r-inst.s
  llvm/test/MC/AArch64/armv8r-sysreg.s
  llvm/test/MC/AArch64/armv8r-unsupported-inst.s
  llvm/test/MC/AArch64/armv8r-unsupported-sysreg.s
  llvm/test/MC/AArch64/basic-a64-instructions.s
  llvm/test/MC/AArch64/ras-extension.s
  llvm/test/MC/Disassembler/AArch64/arm64-branch.txt
  llvm/test/MC/Disassembler/AArch64/armv8.3a-complex.txt
  llvm/test/MC/Disassembler/AArch64/armv8.3a-js.txt
  llvm/test/MC/Disassembler/AArch64/armv8.3a-rcpc.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-dit.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-flag.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-ras.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-tlb.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-trace.txt
  llvm/test/MC/Disassembler/AArch64/armv8.4a-virt.txt
  llvm/test/MC/Disassembler/AArch64/armv8.5a-predres.txt
  llvm/test/MC/Disassembler/AArch64/armv8.5a-specrestrict.txt
  llvm/test/MC/Disassembler/AArch64/armv8.5a-ssbs.txt
  llvm/test/MC/Disassembler/AArch64/armv8a-el3.txt
  llvm/test/MC/Disassembler/AArch64/armv8a-fpmul.txt
  llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt

Index: llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt
===
--- llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt
+++ llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt
@@ -1257,27 +1257,21 @@
 0xe1 0xff 0x1f 0xd4
 
 # CHECK: hvc  #{{1|0x1}}
-# CHECK: smc  #{{12000|0x2ee0}}
 # CHECK: brk  #{{12|0xc}}
 # CHECK: hlt  #{{123|0x7b}}
 0x22 0x0 0x0 0xd4
-0x3 0xdc 0x5 0xd4
 0x80 0x1 0x20 0xd4
 0x60 0xf 0x40 0xd4
 
 # CHECK: dcps1#{{42|0x2a}}
 # CHECK: dcps2#{{9|0x9}}
-# CHECK: dcps3#{{1000|0x3e8}}
 0x41 0x5 0xa0 0xd4
 0x22 0x1 0xa0 0xd4
-0x3 0x7d 0xa0 0xd4
 
 # CHECK: dcps1
 # CHECK: dcps2
-# CHECK: dcps3
 0x1 0x0 0xa0 0xd4
 0x2 0x0 0xa0 0xd4
-0x3 0x0 0xa0 0xd4
 
 #--
 # Extract (immediate)
@@ -3258,13 +3252,11 @@
 # CHECK: msr  {{hacr_el2|HACR_EL2}}, x12
 # CHECK: msr  {{mdcr_el3|MDCR_EL3}}, x12
 # CHECK: msr  {{ttbr0_el1|TTBR0_EL1}}, x12
-# CHECK: msr  {{ttbr0_el2|TTBR0_EL2}}, x12
 # CHECK: msr  {{ttbr0_el3|TTBR0_EL3}}, x12
 # CHECK: msr  {{ttbr1_el1|TTBR1_EL1}}, x12
 # CHECK: msr  {{tcr_el1|TCR_EL1}}, x12
 # CHECK: msr  {{tcr_el2|TCR_EL2}}, x12
 # CHECK: msr  {{tcr_el3|TCR_EL3}}, x12
-# CHECK: msr  {{vttbr_el2|VTTBR_EL2}}, x12
 # CHECK: msr  {{vtcr_el2|VTCR_EL2}}, x12
 # CHECK: msr  {{dacr32_el2|DACR32_EL2}}, x12
 # CHECK: msr  {{spsr_el1|SPSR_EL1}}, x12
@@ -3554,13 +3546,11 @@
 # CHECK: mrs  x9, {{hacr_el2|HACR_EL2}}
 # CHECK: mrs  x9, {{mdcr_el3|MDCR_EL3}}
 # CHECK: mrs  x9, {{ttbr0_el1|TTBR0_EL1}}
-# CHECK: mrs  x9, {{ttbr0_el2|TTBR0_EL2}}
 # CHECK: mrs  x9, {{ttbr0_el3|TTBR0_EL3}}
 # CHECK: mrs  x9, {{ttbr1_el1|TTBR1_EL1}}
 # CHECK: mrs  x9, {{tcr_el1|TCR_EL1}}
 # CHECK: mrs  x9, {{tcr_el2|TCR_EL2}}
 # CHECK: mrs  x9, {{tcr_el3|TCR_EL3}}
-# CHECK: mrs  x9, {{vttbr_el2|VTTBR_EL2}}
 # CHECK: mrs  x9, {{vtcr_el2|VTCR_EL2}}
 # CHECK: mrs  x9, {{dacr32_el2|DACR32_EL2}}
 # CHECK: mrs  x9, {{spsr_el1|SPSR_EL1}}
Index: llvm/test/MC/Disassembler/AArch64/armv8a-fpmul.txt
===
--- llvm/test/MC/Disassembler/AArch64/armv8a-fpmul.txt
+++ llvm/test/MC/

[PATCH] D107613: [Clang][DiagnosticSemaKinds] combine diagnostic texts

2021-10-04 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D107613#3040402 , @dschuff wrote:

> It looks like this error is intended to catch mismatches for attributes that 
> can affect codegen such as noreturn (in which case it makes sense to have it 
> as an error) but it also now fires for cases such as 
> `__attribute__(warning())` which often do not duplicate the attribute on the 
> definition. Is that intended?

Duplicating the attribute on the definition is not needed for 
`__attribute__(warning())`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107613

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


[PATCH] D110668: [clang-cl] Accept `#pragma warning(disable : N)` for some N

2021-10-04 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

> What I mean,  for example:
>
>   def UnusedParameter : DiagGroup<"unused-parameter", 4100>;

That's an interesting idea.

Given how seldom this is used, I weakly prefer having actual code for this 
though: It makes it easy to see all of those mapped flags, and it keeps rarely 
used things out of tablegen, which is imho a good thing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110668

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


[PATCH] D105297: [OPENMP]Fix PR50347: Mapping of global scope deep object fails.

2021-10-04 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 376945.
ABataev added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105297

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/reduction_implicit_map.cpp
  clang/test/OpenMP/target_codegen.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_data_map_codegen_hold.cpp
  clang/test/OpenMP/target_data_map_pointer_array_subscript_codegen.cpp
  clang/test/OpenMP/target_data_use_device_addr_codegen.cpp
  clang/test/OpenMP/target_defaultmap_codegen_01.cpp
  clang/test/OpenMP/target_enter_data_codegen.cpp
  clang/test/OpenMP/target_enter_data_depend_codegen.cpp
  clang/test/OpenMP/target_exit_data_codegen.cpp
  clang/test/OpenMP/target_exit_data_depend_codegen.cpp
  clang/test/OpenMP/target_firstprivate_codegen.cpp
  clang/test/OpenMP/target_map_codegen_12.cpp
  clang/test/OpenMP/target_map_codegen_13.cpp
  clang/test/OpenMP/target_map_codegen_14.cpp
  clang/test/OpenMP/target_map_codegen_18.inc
  clang/test/OpenMP/target_map_codegen_20.cpp
  clang/test/OpenMP/target_map_codegen_23.cpp
  clang/test/OpenMP/target_map_codegen_28.cpp
  clang/test/OpenMP/target_map_codegen_29.cpp
  clang/test/OpenMP/target_map_codegen_31.cpp
  clang/test/OpenMP/target_map_codegen_32.cpp
  clang/test/OpenMP/target_map_codegen_34.cpp
  clang/test/OpenMP/target_map_codegen_35.cpp
  clang/test/OpenMP/target_map_codegen_hold.cpp
  clang/test/OpenMP/target_map_member_expr_array_section_codegen.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_simd_codegen.cpp
  clang/test/OpenMP/target_teams_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_collapse_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_dist_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_collapse_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_dist_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_schedule_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_collapse_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_dist_schedule_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_collapse_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_dist_schedule_codegen.cpp
  clang/test/OpenMP/target_update_codegen.cpp
  clang/test/OpenMP/target_update_depend_codegen.cpp
  clang/test/OpenMP/teams_distribute_codegen.cpp
  clang/test/OpenMP/teams_distribute_collapse_codegen.cpp
  clang/test/OpenMP/teams_distribute_dist_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_collapse_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_dist_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_collapse_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_dist_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_schedule_codegen.cpp
  clang/test/OpenMP/teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/teams_distribute_simd_collapse_codegen.cpp
  clang/test/OpenMP/teams_distribute_simd_dist_schedule_codegen.cpp
  clang/test/OpenMP/teams_firstprivate_codegen.cpp

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


[PATCH] D111078: [AIX] Enable int128 in 64 bit mode

2021-10-04 Thread Jinsong Ji via Phabricator via cfe-commits
jsji created this revision.
jsji added reviewers: PowerPC, hubert.reinterpretcast, nemanjai.
jsji requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This patch remove the override in AIX target,
so the int128 is enabled in 64 bit mode or with ForceEnableInt128.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111078

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/Driver/types.c
  llvm/test/CodeGen/PowerPC/int128_ldst.ll


Index: llvm/test/CodeGen/PowerPC/int128_ldst.ll
===
--- llvm/test/CodeGen/PowerPC/int128_ldst.ll
+++ llvm/test/CodeGen/PowerPC/int128_ldst.ll
@@ -17,6 +17,9 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
 ; RUN:   -mcpu=pwr8  \
 ; RUN:   < %s | FileCheck %s --check-prefixes=CHECK,CHECK-PREP10,CHECK-P8
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-ibm-aix-xcoff \
+; RUN:   -mcpu=pwr8  \
+; RUN:   < %s | FileCheck %s --check-prefixes=CHECK,CHECK-PREP10,CHECK-P8
 
 ; Function Attrs: norecurse nounwind readonly uwtable willreturn
 define dso_local i128 @ld_0___int128___int128(i64 %ptr) {
Index: clang/test/Driver/types.c
===
--- clang/test/Driver/types.c
+++ clang/test/Driver/types.c
@@ -12,8 +12,8 @@
 // RUN: not %clang -c --target=powerpc-ibm-aix -fsyntax-only %s \
 // RUN: 2>&1 | FileCheck %s
 
-// RUN: not %clang -c --target=powerpc64-ibm-aix -fsyntax-only %s \
-// RUN: 2>&1 | FileCheck %s
+// RUN: %clang -c --target=powerpc64-ibm-aix -fsyntax-only %s \
+// RUN: 2>&1
 
 void a() {
   __int128_t s;
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -743,7 +743,6 @@
 
   // AIX sets FLT_EVAL_METHOD to be 1.
   unsigned getFloatEvalMethod() const override { return 1; }
-  bool hasInt128Type() const override { return false; }
 
   bool defaultsToAIXPowerAlignment() const override { return true; }
 };


Index: llvm/test/CodeGen/PowerPC/int128_ldst.ll
===
--- llvm/test/CodeGen/PowerPC/int128_ldst.ll
+++ llvm/test/CodeGen/PowerPC/int128_ldst.ll
@@ -17,6 +17,9 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
 ; RUN:   -mcpu=pwr8  \
 ; RUN:   < %s | FileCheck %s --check-prefixes=CHECK,CHECK-PREP10,CHECK-P8
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-ibm-aix-xcoff \
+; RUN:   -mcpu=pwr8  \
+; RUN:   < %s | FileCheck %s --check-prefixes=CHECK,CHECK-PREP10,CHECK-P8
 
 ; Function Attrs: norecurse nounwind readonly uwtable willreturn
 define dso_local i128 @ld_0___int128___int128(i64 %ptr) {
Index: clang/test/Driver/types.c
===
--- clang/test/Driver/types.c
+++ clang/test/Driver/types.c
@@ -12,8 +12,8 @@
 // RUN: not %clang -c --target=powerpc-ibm-aix -fsyntax-only %s \
 // RUN: 2>&1 | FileCheck %s
 
-// RUN: not %clang -c --target=powerpc64-ibm-aix -fsyntax-only %s \
-// RUN: 2>&1 | FileCheck %s
+// RUN: %clang -c --target=powerpc64-ibm-aix -fsyntax-only %s \
+// RUN: 2>&1
 
 void a() {
   __int128_t s;
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -743,7 +743,6 @@
 
   // AIX sets FLT_EVAL_METHOD to be 1.
   unsigned getFloatEvalMethod() const override { return 1; }
-  bool hasInt128Type() const override { return false; }
 
   bool defaultsToAIXPowerAlignment() const override { return true; }
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105151: [OPENMP]Fix PR50733: unexpected final value of list-item in linear clause in loop construct.

2021-10-04 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 376947.
ABataev added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105151

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/for_linear_codegen.cpp
  clang/test/OpenMP/for_simd_codegen.cpp
  clang/test/OpenMP/parallel_for_linear_codegen.cpp
  clang/test/OpenMP/parallel_for_simd_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/simd_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp

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


[PATCH] D110668: [clang-cl] Accept `#pragma warning(disable : N)` for some N

2021-10-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D110668#3038858 , @xbolva00 wrote:

> In D110668#3036361 , @thakis wrote:
>
>> In D110668#3034576 , @xbolva00 
>> wrote:
>>
>>> Please next time give a bit more time to potential reviewers / other folks 
>>> outside your org. The whole lifecycle of this patch (posted - landed) took 
>>> < 24h.
>>
>> Is there anything wrong with the patch?
>>
>> I agree that it's good to let larger changes sit for a bit, but this seems 
>> like a fairly small and inconsequential change to me. Many patches land with 
>> a review time < 24h.
>>
>> In any case, happy to address post-commit review comments too of course.
>
> I think I would prefer to implement such "mapping" in DiagnosticGroups.td 
> instead of current solution. cc @aaron.ballman as well, as he is an 
> exprienced reviewer here.
>
> What I mean,  for example:
>
>   def UnusedParameter : DiagGroup<"unused-parameter", 4100>;

FWIW, I agree that this is a better approach -- I'm uncomfortable having a 
separate list of diagnostic IDs that matter. To me, this information is part of 
the diagnostic itself. Having it listed alongside the diagnostic text also 
means that when we repurpose a diagnostic to have a slightly different meaning 
(which does happen from time to time), there's something more visible in the 
reviewer's face about whether the change also means the diagnostic shouldn't 
map to a CL diagnostic (or should map to a different one). Personally, I would 
prefer to see it surfaced like this:

`def UnusedParameter : DiagGroup<"unused-parameter", [CL<4100>]>;`

so that it accepts a list of alternative IDs for the diagnostic. We currently 
only care about the stable numbering from cl.exe, but there's no reason we 
wouldn't want to use this for other kinds of diagnostic grouping aliases. For 
example, someday we may want to use these same facilities to map between Clang 
diagnostic groups and GCC diagnostic groups where we surfaced different names 
for the group by accident.

In D110668#3040408 , @thakis wrote:

> That's an interesting idea.
>
> Given how seldom this is used, I weakly prefer having actual code for this 
> though: It makes it easy to see all of those mapped flags, and it keeps 
> rarely used things out of tablegen, which is imho a good thing.

If we want to make it easy to see all the mapped flags, we can add a -cc1 
option to dump them out in a more consumable manner, so I think we have 
solutions we can use there. I don't see this as being a rarely used thing 
though -- it's the stable identifier for the diagnostic, so it strongly relates 
to the definition of the diagnostic itself. This comes up in user-facing ways 
like through `#pragma warning`, so it seems worth it to have it in tablegen, at 
least to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110668

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


[PATCH] D111079: [Clang] Add core papers added in the October 2021 WG21 plenary.

2021-10-04 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
cor3ntin 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/D111079

Files:
  clang/www/cxx_status.html


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1321,6 +1321,53 @@
   https://wg21.link/p2201r1";>P2201R1
   Yes
 
+
+
+  Deducing this
+  https://wg21.link/P0847R7";>P0847R7
+  No
+
+
+  Change scope of lambda trailing-return-type
+  https://wg21.link/P2036R3";>P2036R3
+  No
+
+
+  Multidimensional subscript operator
+  https://wg21.link/P2128R6";>P2128R6
+  No
+
+
+  Non-literal variables (and labels and gotos) in constexpr 
functions)
+  https://wg21.link/P2242R3";>P2242R3
+  No
+
+
+  Character encoding of diagnostic text
+  https://wg21.link/P2246R1";>P2246R1
+  Yes
+
+
+  Character sets and encodings
+  https://wg21.link/P2314R4";>P2314R4
+  Yes
+
+
+  Consistent character literal encoding
+  https://wg21.link/P2316R2";>P2316R2
+  Yes
+
+
+  Add support for preprocessing directives elifdef and elifndef
+  https://wg21.link/P2334R1";>P2334R1
+  Clang 13
+
+
+  Extend init-statement to allow alias-declaration
+  https://wg21.link/P2360R0";>P2360R0
+  No
+
+
 
 
 


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1321,6 +1321,53 @@
   https://wg21.link/p2201r1";>P2201R1
   Yes
 
+
+
+  Deducing this
+  https://wg21.link/P0847R7";>P0847R7
+  No
+
+
+  Change scope of lambda trailing-return-type
+  https://wg21.link/P2036R3";>P2036R3
+  No
+
+
+  Multidimensional subscript operator
+  https://wg21.link/P2128R6";>P2128R6
+  No
+
+
+  Non-literal variables (and labels and gotos) in constexpr functions)
+  https://wg21.link/P2242R3";>P2242R3
+  No
+
+
+  Character encoding of diagnostic text
+  https://wg21.link/P2246R1";>P2246R1
+  Yes
+
+
+  Character sets and encodings
+  https://wg21.link/P2314R4";>P2314R4
+  Yes
+
+
+  Consistent character literal encoding
+  https://wg21.link/P2316R2";>P2316R2
+  Yes
+
+
+  Add support for preprocessing directives elifdef and elifndef
+  https://wg21.link/P2334R1";>P2334R1
+  Clang 13
+
+
+  Extend init-statement to allow alias-declaration
+  https://wg21.link/P2360R0";>P2360R0
+  No
+
+
 
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110482: [clang] Implement if consteval (P1938)

2021-10-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: rsmith.
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Aside from a nit, I think this is ready to go. Adding Richard in case he has 
the chance to give this a once-over before it lands.




Comment at: clang/lib/Parse/ParseStmt.cpp:1522-1526
+auto IsCompoundStatement = [](const Stmt *Stmt) {
+  if (const AttributedStmt *Outer = dyn_cast_or_null(Stmt))
+Stmt = Outer->getSubStmt();
+  return isa_and_nonnull(Stmt);
+};





Comment at: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p4.cpp:4
+void test_consteval() {
+  if consteval ({1;}); // expected-error {{expected { after consteval}}
+  if consteval (void) 0; // expected-error {{expected { after consteval}}

It looks like you dropped the test for GNU statement expressions; can you add 
that one back (it's helpful to ensure we don't accidentally regress behavior in 
the future given how closely these relate to compound statements already).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110482

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


[PATCH] D110482: [clang] Implement if consteval (P1938)

2021-10-04 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 376961.
cor3ntin added a comment.

Address nits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110482

Files:
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/Stmt.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/Analysis/CFG.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/JumpDiagnostics.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  clang/test/AST/Interp/if_consteval.cpp
  clang/test/AST/ast-dump-if-json.cpp
  clang/test/AST/ast-dump-stmt.cpp
  clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p4.cpp
  clang/test/CodeGenCXX/cxx2b-consteval-if.cpp

Index: clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -o - | FileCheck %s
+
+void should_be_used_1();
+void should_be_used_2();
+void should_be_used_3();
+constexpr void should_not_be_used() {}
+
+constexpr void f() {
+  if consteval {
+should_not_be_used(); // CHECK-NOT: call {{.*}}should_not_be_used
+  } else {
+should_be_used_1();  // CHECK: call {{.*}}should_be_used_1
+  }
+
+  if !consteval {
+should_be_used_2();  // CHECK: call {{.*}}should_be_used_2
+  }
+
+  if !consteval {
+should_be_used_3();  // CHECK: call {{.*}}should_be_used_3
+  } else {
+should_not_be_used(); // CHECK-NOT: call {{.*}}should_not_be_used
+  }
+}
+
+void g() {
+  f();
+}
Index: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p4.cpp
===
--- /dev/null
+++ clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p4.cpp
@@ -0,0 +1,158 @@
+// RUN: %clang_cc1 -std=c++2b -verify %s
+
+void test_consteval() {
+  if consteval ({(void)1;});  // expected-error {{expected { after consteval}}
+  if consteval (void) 0; // expected-error {{expected { after consteval}}
+  if consteval {
+(void)0;
+  } else (void)0; // expected-error {{expected { after else}}
+
+  static_assert([] {
+if consteval {
+  return 0;
+}
+return 1;
+  }() == 0);
+
+  static_assert([] {
+if consteval {
+  return 0;
+} else {
+  return 1;
+}
+  }() == 0);
+
+  static_assert([] {
+if !consteval {
+  return 0;
+} else {
+  return 1;
+}
+  }() == 1);
+
+  static_assert([] {
+if not consteval {
+  return 0;
+}
+return 1;
+  }() == 1);
+
+  if consteval [[likely]] { // expected-warning {{attribute 'likely' has no effect when annotating an 'if consteval' statement}}\
+// expected-note 2{{annotating the 'if consteval' statement here}}
+
+
+  }
+  else [[unlikely]] { // expected-warning {{attribute 'unlikely' has no effect when annotating an 'if consteval' statement}}
+
+  }
+
+}
+
+void test_consteval_jumps() {
+  if consteval { // expected-note 4{{jump enters controlled statement of consteval if}}
+goto a;
+goto b; // expected-error {{cannot jump from this goto statement to its label}}
+  a:;
+  } else {
+goto b;
+goto a; // expected-error {{cannot jump from this goto statement to its label}}
+  b:;
+  }
+  goto a; // expected-error {{cannot jump from this goto statement to its label}}
+  goto b; // expected-error {{cannot jump from this goto statement to its label}}
+}
+
+void test_consteval_switch() {
+  int x = 42;
+  switch (x) {
+if consteval { // expected-note 2{{jump enters controlled statement of consteval if}}
+case 1:;   // expected-error {{cannot jump from switch statement to this case label}}
+default:;  // expected-error {{cannot jump from switch statement to this case label}}
+} else {
+}
+  }
+  switch (x) {
+if consteval { // expected-note 2{{jump enters controlled statement of consteval if}}
+} else {
+case 2:;  // expected-error {{cannot jump from switch statement to this case label}}
+default:; // expected-error {{cannot jump from switch statement to this case label}}
+}
+  }
+}
+
+consteval int f(int i) { return i; }
+constexpr int g(int i) {
+  if consteval {
+return f(i);
+  } e

[PATCH] D110824: [PowerPC] Fix to guard fetch and cas 64-bit builtin versions

2021-10-04 Thread Kamau Bridgeman via Phabricator via cfe-commits
kamaub updated this revision to Diff 376962.
kamaub added a comment.

Moving test case to correct file before commiting as request in review comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110824

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-error.c


Index: clang/test/CodeGen/builtins-ppc-xlcompat-error.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-error.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-error.c
@@ -104,6 +104,25 @@
 int test_darn_raw() {
   return __darn_raw(); //expected-error {{this builtin is only available on 
64-bit targets}}
 }
+
+int test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
+  return __compare_and_swaplp(&a, &b, c); // expected-error {{this builtin is 
only available on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_addlp(long a, long b) {
+  __fetch_and_addlp(&a, b); // expected-error {{this builtin is only available 
on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_andlp(unsigned long a, unsigned long b) {
+  __fetch_and_andlp(&a, b); // expected-error {{this builtin is only available 
on 64-bit targets}}
+}
+void test_builtin_ppc_fetch_and_orlp(unsigned long a, unsigned long b) {
+  __fetch_and_orlp(&a, b); // expected-error {{this builtin is only available 
on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_swaplp(unsigned long a, unsigned long b) {
+  __fetch_and_swaplp(&a, b); // expected-error {{this builtin is only 
available on 64-bit targets}}
+}
 #endif
 
 unsigned long test_mfspr(void) {
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3297,6 +3297,11 @@
   case PPC::BI__builtin_ppc_addex:
   case PPC::BI__builtin_darn:
   case PPC::BI__builtin_darn_raw:
+  case PPC::BI__builtin_ppc_compare_and_swaplp:
+  case PPC::BI__builtin_ppc_fetch_and_addlp:
+  case PPC::BI__builtin_ppc_fetch_and_andlp:
+  case PPC::BI__builtin_ppc_fetch_and_orlp:
+  case PPC::BI__builtin_ppc_fetch_and_swaplp:
 return true;
   }
   return false;


Index: clang/test/CodeGen/builtins-ppc-xlcompat-error.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-error.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-error.c
@@ -104,6 +104,25 @@
 int test_darn_raw() {
   return __darn_raw(); //expected-error {{this builtin is only available on 64-bit targets}}
 }
+
+int test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
+  return __compare_and_swaplp(&a, &b, c); // expected-error {{this builtin is only available on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_addlp(long a, long b) {
+  __fetch_and_addlp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_andlp(unsigned long a, unsigned long b) {
+  __fetch_and_andlp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
+}
+void test_builtin_ppc_fetch_and_orlp(unsigned long a, unsigned long b) {
+  __fetch_and_orlp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_swaplp(unsigned long a, unsigned long b) {
+  __fetch_and_swaplp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
+}
 #endif
 
 unsigned long test_mfspr(void) {
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3297,6 +3297,11 @@
   case PPC::BI__builtin_ppc_addex:
   case PPC::BI__builtin_darn:
   case PPC::BI__builtin_darn_raw:
+  case PPC::BI__builtin_ppc_compare_and_swaplp:
+  case PPC::BI__builtin_ppc_fetch_and_addlp:
+  case PPC::BI__builtin_ppc_fetch_and_andlp:
+  case PPC::BI__builtin_ppc_fetch_and_orlp:
+  case PPC::BI__builtin_ppc_fetch_and_swaplp:
 return true;
   }
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111078: [AIX] Enable int128 in 64 bit mode

2021-10-04 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

Making a change to whether a platform has `__int128` affects the ABI of 
libc++'s `std::chrono::file_clock`. We should make sure the mitigation patch is 
posted and accepted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111078

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


[PATCH] D111079: [Clang] Add core papers added in the October 2021 WG21 plenary.

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

LGTM, thanks! (Don't worry about the extra paren I found, I'll handle that when 
I land this.)




Comment at: clang/www/cxx_status.html:1341
+
+  Non-literal variables (and labels and gotos) in constexpr 
functions)
+  https://wg21.link/P2242R3";>P2242R3




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111079

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


[PATCH] D110216: [clang] retain type sugar in auto / template argument deduction

2021-10-04 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchersInternal.h:1032
 if (const auto *S = dyn_cast(&Node)) {
-  EffectiveType = S->getDeducedType().getTypePtrOrNull();
-  if (!EffectiveType)
-return false;
+  QualType T = S->getDeducedType();
+  return !T.isNull() ? matchesSpecialized(*T, Finder, Builder) : false;

gcc 8.4.1 doesn't like `T` being the same name as a template parameter for this 
class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110216

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


[PATCH] D110482: [clang] Implement if consteval (P1938)

2021-10-04 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 376967.
cor3ntin added a comment.

Fix compilation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110482

Files:
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/Stmt.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/Analysis/CFG.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/JumpDiagnostics.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  clang/test/AST/Interp/if_consteval.cpp
  clang/test/AST/ast-dump-if-json.cpp
  clang/test/AST/ast-dump-stmt.cpp
  clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p4.cpp
  clang/test/CodeGenCXX/cxx2b-consteval-if.cpp

Index: clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -o - | FileCheck %s
+
+void should_be_used_1();
+void should_be_used_2();
+void should_be_used_3();
+constexpr void should_not_be_used() {}
+
+constexpr void f() {
+  if consteval {
+should_not_be_used(); // CHECK-NOT: call {{.*}}should_not_be_used
+  } else {
+should_be_used_1();  // CHECK: call {{.*}}should_be_used_1
+  }
+
+  if !consteval {
+should_be_used_2();  // CHECK: call {{.*}}should_be_used_2
+  }
+
+  if !consteval {
+should_be_used_3();  // CHECK: call {{.*}}should_be_used_3
+  } else {
+should_not_be_used(); // CHECK-NOT: call {{.*}}should_not_be_used
+  }
+}
+
+void g() {
+  f();
+}
Index: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p4.cpp
===
--- /dev/null
+++ clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p4.cpp
@@ -0,0 +1,158 @@
+// RUN: %clang_cc1 -std=c++2b -verify %s
+
+void test_consteval() {
+  if consteval ({(void)1;});  // expected-error {{expected { after consteval}}
+  if consteval (void) 0; // expected-error {{expected { after consteval}}
+  if consteval {
+(void)0;
+  } else (void)0; // expected-error {{expected { after else}}
+
+  static_assert([] {
+if consteval {
+  return 0;
+}
+return 1;
+  }() == 0);
+
+  static_assert([] {
+if consteval {
+  return 0;
+} else {
+  return 1;
+}
+  }() == 0);
+
+  static_assert([] {
+if !consteval {
+  return 0;
+} else {
+  return 1;
+}
+  }() == 1);
+
+  static_assert([] {
+if not consteval {
+  return 0;
+}
+return 1;
+  }() == 1);
+
+  if consteval [[likely]] { // expected-warning {{attribute 'likely' has no effect when annotating an 'if consteval' statement}}\
+// expected-note 2{{annotating the 'if consteval' statement here}}
+
+
+  }
+  else [[unlikely]] { // expected-warning {{attribute 'unlikely' has no effect when annotating an 'if consteval' statement}}
+
+  }
+
+}
+
+void test_consteval_jumps() {
+  if consteval { // expected-note 4{{jump enters controlled statement of consteval if}}
+goto a;
+goto b; // expected-error {{cannot jump from this goto statement to its label}}
+  a:;
+  } else {
+goto b;
+goto a; // expected-error {{cannot jump from this goto statement to its label}}
+  b:;
+  }
+  goto a; // expected-error {{cannot jump from this goto statement to its label}}
+  goto b; // expected-error {{cannot jump from this goto statement to its label}}
+}
+
+void test_consteval_switch() {
+  int x = 42;
+  switch (x) {
+if consteval { // expected-note 2{{jump enters controlled statement of consteval if}}
+case 1:;   // expected-error {{cannot jump from switch statement to this case label}}
+default:;  // expected-error {{cannot jump from switch statement to this case label}}
+} else {
+}
+  }
+  switch (x) {
+if consteval { // expected-note 2{{jump enters controlled statement of consteval if}}
+} else {
+case 2:;  // expected-error {{cannot jump from switch statement to this case label}}
+default:; // expected-error {{cannot jump from switch statement to this case label}}
+}
+  }
+}
+
+consteval int f(int i) { return i; }
+constexpr int g(int i) {
+  if consteval {
+return f(i);
+  

[clang] 922863e - Add core papers added in the October 2021 WG21 plenary

2021-10-04 Thread Aaron Ballman via cfe-commits

Author: Corentin Jabot
Date: 2021-10-04T14:42:13-04:00
New Revision: 922863e75f10db3bff001483279ba649d9735f46

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

LOG: Add core papers added in the October 2021 WG21 plenary

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 9ded88755836d..f3d1edf08cb97 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -1321,6 +1321,53 @@ C++2b implementation status
   https://wg21.link/p2201r1";>P2201R1
   Yes
 
+
+
+  Deducing this
+  https://wg21.link/P0847R7";>P0847R7
+  No
+
+
+  Change scope of lambda trailing-return-type
+  https://wg21.link/P2036R3";>P2036R3
+  No
+
+
+  Multidimensional subscript operator
+  https://wg21.link/P2128R6";>P2128R6
+  No
+
+
+  Non-literal variables (and labels and gotos) in constexpr 
functions
+  https://wg21.link/P2242R3";>P2242R3
+  No
+
+
+  Character encoding of diagnostic text
+  https://wg21.link/P2246R1";>P2246R1
+  Yes
+
+
+  Character sets and encodings
+  https://wg21.link/P2314R4";>P2314R4
+  Yes
+
+
+  Consistent character literal encoding
+  https://wg21.link/P2316R2";>P2316R2
+  Yes
+
+
+  Add support for preprocessing directives elifdef and elifndef
+  https://wg21.link/P2334R1";>P2334R1
+  Clang 13
+
+
+  Extend init-statement to allow alias-declaration
+  https://wg21.link/P2360R0";>P2360R0
+  No
+
+
 
 
 



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


[PATCH] D111079: [Clang] Add core papers added in the October 2021 WG21 plenary.

2021-10-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

Thanks! I've commit on your behalf in 922863e75f10db3bff001483279ba649d9735f46 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111079

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


[PATCH] D109178: [PowerPC] Disable vector types when not supported by subtarget features

2021-10-04 Thread Lei Huang via Phabricator via cfe-commits
lei updated this revision to Diff 376969.
lei added a comment.

address line comment and update tc to reflect new behaviour.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109178

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Headers/altivec.h
  clang/lib/Sema/DeclSpec.cpp
  clang/test/CodeGen/builtins-ppc-int128.c
  clang/test/CodeGen/builtins-ppc-vsx.c
  clang/test/Parser/altivec-bool-128.c
  clang/test/Parser/altivec.c
  clang/test/Parser/cxx-altivec-bool-128.cpp
  clang/test/Parser/cxx-altivec.cpp
  clang/test/Sema/altivec-generic-overload.c
  clang/test/Sema/builtins-ppc.c

Index: clang/test/Sema/builtins-ppc.c
===
--- clang/test/Sema/builtins-ppc.c
+++ clang/test/Sema/builtins-ppc.c
@@ -6,6 +6,9 @@
 // RUN: %clang_cc1 -target-feature +altivec -target-feature +crypto\
 // RUN: -triple powerpc64le-unknown-unknown -DTEST_CRYPTO -fsyntax-only  \
 // RUN: -verify %s
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +crypto \
+// RUN: -triple powerpc64le-unknown-unknown -DTEST_CRYPTO -fsyntax-only \
+// RUN: -target-feature +vsx -verify %s
 
 #ifdef TEST_HTM
 void test_htm() {
@@ -37,6 +40,7 @@
   return __builtin_crypto_vshasigmaw(a, 1, 15);
 }
 
+#ifdef __VSX__
 vector unsigned long long test_vshasigmad_or(void)
 {
   vector unsigned long long a = D_INIT
@@ -46,6 +50,7 @@
   vector unsigned long long e = __builtin_crypto_vshasigmad(a, 1, -15); // expected-error-re {{argument value {{.*}} is outside the valid range}}
   return __builtin_crypto_vshasigmad(a, 0, 15);
 }
+#endif
 
 #endif
 
Index: clang/test/Sema/altivec-generic-overload.c
===
--- clang/test/Sema/altivec-generic-overload.c
+++ clang/test/Sema/altivec-generic-overload.c
@@ -1,4 +1,8 @@
-// RUN: %clang_cc1 %s -triple=powerpc64le-unknown-linux -target-feature +altivec -target-feature +vsx -verify -verify-ignore-unexpected=note -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -triple=powerpc64le-unknown-linux -target-feature +altivec \
+// RUN:  -target-feature +vsx -verify -verify-ignore-unexpected=note -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -triple=powerpc64le-unknown-linux -target-feature +altivec \
+// RUN:  -target-feature +vsx -verify -verify-ignore-unexpected=note -pedantic -fsyntax-only \
+// RUN:  -target-cpu pwr8
 
 typedef signed char __v16sc __attribute__((__vector_size__(16)));
 typedef unsigned char __v16uc __attribute__((__vector_size__(16)));
@@ -20,9 +24,6 @@
 __v4si *__attribute__((__overloadable__)) convert1(vector signed int);
 __v4ui *__attribute__((__overloadable__)) convert1(vector unsigned int);
 __v2sll *__attribute__((__overloadable__)) convert1(vector signed long long);
-__v2ull *__attribute__((__overloadable__)) convert1(vector unsigned long long);
-__v1slll *__attribute__((__overloadable__)) convert1(vector signed __int128);
-__v1ulll *__attribute__((__overloadable__)) convert1(vector unsigned __int128);
 __v4f *__attribute__((__overloadable__)) convert1(vector float);
 __v2d *__attribute__((__overloadable__)) convert1(vector double);
 void __attribute__((__overloadable__)) convert1(vector bool int);
@@ -36,11 +37,17 @@
 vector unsigned int *__attribute__((__overloadable__)) convert2(__v4ui);
 vector signed long long *__attribute__((__overloadable__)) convert2(__v2sll);
 vector unsigned long long *__attribute__((__overloadable__)) convert2(__v2ull);
-vector signed __int128 *__attribute__((__overloadable__)) convert2(__v1slll);
-vector unsigned __int128 *__attribute__((__overloadable__)) convert2(__v1ulll);
 vector float *__attribute__((__overloadable__)) convert2(__v4f);
 vector double *__attribute__((__overloadable__)) convert2(__v2d);
 
+#ifdef __POWER8_VECTOR__
+__v1slll *__attribute__((__overloadable__)) convert1(vector signed __int128);
+__v1ulll *__attribute__((__overloadable__)) convert1(vector unsigned __int128);
+__v2ull *__attribute__((__overloadable__)) convert1(vector unsigned long long);
+vector signed __int128 *__attribute__((__overloadable__)) convert2(__v1slll);
+vector unsigned __int128 *__attribute__((__overloadable__)) convert2(__v1ulll);
+#endif
+
 void test() {
   __v16sc gv1;
   __v16uc gv2;
@@ -49,11 +56,14 @@
   __v4si gv5;
   __v4ui gv6;
   __v2sll gv7;
+  __v4f gv11;
+  __v2d gv12;
+
+#ifdef __POWER8_VECTOR__
   __v2ull gv8;
   __v1slll gv9;
   __v1ulll gv10;
-  __v4f gv11;
-  __v2d gv12;
+#endif
 
   vector signed char av1;
   vector unsigned char av2;
@@ -63,8 +73,10 @@
   vector unsigned int av6;
   vector signed long long av7;
   vector unsigned long long av8;
+#ifdef __POWER8_VECTOR__
   vector signed __int128 av9;
   vector unsigned __int128 av10;
+#endif
   vector float av11;
   vector double av12;
   vector bool int av13;
@@ -77,9 +89,11 @@
   __v4si *gv5_p = convert1(gv5);
   __v4ui *gv6_p = convert1(gv6);
 

[PATCH] D110614: [clang-tidy] Fix false positives in cppcoreguidelines-virtual-class-destructor

2021-10-04 Thread Marco Gartmann via Phabricator via cfe-commits
mgartmann added a comment.

Please excuse my late reply! I have been on vacation for the last two weeks and 
didn't have the time to respond to this thread until now.

In D110614#3032760 , @carlosgalvezp 
wrote:

> So the derived destructor only shows up in `ClassTemplateSpecializationDecl` 
> - the `CXXRecordDecl` doesn't have it (therefore implicit public non-virtual) 
> and that's why the check triggers.

I came to the same conclusion with a quick troubleshoot. Honestly, I didn't 
expect SEMA to behave this way and to generate CXXRecordDecl nodes without any 
CXXDestructorDecl sub-node. 
As a rather novice C++ programmer, I didn't have the described scenarios in 
mind when I initially created the check. Hence, the needed tests to find these 
false-positives beforehand were missing. 
I would like to apologise to everyone for the trouble this has caused.

@carlosgalvezp Thanks a lot for putting your time and effort into fix this bug!

In D110614#3038519 , @carlosgalvezp 
wrote:

> Anyway this check will need to be extended in the future, since the C++ Core 
> Guidelines has added a new bullet in their "Enforcement" section:
> https://github.com/isocpp/CppCoreGuidelines/commit/e44a9fcbd40923e9d5d342e444cf8a811e4a3eae

Thanks for pointing this out to me. Let me know if I can help you with this in 
any way. I would be available to implement the new enforcement from 2021-10-11 
on.

Again, my dearest apologies for this bug.


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

https://reviews.llvm.org/D110614

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


[PATCH] D110600: [clang-tidy] Fix add_new_check.py to generate correct list.rst autofix column from relative path

2021-10-04 Thread Matt Beardsley via Phabricator via cfe-commits
mattbeardsley added a comment.

Thanks! Could you help me commit again when you have time? (same info as here 
)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110600

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


[PATCH] D110216: [clang] retain type sugar in auto / template argument deduction

2021-10-04 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Looks like this fixes PR51282.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110216

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


[PATCH] D110668: [clang-cl] Accept `#pragma warning(disable : N)` for some N

2021-10-04 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Thanks for the feedback. I'll work on a follow-up that implements that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110668

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


[clang] 8b3d944 - [PowerPC] Disable vector types when not supported by subtarget features

2021-10-04 Thread Lei Huang via cfe-commits

Author: Lei Huang
Date: 2021-10-04T14:16:47-05:00
New Revision: 8b3d944a97cc944a24ed1296c801da5654896092

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

LOG: [PowerPC] Disable vector types when not supported by subtarget features

Update clang to treat vector unsigned long long and friends as invalid
for AltiVec without VSX.

Reported in: https://bugs.llvm.org/show_bug.cgi?id=47782

Reviewed By: nemanjai, amyk

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

Added: 
clang/test/CodeGen/builtins-ppc-int128.c

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Headers/altivec.h
clang/lib/Sema/DeclSpec.cpp
clang/test/CodeGen/builtins-ppc-vsx.c
clang/test/Parser/altivec-bool-128.c
clang/test/Parser/altivec.c
clang/test/Parser/cxx-altivec-bool-128.cpp
clang/test/Parser/cxx-altivec.cpp
clang/test/Sema/altivec-generic-overload.c
clang/test/Sema/builtins-ppc.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c71a00b184328..96cb4a0fcb96f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -268,10 +268,12 @@ def err_invalid_vector_double_decl_spec : Error <
 def err_invalid_vector_bool_int128_decl_spec : Error <
   "use of '__int128' with '__vector bool' requires VSX support enabled (on "
   "POWER10 or later)">;
+def err_invalid_vector_int128_decl_spec : Error<
+  "use of '__int128' with '__vector' requires extended Altivec support"
+  " (available on POWER8 or later)">;
 def err_invalid_vector_long_long_decl_spec : Error <
-  "use of 'long long' with '__vector bool' requires VSX support (available on "
-  "POWER7 or later) or extended Altivec support (available on POWER8 or later) 
"
-  "to be enabled">;
+  "use of 'long long' with '__vector' requires VSX support (available on "
+  "POWER7 or later) to be enabled">;
 def err_invalid_vector_long_double_decl_spec : Error<
   "cannot use 'long double' with '__vector'">;
 def warn_vector_long_decl_spec_combination : Warning<

diff  --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h
index 5da4fbf72ce97..4e229a4bf510c 100644
--- a/clang/lib/Headers/altivec.h
+++ b/clang/lib/Headers/altivec.h
@@ -8842,7 +8842,7 @@ static __inline__ vector long long __ATTRS_o_ai
 vec_sl(vector long long __a, vector unsigned long long __b) {
   return (vector long long)vec_sl((vector unsigned long long)__a, __b);
 }
-#else
+#elif defined(__VSX__)
 static __inline__ vector unsigned char __ATTRS_o_ai
 vec_vspltb(vector unsigned char __a, unsigned char __b);
 static __inline__ vector unsigned long long __ATTRS_o_ai
@@ -,7 +,7 @@ static __inline__ vector long long __ATTRS_o_ai
 vec_sl(vector long long __a, vector unsigned long long __b) {
   return (vector long long)vec_sl((vector unsigned long long)__a, __b);
 }
-#endif
+#endif /* __VSX__ */
 
 /* vec_vslb */
 
@@ -10353,7 +10353,7 @@ static __inline__ vector long long __ATTRS_o_ai
 vec_sr(vector long long __a, vector unsigned long long __b) {
   return (vector long long)vec_sr((vector unsigned long long)__a, __b);
 }
-#else
+#elif defined(__VSX__)
 static __inline__ vector unsigned long long __ATTRS_o_ai
 vec_sr(vector unsigned long long __a, vector unsigned long long __b) {
   __b %= (vector unsigned long long)(sizeof(unsigned long long) * 
__CHAR_BIT__);
@@ -10397,7 +10397,7 @@ static __inline__ vector long long __ATTRS_o_ai
 vec_sr(vector long long __a, vector unsigned long long __b) {
   return (vector long long)vec_sr((vector unsigned long long)__a, __b);
 }
-#endif
+#endif /* __VSX__ */
 
 /* vec_vsrb */
 
@@ -10483,7 +10483,7 @@ static __inline__ vector unsigned long long __ATTRS_o_ai
 vec_sra(vector unsigned long long __a, vector unsigned long long __b) {
   return (vector unsigned long long)((vector signed long long)__a >> __b);
 }
-#else
+#elif defined(__VSX__)
 static __inline__ vector signed long long __ATTRS_o_ai
 vec_sra(vector signed long long __a, vector unsigned long long __b) {
   __b %= (vector unsigned long long)(sizeof(unsigned long long) * 
__CHAR_BIT__);
@@ -10495,7 +10495,7 @@ vec_sra(vector unsigned long long __a, vector unsigned 
long long __b) {
   __b %= (vector unsigned long long)(sizeof(unsigned long long) * 
__CHAR_BIT__);
   return (vector unsigned long long)((vector signed long long)__a >> __b);
 }
-#endif
+#endif /* __VSX__ */
 
 /* vec_vsrab */
 
@@ -17227,6 +17227,7 @@ provided.
 #define vec_ncipher_be __builtin_altivec_crypto_vncipher
 #define vec_ncipherlast_be __builtin_altivec_crypto_vncipherlast
 
+#ifdef __VSX__
 static __inline__ vector unsigned long long __attribute__((__always_inline__))
 __builtin_crypto_vsbox(vector unsigned lon

[PATCH] D109178: [PowerPC] Disable vector types when not supported by subtarget features

2021-10-04 Thread Lei Huang 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 rG8b3d944a97cc: [PowerPC] Disable vector types when not 
supported by subtarget features (authored by lei).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109178

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Headers/altivec.h
  clang/lib/Sema/DeclSpec.cpp
  clang/test/CodeGen/builtins-ppc-int128.c
  clang/test/CodeGen/builtins-ppc-vsx.c
  clang/test/Parser/altivec-bool-128.c
  clang/test/Parser/altivec.c
  clang/test/Parser/cxx-altivec-bool-128.cpp
  clang/test/Parser/cxx-altivec.cpp
  clang/test/Sema/altivec-generic-overload.c
  clang/test/Sema/builtins-ppc.c

Index: clang/test/Sema/builtins-ppc.c
===
--- clang/test/Sema/builtins-ppc.c
+++ clang/test/Sema/builtins-ppc.c
@@ -6,6 +6,9 @@
 // RUN: %clang_cc1 -target-feature +altivec -target-feature +crypto\
 // RUN: -triple powerpc64le-unknown-unknown -DTEST_CRYPTO -fsyntax-only  \
 // RUN: -verify %s
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +crypto \
+// RUN: -triple powerpc64le-unknown-unknown -DTEST_CRYPTO -fsyntax-only \
+// RUN: -target-feature +vsx -verify %s
 
 #ifdef TEST_HTM
 void test_htm() {
@@ -37,6 +40,7 @@
   return __builtin_crypto_vshasigmaw(a, 1, 15);
 }
 
+#ifdef __VSX__
 vector unsigned long long test_vshasigmad_or(void)
 {
   vector unsigned long long a = D_INIT
@@ -46,6 +50,7 @@
   vector unsigned long long e = __builtin_crypto_vshasigmad(a, 1, -15); // expected-error-re {{argument value {{.*}} is outside the valid range}}
   return __builtin_crypto_vshasigmad(a, 0, 15);
 }
+#endif
 
 #endif
 
Index: clang/test/Sema/altivec-generic-overload.c
===
--- clang/test/Sema/altivec-generic-overload.c
+++ clang/test/Sema/altivec-generic-overload.c
@@ -1,4 +1,8 @@
-// RUN: %clang_cc1 %s -triple=powerpc64le-unknown-linux -target-feature +altivec -target-feature +vsx -verify -verify-ignore-unexpected=note -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -triple=powerpc64le-unknown-linux -target-feature +altivec \
+// RUN:  -target-feature +vsx -verify -verify-ignore-unexpected=note -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -triple=powerpc64le-unknown-linux -target-feature +altivec \
+// RUN:  -target-feature +vsx -verify -verify-ignore-unexpected=note -pedantic -fsyntax-only \
+// RUN:  -target-cpu pwr8
 
 typedef signed char __v16sc __attribute__((__vector_size__(16)));
 typedef unsigned char __v16uc __attribute__((__vector_size__(16)));
@@ -20,9 +24,6 @@
 __v4si *__attribute__((__overloadable__)) convert1(vector signed int);
 __v4ui *__attribute__((__overloadable__)) convert1(vector unsigned int);
 __v2sll *__attribute__((__overloadable__)) convert1(vector signed long long);
-__v2ull *__attribute__((__overloadable__)) convert1(vector unsigned long long);
-__v1slll *__attribute__((__overloadable__)) convert1(vector signed __int128);
-__v1ulll *__attribute__((__overloadable__)) convert1(vector unsigned __int128);
 __v4f *__attribute__((__overloadable__)) convert1(vector float);
 __v2d *__attribute__((__overloadable__)) convert1(vector double);
 void __attribute__((__overloadable__)) convert1(vector bool int);
@@ -36,11 +37,17 @@
 vector unsigned int *__attribute__((__overloadable__)) convert2(__v4ui);
 vector signed long long *__attribute__((__overloadable__)) convert2(__v2sll);
 vector unsigned long long *__attribute__((__overloadable__)) convert2(__v2ull);
-vector signed __int128 *__attribute__((__overloadable__)) convert2(__v1slll);
-vector unsigned __int128 *__attribute__((__overloadable__)) convert2(__v1ulll);
 vector float *__attribute__((__overloadable__)) convert2(__v4f);
 vector double *__attribute__((__overloadable__)) convert2(__v2d);
 
+#ifdef __POWER8_VECTOR__
+__v1slll *__attribute__((__overloadable__)) convert1(vector signed __int128);
+__v1ulll *__attribute__((__overloadable__)) convert1(vector unsigned __int128);
+__v2ull *__attribute__((__overloadable__)) convert1(vector unsigned long long);
+vector signed __int128 *__attribute__((__overloadable__)) convert2(__v1slll);
+vector unsigned __int128 *__attribute__((__overloadable__)) convert2(__v1ulll);
+#endif
+
 void test() {
   __v16sc gv1;
   __v16uc gv2;
@@ -49,11 +56,14 @@
   __v4si gv5;
   __v4ui gv6;
   __v2sll gv7;
+  __v4f gv11;
+  __v2d gv12;
+
+#ifdef __POWER8_VECTOR__
   __v2ull gv8;
   __v1slll gv9;
   __v1ulll gv10;
-  __v4f gv11;
-  __v2d gv12;
+#endif
 
   vector signed char av1;
   vector unsigned char av2;
@@ -63,8 +73,10 @@
   vector unsigned int av6;
   vector signed long long av7;
   vector unsigned long long av8;
+#ifdef __POWER8_VECTOR__
   vector signed __int128 av9;
   vector unsigned __int128 av10;
+#endif
   vector float av11;
   vect

[PATCH] D110216: [clang] retain type sugar in auto / template argument deduction

2021-10-04 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov marked an inline comment as done.
mizvekov added a comment.

In D110216#3040748 , @craig.topper 
wrote:

> Looks like this fixes PR51282.

Okay, interesting. This could be just papering over the bug.
Do you still lose this alignment if it goes through a template argument?
If you do, this looks like a canonicalization bug.




Comment at: clang/include/clang/ASTMatchers/ASTMatchersInternal.h:1032
 if (const auto *S = dyn_cast(&Node)) {
-  EffectiveType = S->getDeducedType().getTypePtrOrNull();
-  if (!EffectiveType)
-return false;
+  QualType T = S->getDeducedType();
+  return !T.isNull() ? matchesSpecialized(*T, Finder, Builder) : false;

craig.topper wrote:
> gcc 8.4.1 doesn't like `T` being the same name as a template parameter for 
> this class.
Oh wow, didn't even realize, thanks!!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110216

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


[clang] 56e72a4 - Update `DynTypedNode` to support the conversion of `TypeLoc`s.

2021-10-04 Thread Yitzhak Mandelbaum via cfe-commits

Author: James King
Date: 2021-10-04T19:25:24Z
New Revision: 56e72a40c1985529399738f66c6f4c24029112d6

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

LOG: Update `DynTypedNode` to support the conversion of `TypeLoc`s.

This provides better support for `TypeLoc`s to allow `TypeLoc`-related
matchers to feature stricter typing and to avoid relying on the dynamic
casting of `TypeLoc`s in matchers.

Reviewed By: ymandel, tdl-g, sbenza

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

Added: 


Modified: 
clang/include/clang/AST/ASTTypeTraits.h
clang/lib/AST/ASTTypeTraits.cpp
clang/unittests/AST/ASTTypeTraitsTest.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTTypeTraits.h 
b/clang/include/clang/AST/ASTTypeTraits.h
index 950b02d1ab6bf..144977b3cd219 100644
--- a/clang/include/clang/AST/ASTTypeTraits.h
+++ b/clang/include/clang/AST/ASTTypeTraits.h
@@ -63,6 +63,7 @@ class ASTNodeKind {
   static ASTNodeKind getFromNode(const Decl &D);
   static ASTNodeKind getFromNode(const Stmt &S);
   static ASTNodeKind getFromNode(const Type &T);
+  static ASTNodeKind getFromNode(const TypeLoc &T);
   static ASTNodeKind getFromNode(const OMPClause &C);
   static ASTNodeKind getFromNode(const Attr &A);
   /// \}
@@ -133,6 +134,8 @@ class ASTNodeKind {
 NKI_TemplateName,
 NKI_NestedNameSpecifierLoc,
 NKI_QualType,
+#define TYPELOC(CLASS, PARENT) NKI_##CLASS##TypeLoc,
+#include "clang/AST/TypeLocNodes.def"
 NKI_TypeLoc,
 NKI_LastKindWithoutPointerIdentity = NKI_TypeLoc,
 NKI_CXXBaseSpecifier,
@@ -198,6 +201,8 @@ KIND_TO_KIND_ID(TemplateName)
 KIND_TO_KIND_ID(NestedNameSpecifier)
 KIND_TO_KIND_ID(NestedNameSpecifierLoc)
 KIND_TO_KIND_ID(QualType)
+#define TYPELOC(CLASS, PARENT) KIND_TO_KIND_ID(CLASS##TypeLoc)
+#include "clang/AST/TypeLocNodes.def"
 KIND_TO_KIND_ID(TypeLoc)
 KIND_TO_KIND_ID(Decl)
 KIND_TO_KIND_ID(Stmt)
@@ -304,7 +309,7 @@ class DynTypedNode {
   return getUnchecked().getAsOpaquePtr() <
  Other.getUnchecked().getAsOpaquePtr();
 
-if (ASTNodeKind::getFromNodeKind().isSame(NodeKind)) {
+if (ASTNodeKind::getFromNodeKind().isBaseOf(NodeKind)) {
   auto TLA = getUnchecked();
   auto TLB = Other.getUnchecked();
   return std::make_pair(TLA.getType().getAsOpaquePtr(),
@@ -336,7 +341,7 @@ class DynTypedNode {
 if (ASTNodeKind::getFromNodeKind().isSame(NodeKind))
   return getUnchecked() == Other.getUnchecked();
 
-if (ASTNodeKind::getFromNodeKind().isSame(NodeKind))
+if (ASTNodeKind::getFromNodeKind().isBaseOf(NodeKind))
   return getUnchecked() == Other.getUnchecked();
 
 if 
(ASTNodeKind::getFromNodeKind().isSame(NodeKind))
@@ -365,7 +370,7 @@ class DynTypedNode {
 }
 static unsigned getHashValue(const DynTypedNode &Val) {
   // FIXME: Add hashing support for the remaining types.
-  if (ASTNodeKind::getFromNodeKind().isSame(Val.NodeKind)) {
+  if (ASTNodeKind::getFromNodeKind().isBaseOf(Val.NodeKind)) {
 auto TL = Val.getUnchecked();
 return llvm::hash_combine(TL.getType().getAsOpaquePtr(),
   TL.getOpaqueData());
@@ -455,6 +460,29 @@ class DynTypedNode {
 }
   };
 
+  /// Converter that stores nodes by value. It must be possible to dynamically
+  /// cast the stored node within a type hierarchy without breaking (especially
+  /// through slicing).
+  template >
+  struct DynCastValueConverter {
+static const T *get(ASTNodeKind NodeKind, const void *Storage) {
+  if (ASTNodeKind::getFromNodeKind().isBaseOf(NodeKind))
+return &getUnchecked(NodeKind, Storage);
+  return nullptr;
+}
+static const T &getUnchecked(ASTNodeKind NodeKind, const void *Storage) {
+  assert(ASTNodeKind::getFromNodeKind().isBaseOf(NodeKind));
+  return *static_cast(reinterpret_cast(Storage));
+}
+static DynTypedNode create(const T &Node) {
+  DynTypedNode Result;
+  Result.NodeKind = ASTNodeKind::getFromNode(Node);
+  new (&Result.Storage) T(Node);
+  return Result;
+}
+  };
+
   ASTNodeKind NodeKind;
 
   /// Stores the data of the node.
@@ -525,9 +553,10 @@ template <>
 struct DynTypedNode::BaseConverter : public ValueConverter {};
 
-template <>
+template 
 struct DynTypedNode::BaseConverter<
-TypeLoc, void> : public ValueConverter {};
+T, std::enable_if_t::value>>
+: public DynCastValueConverter {};
 
 template <>
 struct DynTypedNode::BaseConverter

diff  --git a/clang/lib/AST/ASTTypeTraits.cpp b/clang/lib/AST/ASTTypeTraits.cpp
index 6f9323ff1f25b..88f86cbb367ac 100644
--- a/clang/lib/AST/ASTTypeTraits.cpp
+++ b/clang/lib/AST/ASTTypeTraits.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OpenM

[PATCH] D110586: Update `DynTypedNode` to support the conversion of `TypeLoc`s.

2021-10-04 Thread Yitzhak Mandelbaum 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 rG56e72a40c198: Update `DynTypedNode` to support the 
conversion of `TypeLoc`s. (authored by jcking1034, committed by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110586

Files:
  clang/include/clang/AST/ASTTypeTraits.h
  clang/lib/AST/ASTTypeTraits.cpp
  clang/unittests/AST/ASTTypeTraitsTest.cpp

Index: clang/unittests/AST/ASTTypeTraitsTest.cpp
===
--- clang/unittests/AST/ASTTypeTraitsTest.cpp
+++ clang/unittests/AST/ASTTypeTraitsTest.cpp
@@ -199,5 +199,41 @@
   EXPECT_FALSE(Node < Node);
 }
 
+TEST(DynTypedNode, TypeLoc) {
+  std::string code = R"cc(void example() { int abc; })cc";
+  auto AST = clang::tooling::buildASTFromCode(code);
+  auto matches =
+  match(traverse(TK_AsIs,
+ varDecl(hasName("abc"), hasTypeLoc(typeLoc().bind("tl",
+AST->getASTContext());
+  EXPECT_EQ(matches.size(), 1u);
+
+  const auto &tl = *matches[0].getNodeAs("tl");
+  DynTypedNode Node = DynTypedNode::create(tl);
+  EXPECT_TRUE(Node == Node);
+  EXPECT_FALSE(Node < Node);
+}
+
+TEST(DynTypedNode, PointerTypeLoc) {
+  std::string code = R"cc(void example() { int *abc; })cc";
+  auto AST = clang::tooling::buildASTFromCode(code);
+  auto matches =
+  match(traverse(TK_AsIs, varDecl(hasName("abc"),
+  hasTypeLoc(typeLoc().bind("ptl",
+AST->getASTContext());
+  EXPECT_EQ(matches.size(), 1u);
+
+  const auto &tl = *matches[0].getNodeAs("ptl");
+  DynTypedNode TypeLocNode = DynTypedNode::create(tl);
+  EXPECT_TRUE(TypeLocNode == TypeLocNode);
+  EXPECT_FALSE(TypeLocNode < TypeLocNode);
+
+  const auto &ptl = *matches[0].getNodeAs("ptl");
+  EXPECT_EQ(&tl, &ptl);
+  DynTypedNode PointerTypeLocNode = DynTypedNode::create(ptl);
+  EXPECT_TRUE(PointerTypeLocNode == PointerTypeLocNode);
+  EXPECT_FALSE(PointerTypeLocNode < PointerTypeLocNode);
+}
+
 } // namespace
 }  // namespace clang
Index: clang/lib/AST/ASTTypeTraits.cpp
===
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OpenMPClause.h"
+#include "clang/AST/TypeLoc.h"
 
 using namespace clang;
 
@@ -28,6 +29,8 @@
 {NKI_None, "TemplateName"},
 {NKI_None, "NestedNameSpecifierLoc"},
 {NKI_None, "QualType"},
+#define TYPELOC(CLASS, PARENT) {NKI_##PARENT, #CLASS "TypeLoc"},
+#include "clang/AST/TypeLocNodes.def"
 {NKI_None, "TypeLoc"},
 {NKI_None, "CXXBaseSpecifier"},
 {NKI_None, "CXXCtorInitializer"},
@@ -127,6 +130,17 @@
   llvm_unreachable("invalid type kind");
  }
 
+ ASTNodeKind ASTNodeKind::getFromNode(const TypeLoc &T) {
+   switch (T.getTypeLocClass()) {
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
+#define TYPELOC(CLASS, PARENT) \
+  case TypeLoc::CLASS: \
+return ASTNodeKind(NKI_##CLASS##TypeLoc);
+#include "clang/AST/TypeLocNodes.def"
+   }
+   llvm_unreachable("invalid typeloc kind");
+ }
+
 ASTNodeKind ASTNodeKind::getFromNode(const OMPClause &C) {
   switch (C.getClauseKind()) {
 #define GEN_CLANG_CLAUSE_CLASS
Index: clang/include/clang/AST/ASTTypeTraits.h
===
--- clang/include/clang/AST/ASTTypeTraits.h
+++ clang/include/clang/AST/ASTTypeTraits.h
@@ -63,6 +63,7 @@
   static ASTNodeKind getFromNode(const Decl &D);
   static ASTNodeKind getFromNode(const Stmt &S);
   static ASTNodeKind getFromNode(const Type &T);
+  static ASTNodeKind getFromNode(const TypeLoc &T);
   static ASTNodeKind getFromNode(const OMPClause &C);
   static ASTNodeKind getFromNode(const Attr &A);
   /// \}
@@ -133,6 +134,8 @@
 NKI_TemplateName,
 NKI_NestedNameSpecifierLoc,
 NKI_QualType,
+#define TYPELOC(CLASS, PARENT) NKI_##CLASS##TypeLoc,
+#include "clang/AST/TypeLocNodes.def"
 NKI_TypeLoc,
 NKI_LastKindWithoutPointerIdentity = NKI_TypeLoc,
 NKI_CXXBaseSpecifier,
@@ -198,6 +201,8 @@
 KIND_TO_KIND_ID(NestedNameSpecifier)
 KIND_TO_KIND_ID(NestedNameSpecifierLoc)
 KIND_TO_KIND_ID(QualType)
+#define TYPELOC(CLASS, PARENT) KIND_TO_KIND_ID(CLASS##TypeLoc)
+#include "clang/AST/TypeLocNodes.def"
 KIND_TO_KIND_ID(TypeLoc)
 KIND_TO_KIND_ID(Decl)
 KIND_TO_KIND_ID(Stmt)
@@ -304,7 +309,7 @@
   return getUnchecked().getAsOpaquePtr() <
  Other.getUnchecked().getAsOpaquePtr();
 
-if (ASTNodeKind::getFromNodeKind().isSame(NodeKind)) {
+if (ASTNodeKind::getFromNodeKind().isBaseOf(NodeKind)) {
   auto TLA = getUnchecked();
   auto TLB = Other.getUnchecked();
   return std::make_

[PATCH] D110252: Added note about Whatstyle and Unformat

2021-10-04 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

IMHO is that I don't personally feel we need to endorse of someone else's that 
could be potentially incomplete,  These tools are interesting (per say) but I 
have no idea how accurate they are in terms of using all the options or how 
much they keep pace, for everything else there is "google search" to find 
these, (other search engines are available)

My feeling is that if you are using this tool then perhaps you are rushing to 
get to your format and you should be either :

a) picking a default style
b) taking a bit more time to read the manual and choose what you want.

Those tools suggest a quick fix, but come with extra effort to get them 
installed (extra python modules) and I personally wouldn't want clang-format to 
be somehow responsible if they generate an incorrect .clang-format file or 
messed up someones files.

I'll let others decide if they think it's of value but for me it's a no (sorry 
just my 2c worth).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110252

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


[clang] 8328966 - [PowerPC] Fix to guard fetch and cas 64-bit builtin versions

2021-10-04 Thread Kamau Bridgeman via cfe-commits

Author: Kamau Bridgeman
Date: 2021-10-04T14:45:36-05:00
New Revision: 83289665200b6b9212e0ff14e274b2c431a2e1fa

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

LOG: [PowerPC] Fix to guard fetch and cas 64-bit builtin versions

The builtins: `__compare_and_swaplp`, `__fetch_and_addlp`,
` __fetch_and_andlp`, `__fetch_and_orlp`, `__fetch_and_swaplp` are
64 bit only. This patch ensures the compiler produces an error in 32 bit mode.

Reviewed By: #powerpc, nemanjai

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

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins-ppc-xlcompat-error.c

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 207b28ec5972..a6d26ac65465 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3297,6 +3297,11 @@ static bool isPPC_64Builtin(unsigned BuiltinID) {
   case PPC::BI__builtin_ppc_addex:
   case PPC::BI__builtin_darn:
   case PPC::BI__builtin_darn_raw:
+  case PPC::BI__builtin_ppc_compare_and_swaplp:
+  case PPC::BI__builtin_ppc_fetch_and_addlp:
+  case PPC::BI__builtin_ppc_fetch_and_andlp:
+  case PPC::BI__builtin_ppc_fetch_and_orlp:
+  case PPC::BI__builtin_ppc_fetch_and_swaplp:
 return true;
   }
   return false;

diff  --git a/clang/test/CodeGen/builtins-ppc-xlcompat-error.c 
b/clang/test/CodeGen/builtins-ppc-xlcompat-error.c
index f1c577cf846f..9fc218b1de41 100644
--- a/clang/test/CodeGen/builtins-ppc-xlcompat-error.c
+++ b/clang/test/CodeGen/builtins-ppc-xlcompat-error.c
@@ -104,6 +104,25 @@ int test_darn() {
 int test_darn_raw() {
   return __darn_raw(); //expected-error {{this builtin is only available on 
64-bit targets}}
 }
+
+int test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
+  return __compare_and_swaplp(&a, &b, c); // expected-error {{this builtin is 
only available on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_addlp(long a, long b) {
+  __fetch_and_addlp(&a, b); // expected-error {{this builtin is only available 
on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_andlp(unsigned long a, unsigned long b) {
+  __fetch_and_andlp(&a, b); // expected-error {{this builtin is only available 
on 64-bit targets}}
+}
+void test_builtin_ppc_fetch_and_orlp(unsigned long a, unsigned long b) {
+  __fetch_and_orlp(&a, b); // expected-error {{this builtin is only available 
on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_swaplp(unsigned long a, unsigned long b) {
+  __fetch_and_swaplp(&a, b); // expected-error {{this builtin is only 
available on 64-bit targets}}
+}
 #endif
 
 unsigned long test_mfspr(void) {



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


[PATCH] D110824: [PowerPC] Fix to guard fetch and cas 64-bit builtin versions

2021-10-04 Thread Kamau Bridgeman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG83289665200b: [PowerPC] Fix to guard fetch and cas 64-bit 
builtin versions (authored by kamaub).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110824

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-error.c


Index: clang/test/CodeGen/builtins-ppc-xlcompat-error.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-error.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-error.c
@@ -104,6 +104,25 @@
 int test_darn_raw() {
   return __darn_raw(); //expected-error {{this builtin is only available on 
64-bit targets}}
 }
+
+int test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
+  return __compare_and_swaplp(&a, &b, c); // expected-error {{this builtin is 
only available on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_addlp(long a, long b) {
+  __fetch_and_addlp(&a, b); // expected-error {{this builtin is only available 
on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_andlp(unsigned long a, unsigned long b) {
+  __fetch_and_andlp(&a, b); // expected-error {{this builtin is only available 
on 64-bit targets}}
+}
+void test_builtin_ppc_fetch_and_orlp(unsigned long a, unsigned long b) {
+  __fetch_and_orlp(&a, b); // expected-error {{this builtin is only available 
on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_swaplp(unsigned long a, unsigned long b) {
+  __fetch_and_swaplp(&a, b); // expected-error {{this builtin is only 
available on 64-bit targets}}
+}
 #endif
 
 unsigned long test_mfspr(void) {
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3297,6 +3297,11 @@
   case PPC::BI__builtin_ppc_addex:
   case PPC::BI__builtin_darn:
   case PPC::BI__builtin_darn_raw:
+  case PPC::BI__builtin_ppc_compare_and_swaplp:
+  case PPC::BI__builtin_ppc_fetch_and_addlp:
+  case PPC::BI__builtin_ppc_fetch_and_andlp:
+  case PPC::BI__builtin_ppc_fetch_and_orlp:
+  case PPC::BI__builtin_ppc_fetch_and_swaplp:
 return true;
   }
   return false;


Index: clang/test/CodeGen/builtins-ppc-xlcompat-error.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-error.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-error.c
@@ -104,6 +104,25 @@
 int test_darn_raw() {
   return __darn_raw(); //expected-error {{this builtin is only available on 64-bit targets}}
 }
+
+int test_builtin_ppc_compare_and_swaplp(long a, long b, long c) {
+  return __compare_and_swaplp(&a, &b, c); // expected-error {{this builtin is only available on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_addlp(long a, long b) {
+  __fetch_and_addlp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_andlp(unsigned long a, unsigned long b) {
+  __fetch_and_andlp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
+}
+void test_builtin_ppc_fetch_and_orlp(unsigned long a, unsigned long b) {
+  __fetch_and_orlp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
+}
+
+void test_builtin_ppc_fetch_and_swaplp(unsigned long a, unsigned long b) {
+  __fetch_and_swaplp(&a, b); // expected-error {{this builtin is only available on 64-bit targets}}
+}
 #endif
 
 unsigned long test_mfspr(void) {
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3297,6 +3297,11 @@
   case PPC::BI__builtin_ppc_addex:
   case PPC::BI__builtin_darn:
   case PPC::BI__builtin_darn_raw:
+  case PPC::BI__builtin_ppc_compare_and_swaplp:
+  case PPC::BI__builtin_ppc_fetch_and_addlp:
+  case PPC::BI__builtin_ppc_fetch_and_andlp:
+  case PPC::BI__builtin_ppc_fetch_and_orlp:
+  case PPC::BI__builtin_ppc_fetch_and_swaplp:
 return true;
   }
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111078: [AIX] Enable int128 in 64 bit mode

2021-10-04 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: llvm/test/CodeGen/PowerPC/int128_ldst.ll:31
 ; CHECK-NEXT:mr 3, 5
 ; CHECK-NEXT:blr
 entry:

Confirming that this case matches GCC on AIX:
```
ld 4,8(3)
ld 3,0(3)
blr
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111078

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


[PATCH] D110889: [clang][Fuchsia] Add -DSCUDO_DISABLE_TBI to test flags

2021-10-04 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan abandoned this revision.
leonardchan added a comment.
Herald added a subscriber: abrachet.

In D110889#3035597 , @phosek wrote:

> Is this needed even with D110888 ?

Nope, at least after the updated patch this isn't needed anymore. Abandoning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110889

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


[clang] 0f0e31c - Update inline builtin handling to honor gnu inline attribute

2021-10-04 Thread via cfe-commits

Author: serge-sans-paille
Date: 2021-10-04T22:26:25+02:00
New Revision: 0f0e31cf511def3e92244e615b2646c1fd0df0cd

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

LOG: Update inline builtin handling to honor gnu inline attribute

Per the GCC info page:

If the function is declared 'extern', then this definition of the
function is used only for inlining.  In no case is the function
compiled as a standalone function, not even if you take its address
explicitly.  Such an address becomes an external reference, as if
you had only declared the function, and had not defined it.

Respect that behavior for inline builtins: keep the original definition, and
generate a copy of the declaration suffixed by '.inline' that's only referenced
in direct call.

This fixes holes in c3717b6858d32d64514a187ede1a77be8ba4e542.

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

Added: 
clang/test/CodeGen/memcmp-inline-builtin-to-asm.c
clang/test/CodeGen/memcpy-inline-builtin-no-extern.c

Modified: 
clang/lib/AST/Decl.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/test/CodeGen/memcpy-inline-builtin.c
clang/test/CodeGen/memcpy-nobuiltin.c
clang/test/CodeGen/memcpy-nobuiltin.inc
clang/test/CodeGen/pr9614.c

Removed: 




diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 60ca8633224b..6788f2132fbc 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3177,7 +3177,8 @@ bool FunctionDecl::isInlineBuiltinDeclaration() const {
 
   const FunctionDecl *Definition;
   return hasBody(Definition) && Definition->isInlineSpecified() &&
- Definition->hasAttr();
+ Definition->hasAttr() &&
+ Definition->hasAttr();
 }
 
 bool FunctionDecl::isDestroyingOperatorDelete() const {

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index a62a4d60830d..6dd511acf105 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -4891,12 +4891,28 @@ static CGCallee EmitDirectCallee(CodeGenFunction &CGF, 
GlobalDecl GD) {
   const FunctionDecl *FD = cast(GD.getDecl());
 
   if (auto builtinID = FD->getBuiltinID()) {
-// Replaceable builtin provide their own implementation of a builtin. 
Unless
-// we are in the builtin implementation itself, don't call the actual
-// builtin. If we are in the builtin implementation, avoid trivial infinite
+std::string FDInlineName = (FD->getName() + ".inline").str();
+// When directing calling an inline builtin, call it through it's mangled
+// name to make it clear it's not the actual builtin.
+if (FD->isInlineBuiltinDeclaration() &&
+CGF.CurFn->getName() != FDInlineName) {
+  llvm::Constant *CalleePtr = EmitFunctionDeclPointer(CGF.CGM, GD);
+  llvm::Function *Fn = llvm::cast(CalleePtr);
+  llvm::Module *M = Fn->getParent();
+  llvm::Function *Clone = M->getFunction(FDInlineName);
+  if (!Clone) {
+Clone = llvm::Function::Create(Fn->getFunctionType(),
+   llvm::GlobalValue::InternalLinkage,
+   Fn->getAddressSpace(), FDInlineName, M);
+Clone->addFnAttr(llvm::Attribute::AlwaysInline);
+  }
+  return CGCallee::forDirect(Clone, GD);
+}
+
+// Replaceable builtins provide their own implementation of a builtin. If 
we
+// are in an inline builtin implementation, avoid trivial infinite
 // recursion.
-if (!FD->isInlineBuiltinDeclaration() ||
-CGF.CurFn->getName() == FD->getName())
+else
   return CGCallee::forBuiltin(builtinID, FD);
   }
 
@@ -4905,6 +4921,7 @@ static CGCallee EmitDirectCallee(CodeGenFunction &CGF, 
GlobalDecl GD) {
   FD->hasAttr())
 CalleePtr = CGF.CGM.getCUDARuntime().getKernelStub(
 cast(CalleePtr->stripPointerCasts()));
+
   return CGCallee::forDirect(CalleePtr, GD);
 }
 

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index da9a5303daad..13bc366b6c2f 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -45,6 +45,7 @@
 #include "llvm/Support/CRC.h"
 #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
 #include "llvm/Transforms/Utils/PromoteMemToReg.h"
+
 using namespace clang;
 using namespace CodeGen;
 
@@ -1294,10 +1295,22 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, 
llvm::Function *Fn,
   FunctionArgList Args;
   QualType ResTy = BuildFunctionArgList(GD, Args);
 
-  // Give a 
diff erent name to inline builtin to avoid conflict with actual
-  // builtins.
-  if (FD->isInlineBuiltinDeclaration() && Fn)
-Fn->setName(Fn->getName() + ".inline");
+  // When generating code for a builtin with an i

[PATCH] D111009: Update inline builtin handling to honor gnu inline attribute

2021-10-04 Thread serge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f0e31cf511d: Update inline builtin handling to honor gnu 
inline attribute (authored by serge-sans-paille).

Changed prior to commit:
  https://reviews.llvm.org/D111009?vs=376812&id=377023#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111009

Files:
  clang/lib/AST/Decl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/memcmp-inline-builtin-to-asm.c
  clang/test/CodeGen/memcpy-inline-builtin-no-extern.c
  clang/test/CodeGen/memcpy-inline-builtin.c
  clang/test/CodeGen/memcpy-nobuiltin.c
  clang/test/CodeGen/memcpy-nobuiltin.inc
  clang/test/CodeGen/pr9614.c

Index: clang/test/CodeGen/pr9614.c
===
--- clang/test/CodeGen/pr9614.c
+++ clang/test/CodeGen/pr9614.c
@@ -32,14 +32,14 @@
 
 // CHECK-LABEL: define{{.*}} void @f()
 // CHECK: call void @foo()
-// CHECK: call i32 @abs(i32 %0)
+// CHECK: call i32 @abs(i32 0)
 // CHECK: call i8* @strrchr(
 // CHECK: call void @llvm.prefetch.p0i8(
 // CHECK: call i8* @memchr(
 // CHECK: ret void
 
 // CHECK: declare void @foo()
+// CHECK: declare i32 @abs(i32
 // CHECK: declare i8* @strrchr(i8*, i32)
 // CHECK: declare i8* @memchr(
-// CHECK: declare i32 @abs(i32
 // CHECK: declare void @llvm.prefetch.p0i8(
Index: clang/test/CodeGen/memcpy-nobuiltin.inc
===
--- clang/test/CodeGen/memcpy-nobuiltin.inc
+++ clang/test/CodeGen/memcpy-nobuiltin.inc
@@ -2,7 +2,7 @@
 extern void *memcpy(void *dest, void const *from, size_t n);
 
 #ifdef WITH_DECL
-inline __attribute__((always_inline)) void *memcpy(void *dest, void const *from, size_t n) {
+inline __attribute__((always_inline)) __attribute__((gnu_inline)) void *memcpy(void *dest, void const *from, size_t n) {
   char const *ifrom = from;
   char *idest = dest;
   while (n--)
@@ -11,7 +11,7 @@
 }
 #endif
 #ifdef WITH_SELF_REFERENCE_DECL
-inline __attribute__((always_inline)) void *memcpy(void *dest, void const *from, size_t n) {
+inline __attribute__((always_inline)) __attribute__((gnu_inline)) void *memcpy(void *dest, void const *from, size_t n) {
   if (n != 0)
 memcpy(dest, from, n);
   return dest;
Index: clang/test/CodeGen/memcpy-nobuiltin.c
===
--- clang/test/CodeGen/memcpy-nobuiltin.c
+++ clang/test/CodeGen/memcpy-nobuiltin.c
@@ -1,11 +1,11 @@
 // RUN: %clang_cc1 -verify -S -emit-llvm -o- %s -isystem %S -DWITH_DECL | FileCheck --check-prefix=CHECK-WITH-DECL %s
 // RUN: %clang_cc1 -verify -S -emit-llvm -o- %s -isystem %S -UWITH_DECL | FileCheck --check-prefix=CHECK-NO-DECL %s
-// RUN: %clang_cc1 -verify -S -emit-llvm -o- %s -isystem %S -DWITH_SELF_REFERENCE_DECL | FileCheck --check-prefix=CHECK-SELF-REF-DECL %s
+// RUN: %clang_cc1 -verify -S -emit-llvm -o- %s -isystem %S -disable-llvm-passes -DWITH_SELF_REFERENCE_DECL | FileCheck --check-prefix=CHECK-SELF-REF-DECL %s
 //
 // CHECK-WITH-DECL-NOT: @llvm.memcpy
 // CHECK-NO-DECL: @llvm.memcpy
 // CHECK-SELF-REF-DECL-LABEL: define {{.*}}i8* @memcpy.inline
-// CHECK-SELF-REF-DECL:   @memcpy(
+// CHECK-SELF-REF-DECL:   @llvm.memcpy.{{.*}}(
 //
 #include 
 void test(void *dest, void const *from, size_t n) {
Index: clang/test/CodeGen/memcpy-inline-builtin.c
===
--- clang/test/CodeGen/memcpy-inline-builtin.c
+++ clang/test/CodeGen/memcpy-inline-builtin.c
@@ -32,13 +32,39 @@
 // CHECK-NEXT:store i8* [[TMP0]], i8** [[A_ADDR_I]], align 8
 // CHECK-NEXT:store i8* [[TMP1]], i8** [[B_ADDR_I]], align 8
 // CHECK-NEXT:store i64 [[TMP2]], i64* [[C_ADDR_I]], align 8
-// CHECK-NEXT:call void asm sideeffect "# memcpy.inline marker", "~{dirflag},~{fpsr},~{flags}"() #[[ATTR2:[0-9]+]], !srcloc !2
+// CHECK-NEXT:call void asm sideeffect "# memcpy.inline marker", "~{dirflag},~{fpsr},~{flags}"() #[[ATTR4:[0-9]+]], !srcloc !2
 // CHECK-NEXT:[[TMP3:%.*]] = load i8*, i8** [[A_ADDR_I]], align 8
 // CHECK-NEXT:[[TMP4:%.*]] = load i8*, i8** [[B_ADDR_I]], align 8
 // CHECK-NEXT:[[TMP5:%.*]] = load i64, i64* [[C_ADDR_I]], align 8
-// CHECK-NEXT:call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 [[TMP3]], i8* align 1 [[TMP4]], i64 [[TMP5]], i1 false) #[[ATTR2]]
+// CHECK-NEXT:call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 [[TMP3]], i8* align 1 [[TMP4]], i64 [[TMP5]], i1 false) #[[ATTR4]]
+// CHECK-NEXT:ret i8* [[TMP3]]
+//
+void *foo(void *a, const void *b, size_t c) {
+  return memcpy(a, b, c);
+}
+
+// CHECK-LABEL: @bar(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[C_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[CPY:%.*]] = alloca i8* (i8*, i8*, i64)*, align

[PATCH] D110484: [clang-repl] Allow loading of plugins in clang-repl.

2021-10-04 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

LGTM modulo existing comments.


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

https://reviews.llvm.org/D110484

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


[PATCH] D110484: [clang-repl] Allow loading of plugins in clang-repl.

2021-10-04 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 377026.
v.g.vassilev marked 2 inline comments as done.
v.g.vassilev added a comment.

Address comments.


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

https://reviews.llvm.org/D110484

Files:
  clang/include/clang/Frontend/CompilerInstance.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/test/Interpreter/plugins.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/tools/clang-repl/ClangRepl.cpp

Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -80,6 +80,9 @@
   llvm::install_fatal_error_handler(LLVMErrorHandler,
 static_cast(&CI->getDiagnostics()));
 
+  // Load any requested plugins.
+  CI->LoadRequestedPlugins();
+
   auto Interp = ExitOnErr(clang::Interpreter::create(std::move(CI)));
   for (const std::string &input : OptInputs) {
 if (auto Err = Interp->ParseAndExecute(input))
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -16,3 +16,8 @@
   clangInterpreter
   clangTooling
   )
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  export_executable_symbols_for_plugins(clang-repl)
+endif()
Index: clang/test/Interpreter/plugins.cpp
===
--- /dev/null
+++ clang/test/Interpreter/plugins.cpp
@@ -0,0 +1,14 @@
+// RUN: clang-repl -Xcc -Xclang -Xcc -load -Xcc -Xclang \
+// RUN:-Xcc %llvmshlibdir/PrintFunctionNames%pluginext -Xcc -Xclang\
+// RUN:-Xcc -add-plugin -Xcc -Xclang -Xcc print-fns 2>&1 | FileCheck %s
+// REQUIRES: host-supports-jit, plugins, examples
+
+int i = 10;
+extern "C" int printf(const char*,...);
+auto r1 = printf("i = %d\n", i);
+quit
+
+
+// CHECK: top-level-decl: "i"
+// CHECK-NEXT: top-level-decl: "r1"
+// CHECK-NEXT: i = 10
Index: clang/lib/Interpreter/IncrementalParser.cpp
===
--- clang/lib/Interpreter/IncrementalParser.cpp
+++ clang/lib/Interpreter/IncrementalParser.cpp
@@ -65,6 +65,8 @@
   case frontend::ParseSyntaxOnly:
 Act = CreateFrontendAction(CI);
 break;
+  case frontend::PluginAction:
+LLVM_FALLTHROUGH;
   case frontend::EmitAssembly:
 LLVM_FALLTHROUGH;
   case frontend::EmitObj:
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -203,24 +203,7 @@
 return true;
   }
 
-  // Load any requested plugins.
-  for (const std::string &Path : Clang->getFrontendOpts().Plugins) {
-std::string Error;
-if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))
-  Clang->getDiagnostics().Report(diag::err_fe_unable_to_load_plugin)
-<< Path << Error;
-  }
-
-  // Check if any of the loaded plugins replaces the main AST action
-  for (const FrontendPluginRegistry::entry &Plugin :
-   FrontendPluginRegistry::entries()) {
-std::unique_ptr P(Plugin.instantiate());
-if (P->getActionType() == PluginASTAction::ReplaceAction) {
-  Clang->getFrontendOpts().ProgramAction = clang::frontend::PluginAction;
-  Clang->getFrontendOpts().ActionName = Plugin.getName().str();
-  break;
-}
-  }
+  Clang->LoadRequestedPlugins();
 
   // Honor -mllvm.
   //
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -23,6 +23,7 @@
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Frontend/FrontendPluginRegistry.h"
 #include "clang/Frontend/LogDiagnosticPrinter.h"
 #include "clang/Frontend/SerializedDiagnosticPrinter.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
@@ -1029,6 +1030,27 @@
   return !getDiagnostics().getClient()->getNumErrors();
 }
 
+void CompilerInstance::LoadRequestedPlugins() {
+  // Load any requested plugins.
+  for (const std::string &Path : getFrontendOpts().Plugins) {
+std::string Error;
+if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))
+  getDiagnostics().Report(diag::err_fe_unable_to_load_plugin)
+  << Path << Error;
+  }
+
+  // Check if any of the loaded plugins replaces the main AST action
+  for (const FrontendPluginRegistry::entry &Plugin :
+   FrontendPluginRegistry::entries()) {
+std::unique_ptr

[PATCH] D110665: [clang] Don't use the AST to display backend diagnostics

2021-10-04 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Sounds OK to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110665

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


[PATCH] D109625: [compiler-rt] Ensure required deps for tests targets are actually built

2021-10-04 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

Hmm. Just found out about this, but for future reference, I think this will 
only work for `ninja check-runtimes` and `ninja check-runtimes-{target}`, but 
not necessarily `ninja -C runtimes/runtimes-{target} 
check-runtimes/check-compilter-rt`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109625

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


[clang] 8480063 - [clang][Fuchsia] Re-enable compiler-rt tests in runtimes build

2021-10-04 Thread Leonard Chan via cfe-commits

Author: Leonard Chan
Date: 2021-10-04T14:11:49-07:00
New Revision: 8480063f25b8527d935722769d54d47f0c0d5689

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

LOG: [clang][Fuchsia] Re-enable compiler-rt tests in runtimes build

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

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 1fbbaf74b0ec8..5efa3028a0c65 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -120,6 +120,7 @@ foreach(target 
aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unkn
 set(RUNTIMES_${target}_CMAKE_MODULE_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
 set(RUNTIMES_${target}_CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING 
"")
 set(RUNTIMES_${target}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "")
+set(RUNTIMES_${target}_COMPILER_RT_CAN_EXECUTE_TESTS ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")
 set(RUNTIMES_${target}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")



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


[PATCH] D110778: [clang][Fuchsia] Re-enable compiler-rt tests in runtimes build

2021-10-04 Thread Leonard Chan 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 rG8480063f25b8: [clang][Fuchsia] Re-enable compiler-rt tests 
in runtimes build (authored by leonardchan).
Herald added a subscriber: abrachet.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110778

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -120,6 +120,7 @@
 set(RUNTIMES_${target}_CMAKE_MODULE_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
 set(RUNTIMES_${target}_CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING 
"")
 set(RUNTIMES_${target}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "")
+set(RUNTIMES_${target}_COMPILER_RT_CAN_EXECUTE_TESTS ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")
 set(RUNTIMES_${target}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -120,6 +120,7 @@
 set(RUNTIMES_${target}_CMAKE_MODULE_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "")
 set(RUNTIMES_${target}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "")
+set(RUNTIMES_${target}_COMPILER_RT_CAN_EXECUTE_TESTS ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")
 set(RUNTIMES_${target}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110216: [clang] retain type sugar in auto / template argument deduction

2021-10-04 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D110216#3040748 , @craig.topper 
wrote:

> Looks like this fixes PR51282.

I guess it does fix it, but the underlying implementation of alignment is very 
fragile. The alignment is stored in `AttributedType` nodes, which are always 
sugar, so they are not considered part of the type in a structural sense...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110216

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


[PATCH] D108482: [Clang] Fix instantiation of OpaqueValueExprs (Bug #45964)

2021-10-04 Thread Jason Rice via Phabricator via cfe-commits
ricejasonf updated this revision to Diff 377033.
ricejasonf added a comment.

I rebased onto `main` and made one small style fix. I don't think the rebase 
changes anything.

I do not understand why random things are failing in the CI. Even on my own 
build machine with a fresh build directory CMake fails with errors about 
unregistered files in ExecutionEngine/Orc.

All this stuff is completely unrelated to my very minor change. Is there 
something about the process that I am missing?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108482

Files:
  clang/lib/Sema/TreeTransform.h
  clang/test/CodeGenCXX/pr45964-decomp-transform.cpp


Index: clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++1z -triple x86_64-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
+
+int a[1];
+// CHECK: @a = global [1 x i32] zeroinitializer
+template 
+void test_transform() {
+  auto [b] = a;
+}
+void (*d)(){test_transform<0>};
+// CHECK-LABEL: define {{.*}} @_Z14test_transformILi0EEvv
+// CHECK:   [[ENTRY:.*]]:
+// CHECK-NEXT:  [[ARR:%.*]] = alloca [1 x i32]
+// CHECK-NEXT:  [[BEGIN:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* 
[[ARR]], i64 0, i64 0
+// CHECK-NEXT:  br label %[[BODY:.*]]
+// CHECK-EMPTY:
+// CHECK-NEXT:  [[BODY]]:
+// CHECK-NEXT:  [[CUR:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[NEXT:%.*]], 
%[[BODY]] ]
+// CHECK-NEXT:  [[DEST:%.*]] = getelementptr inbounds i32, i32* [[BEGIN]], i64 
[[CUR]]
+// CHECK-NEXT:  [[SRC:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* @a, 
i64 0, i64 [[CUR]]
+// CHECK-NEXT:  [[X:%.*]] = load i32, i32* [[SRC]]
+// CHECK-NEXT:  store i32 [[X]], i32* [[DEST]]
+// CHECK-NEXT:  [[NEXT]] = add nuw i64 [[CUR]], 1
+// CHECK-NEXT:  [[EQ:%.*]] = icmp eq i64 [[NEXT]], 1
+// CHECK-NEXT:  br i1 [[EQ]], label %[[FIN:.*]], label %[[BODY]]
+// CHECK-EMPTY:
+// CHECK-NEXT:  [[FIN]]:
+// CHECK-NEXT:  ret void
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3840,8 +3840,10 @@
   if (auto *FE = dyn_cast(Init))
 Init = FE->getSubExpr();
 
-  if (auto *AIL = dyn_cast(Init))
-Init = AIL->getCommonExpr();
+  if (auto *AIL = dyn_cast(Init)) {
+auto *OVE = cast(AIL->getCommonExpr());
+Init = OVE->getSourceExpr();
+  }
 
   if (MaterializeTemporaryExpr *MTE = dyn_cast(Init))
 Init = MTE->getSubExpr();


Index: clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++1z -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+int a[1];
+// CHECK: @a = global [1 x i32] zeroinitializer
+template 
+void test_transform() {
+  auto [b] = a;
+}
+void (*d)(){test_transform<0>};
+// CHECK-LABEL: define {{.*}} @_Z14test_transformILi0EEvv
+// CHECK:   [[ENTRY:.*]]:
+// CHECK-NEXT:  [[ARR:%.*]] = alloca [1 x i32]
+// CHECK-NEXT:  [[BEGIN:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* [[ARR]], i64 0, i64 0
+// CHECK-NEXT:  br label %[[BODY:.*]]
+// CHECK-EMPTY:
+// CHECK-NEXT:  [[BODY]]:
+// CHECK-NEXT:  [[CUR:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[NEXT:%.*]], %[[BODY]] ]
+// CHECK-NEXT:  [[DEST:%.*]] = getelementptr inbounds i32, i32* [[BEGIN]], i64 [[CUR]]
+// CHECK-NEXT:  [[SRC:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* @a, i64 0, i64 [[CUR]]
+// CHECK-NEXT:  [[X:%.*]] = load i32, i32* [[SRC]]
+// CHECK-NEXT:  store i32 [[X]], i32* [[DEST]]
+// CHECK-NEXT:  [[NEXT]] = add nuw i64 [[CUR]], 1
+// CHECK-NEXT:  [[EQ:%.*]] = icmp eq i64 [[NEXT]], 1
+// CHECK-NEXT:  br i1 [[EQ]], label %[[FIN:.*]], label %[[BODY]]
+// CHECK-EMPTY:
+// CHECK-NEXT:  [[FIN]]:
+// CHECK-NEXT:  ret void
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3840,8 +3840,10 @@
   if (auto *FE = dyn_cast(Init))
 Init = FE->getSubExpr();
 
-  if (auto *AIL = dyn_cast(Init))
-Init = AIL->getCommonExpr();
+  if (auto *AIL = dyn_cast(Init)) {
+auto *OVE = cast(AIL->getCommonExpr());
+Init = OVE->getSourceExpr();
+  }
 
   if (MaterializeTemporaryExpr *MTE = dyn_cast(Init))
 Init = MTE->getSubExpr();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2568286 - [clang] Don't use the AST to display backend diagnostics

2021-10-04 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2021-10-04T14:14:32-07:00
New Revision: 2568286892310877f24313c8e1626e415f9ae406

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

LOG: [clang] Don't use the AST to display backend diagnostics

We keep a map from function name to source location so we don't have to
do it via looking up a source location from the AST. However, since
function names can be long, we actually use a hash of the function name
as the key.

Additionally, we can't rely on Clang's printing of function names via
the AST, so we just demangle the name instead.

This is necessary to implement
https://lists.llvm.org/pipermail/cfe-dev/2021-September/068930.html.

Reviewed By: dblaikie

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/lib/CodeGen/CodeGenAction.cpp
clang/test/Frontend/backend-diagnostic.c
clang/test/Misc/backend-stack-frame-diagnostics-fallback.cpp
clang/test/Misc/backend-stack-frame-diagnostics.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 35e0d2649f5ee..eacb7e4de0ead 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -26,7 +26,7 @@ def err_fe_linking_module : Error<"cannot link module '%0': 
%1">, DefaultFatal;
 def warn_fe_linking_module : Warning<"linking module '%0': %1">, 
InGroup;
 def note_fe_linking_module : Note<"linking module '%0': %1">;
 
-def warn_fe_frame_larger_than : Warning<"stack frame size (%0) exceeds limit 
(%1) in %q2">,
+def warn_fe_frame_larger_than : Warning<"stack frame size (%0) exceeds limit 
(%1) in '%2'">,
 BackendInfo, InGroup;
 def warn_fe_backend_frame_larger_than: Warning<"%0">,
 BackendInfo, InGroup;

diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 6e1d7f320673c..9fb5f29c94ab5 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -25,6 +25,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/Hashing.h"
 #include "llvm/Bitcode/BitcodeReader.h"
 #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
 #include "llvm/Demangle/Demangle.h"
@@ -126,6 +127,17 @@ namespace clang {
 
 SmallVector LinkModules;
 
+// A map from mangled names to their function's source location, used for
+// backend diagnostics as the Clang AST may be unavailable. We actually use
+// the mangled name's hash as the key because mangled names can be very
+// long and take up lots of space. Using a hash can cause name collision,
+// but that is rare and the consequences are pointing to a wrong source
+// location which is not severe. This is a vector instead of an actual map
+// because we optimize for time building this map rather than time
+// retrieving an entry, as backend diagnostics are uncommon.
+std::vector>
+ManglingFullSourceLocs;
+
 // This is here so that the diagnostic printer knows the module a 
diagnostic
 // refers to.
 llvm::Module *CurLinkModule = nullptr;
@@ -330,6 +342,15 @@ namespace clang {
   if (LinkInModules())
 return;
 
+  for (auto &F : getModule()->functions()) {
+if (const Decl *FD = Gen->GetDeclForMangledName(F.getName())) {
+  auto Loc = FD->getASTContext().getFullLoc(FD->getLocation());
+  // TODO: use a fast content hash when available.
+  auto NameHash = llvm::hash_value(F.getName());
+  ManglingFullSourceLocs.push_back(std::make_pair(NameHash, Loc));
+}
+  }
+
   EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef());
 
   EmitBackendOutput(Diags, HeaderSearchOpts, CodeGenOpts, TargetOpts,
@@ -376,6 +397,8 @@ namespace clang {
 bool &BadDebugInfo, StringRef &Filename,
 unsigned &Line, unsigned &Column) const;
 
+Optional getFunctionSourceLocation(const Function &F) const;
+
 void DiagnosticHandlerImpl(const llvm::DiagnosticInfo &DI);
 /// Specialized handler for InlineAsm diagnostic.
 /// \return True if the diagnostic has been successfully reported, false
@@ -569,17 +592,16 @@ BackendConsumer::StackSizeDiagHandler(const 
llvm::DiagnosticInfoStackSize &D) {
 // We do not know how to format other severities.
 return false;
 
-  if (const Decl *ND = Gen->GetDeclForMangledName(D.getFunction().getName())) {
-// FIXME: Shouldn't need to truncate to uint32_t
-Diags.Report(ND->getASTContext().getFullLoc(ND->getLocation()),
- 

[PATCH] D110665: [clang] Don't use the AST to display backend diagnostics

2021-10-04 Thread Arthur Eubanks via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG256828689231: [clang] Don't use the AST to display 
backend diagnostics (authored by aeubanks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110665

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/Frontend/backend-diagnostic.c
  clang/test/Misc/backend-stack-frame-diagnostics-fallback.cpp
  clang/test/Misc/backend-stack-frame-diagnostics.cpp

Index: clang/test/Misc/backend-stack-frame-diagnostics.cpp
===
--- clang/test/Misc/backend-stack-frame-diagnostics.cpp
+++ clang/test/Misc/backend-stack-frame-diagnostics.cpp
@@ -26,7 +26,7 @@
 
 void frameSizeWarning();
 
-void frameSizeWarning() { // expected-warning-re {{stack frame size ({{[0-9]+}}) exceeds limit ({{[0-9]+}}) in function 'frameSizeWarning'}}
+void frameSizeWarning() { // expected-warning-re {{stack frame size ({{[0-9]+}}) exceeds limit ({{[0-9]+}}) in 'frameSizeWarning()'}}
   char buffer[80];
   doIt(buffer);
 }
@@ -45,7 +45,7 @@
 
 void frameSizeLocalClassWarning() {
   struct S {
-S() { // expected-warning-re {{stack frame size ({{[0-9]+}}) exceeds limit ({{[0-9]+}}) in function 'frameSizeLocalClassWarning()::S::S'}}
+S() { // expected-warning-re {{stack frame size ({{[0-9]+}}) exceeds limit ({{[0-9]+}}) in 'frameSizeLocalClassWarning()::S::S()'}}
   char buffer[80];
   doIt(buffer);
 }
@@ -55,7 +55,7 @@
 
 void frameSizeLambdaWarning() {
   auto fn =
-  []() { // expected-warning-re {{stack frame size ({{[0-9]+}}) exceeds limit ({{[0-9]+}}) in lambda expression}}
+  []() { // expected-warning-re {{stack frame size ({{[0-9]+}}) exceeds limit ({{[0-9]+}}) in 'frameSizeLambdaWarning()::$_0::operator()() const'}}
 char buffer[80];
 doIt(buffer);
   };
@@ -64,7 +64,7 @@
 
 void frameSizeBlocksWarning() {
   auto fn =
-  ^() { // expected-warning-re {{stack frame size ({{[0-9]+}}) exceeds limit ({{[0-9]+}}) in block literal}}
+  ^() { // expected-warning-re {{stack frame size ({{[0-9]+}}) exceeds limit ({{[0-9]+}}) in 'invocation function for block in frameSizeBlocksWarning()'}}
 char buffer[80];
 doIt(buffer);
   };
Index: clang/test/Misc/backend-stack-frame-diagnostics-fallback.cpp
===
--- clang/test/Misc/backend-stack-frame-diagnostics-fallback.cpp
+++ clang/test/Misc/backend-stack-frame-diagnostics-fallback.cpp
@@ -12,7 +12,7 @@
 virtual void f();
   };
 
-  // CHECK: warning: stack frame size ([[#]]) exceeds limit ([[#]]) in function 'frameSizeThunkWarning::B::f'
+  // CHECK: warning: stack frame size ([[#]]) exceeds limit ([[#]]) in 'frameSizeThunkWarning::B::f()'
   // CHECK: warning: stack frame size ([[#]]) exceeds limit ([[#]]) in function '_ZTv0_n12_N21frameSizeThunkWarning1B1fEv'
   void B::f() {
 volatile int x = 0; // Ensure there is stack usage.
Index: clang/test/Frontend/backend-diagnostic.c
===
--- clang/test/Frontend/backend-diagnostic.c
+++ clang/test/Frontend/backend-diagnostic.c
@@ -15,9 +15,9 @@
 
 extern void doIt(char *);
 
-// REGULAR: warning: stack frame size ([[#]]) exceeds limit ([[#]]) in function 'stackSizeWarning'
-// PROMOTE: error: stack frame size ([[#]]) exceeds limit ([[#]]) in function 'stackSizeWarning'
-// IGNORE-NOT: stack frame size ([[#]]) exceeds limit ([[#]]) in function 'stackSizeWarning'
+// REGULAR: warning: stack frame size ([[#]]) exceeds limit ([[#]]) in 'stackSizeWarning'
+// PROMOTE: error: stack frame size ([[#]]) exceeds limit ([[#]]) in 'stackSizeWarning'
+// IGNORE-NOT: stack frame size ([[#]]) exceeds limit ([[#]]) in 'stackSizeWarning'
 void stackSizeWarning() {
   char buffer[80];
   doIt(buffer);
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -25,6 +25,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/Hashing.h"
 #include "llvm/Bitcode/BitcodeReader.h"
 #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
 #include "llvm/Demangle/Demangle.h"
@@ -126,6 +127,17 @@
 
 SmallVector LinkModules;
 
+// A map from mangled names to their function's source location, used for
+// backend diagnostics as the Clang AST may be unavailable. We actually use
+// the mangled name's hash as the key because mangled names can be very
+// long and take up lots of space. Using a hash can cause name collision,
+// but that is rare and the consequences are pointing to a wrong source
+// location which is not severe. This is a vector instead of a

[PATCH] D109632: [clang] de-duplicate methods from AST files

2021-10-04 Thread Richard Howell via Phabricator via cfe-commits
rmaz added a comment.

In D109632#3037501 , @vsapsai wrote:

> My assumption was that all dependent modules are in memory at this point. And 
> we visit transitive modules only once, so I don't expect it to be a big 
> performance hit (though I can be wrong). And deserializing methods from 
> different modules shouldn't be more work because we are deserializing fewer 
> methods than with "set dedupe".

I added some stats collection for the number of methods deserialized, here are 
the results from the slowest file in the above table:

| **Method**  | **# Module File Lookups** | **# Module File Hits** | **# 
Instance Methods Deserialized** | **# Class Methods Deserialized** |
| Baseline| 34023 | 129| 82005  
 | 29298|
| Set Dedupe  | 34023 | 129| 13743  
 | 6781 |
| No external | 45265 | 960| 4010   
 | 1704 |
|

So while the no external approach has ~3.5x fewer methods to deserialize, it 
has to visit ~7.5x as many module files to deserialize methods from.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109632

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


[PATCH] D76096: [clang] allow const structs to be constant expressions in initializer lists

2021-10-04 Thread Tom Hughes via Phabricator via cfe-commits
tomhughes added a comment.

I'm hitting this in the codebase that I'm working on as well. What are the next 
steps (besides reformatting)? It's not completely clear to me from the 
comments. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76096

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


[PATCH] D111100: enable plugins for clang-tidy

2021-10-04 Thread Jameson Nash via Phabricator via cfe-commits
vtjnash created this revision.
Herald added a subscriber: mgorny.
vtjnash requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Fixes 32739


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D00

Files:
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp


Index: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -20,6 +20,7 @@
 #include "../GlobList.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "llvm/Support/InitLLVM.h"
+#include "llvm/Support/PluginLoader.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@ -29,11 +29,17 @@
   clangToolingCore
   )
 
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  set(support_plugins SUPPORT_PLUGINS)
+endif()
+
 add_clang_tool(clang-tidy
   ClangTidyToolMain.cpp
-  )
-add_dependencies(clang-tidy
+
+  DEPENDS
   clang-resource-headers
+  ${support_plugins}
   )
 clang_target_link_libraries(clang-tidy
   PRIVATE
@@ -50,6 +56,9 @@
   ${ALL_CLANG_TIDY_CHECKS}
   )
 
+if(CLANG_PLUGIN_SUPPORT)
+  export_executable_symbols_for_plugins(clang-tidy)
+endif()
 
 install(PROGRAMS clang-tidy-diff.py
   DESTINATION share/clang


Index: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -20,6 +20,7 @@
 #include "../GlobList.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "llvm/Support/InitLLVM.h"
+#include "llvm/Support/PluginLoader.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@ -29,11 +29,17 @@
   clangToolingCore
   )
 
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  set(support_plugins SUPPORT_PLUGINS)
+endif()
+
 add_clang_tool(clang-tidy
   ClangTidyToolMain.cpp
-  )
-add_dependencies(clang-tidy
+
+  DEPENDS
   clang-resource-headers
+  ${support_plugins}
   )
 clang_target_link_libraries(clang-tidy
   PRIVATE
@@ -50,6 +56,9 @@
   ${ALL_CLANG_TIDY_CHECKS}
   )
 
+if(CLANG_PLUGIN_SUPPORT)
+  export_executable_symbols_for_plugins(clang-tidy)
+endif()
 
 install(PROGRAMS clang-tidy-diff.py
   DESTINATION share/clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 95f824a - Revert "[clang][Fuchsia] Re-enable compiler-rt tests in runtimes build"

2021-10-04 Thread Leonard Chan via cfe-commits

Author: Leonard Chan
Date: 2021-10-04T16:11:43-07:00
New Revision: 95f824ad7c2da1e8142dbade4e4e12f389f1eb78

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

LOG: Revert "[clang][Fuchsia] Re-enable compiler-rt tests in runtimes build"

This reverts commit 8480063f25b8527d935722769d54d47f0c0d5689.

We're seeing some test failures on our builders.

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 5efa3028a0c6..1fbbaf74b0ec 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -120,7 +120,6 @@ foreach(target 
aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unkn
 set(RUNTIMES_${target}_CMAKE_MODULE_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
 set(RUNTIMES_${target}_CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING 
"")
 set(RUNTIMES_${target}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "")
-set(RUNTIMES_${target}_COMPILER_RT_CAN_EXECUTE_TESTS ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")
 set(RUNTIMES_${target}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")



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


[PATCH] D76169: [WIP][AST] Allow ExprConstant to evaluate structs in C.

2021-10-04 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a subscriber: erichkeane.
nickdesaulniers added a comment.

Looks like @erichkeane was in the neighborhood in 
606a734755d1fb6c35a17680d0c251f834b79334 
 
("[PR47636] Fix tryEmitPrivate to handle non-constantarraytypes").


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76169

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


[PATCH] D111105: [clang] Add option to clear AST memory before running LLVM passes

2021-10-04 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks created this revision.
Herald added subscribers: dexonsmith, dang.
aeubanks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is to save memory for Clang compiles.
Measuring building PassBuilder.cpp under /usr/bin/time, max rss goes from 
0.93GB to 0.7GB.

This does not turn it by default yet.

I've turned on the option locally and run it over a good amount of files 
without any issues.

For more background, see
https://lists.llvm.org/pipermail/cfe-dev/2021-September/068930.html.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D05

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/Misc/clear-ast-before-backend.c


Index: clang/test/Misc/clear-ast-before-backend.c
===
--- /dev/null
+++ clang/test/Misc/clear-ast-before-backend.c
@@ -0,0 +1,3 @@
+// RUN: %clang -target x86_64-linux-gnu -c -Xclang -clear-ast-before-backend 
%s -S
+// RUN: %clang -target x86_64-linux-gnu -c -Xclang -clear-ast-before-backend 
%s -S -### 2>&1 | FileCheck %s
+// CHECK: "-clear-ast-before-backend"
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -351,6 +351,11 @@
 }
   }
 
+  // FIXME: Fix cleanup issues with clearing the AST when we properly free
+  // things.
+  if (CodeGenOpts.DisableFree && CodeGenOpts.ClearASTBeforeBackend)
+C.getAllocator().Reset();
+
   EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef());
 
   EmitBackendOutput(Diags, HeaderSearchOpts, CodeGenOpts, TargetOpts,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5297,6 +5297,9 @@
 def disable_free : Flag<["-"], "disable-free">,
   HelpText<"Disable freeing of memory on exit">,
   MarshallingInfoFlag>;
+def clear_ast_before_backend : Flag<["-"], "clear-ast-before-backend">,
+  HelpText<"Clear the Clang AST before running backend code generation">,
+  MarshallingInfoFlag>;
 def enable_noundef_analysis : Flag<["-"], "enable-noundef-analysis">, 
Group,
   HelpText<"Enable analyzing function argument and return types for mandatory 
definedness">,
   MarshallingInfoFlag>;
Index: clang/include/clang/Basic/CodeGenOptions.def
===
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -54,6 +54,7 @@
 CODEGENOPT(EnableAIXExtendedAltivecABI, 1, 0) ///< Set for -mabi=vec-extabi. 
Enables the extended Altivec ABI on AIX.
 ENUM_CODEGENOPT(FramePointer, FramePointerKind, 2, FramePointerKind::None) /// 
frame-pointer: all,non-leaf,none
 
+CODEGENOPT(ClearASTBeforeBackend , 1, 0) ///< Free the AST before running 
backend code generation. Only works with -disable-free.
 CODEGENOPT(DisableFree   , 1, 0) ///< Don't free memory.
 CODEGENOPT(DiscardValueNames , 1, 0) ///< Discard Value Names from the IR 
(LLVMContext flag)
 CODEGENOPT(DisableLLVMPasses , 1, 0) ///< Don't run any LLVM IR passes to get


Index: clang/test/Misc/clear-ast-before-backend.c
===
--- /dev/null
+++ clang/test/Misc/clear-ast-before-backend.c
@@ -0,0 +1,3 @@
+// RUN: %clang -target x86_64-linux-gnu -c -Xclang -clear-ast-before-backend %s -S
+// RUN: %clang -target x86_64-linux-gnu -c -Xclang -clear-ast-before-backend %s -S -### 2>&1 | FileCheck %s
+// CHECK: "-clear-ast-before-backend"
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -351,6 +351,11 @@
 }
   }
 
+  // FIXME: Fix cleanup issues with clearing the AST when we properly free
+  // things.
+  if (CodeGenOpts.DisableFree && CodeGenOpts.ClearASTBeforeBackend)
+C.getAllocator().Reset();
+
   EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef());
 
   EmitBackendOutput(Diags, HeaderSearchOpts, CodeGenOpts, TargetOpts,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5297,6 +5297,9 @@
 def disable_free : Flag<["-"], "disable-free">,
   HelpText<"Disable freeing of memory on exit">,
   MarshallingInfoFlag>;
+def clear_ast_before_backend : Flag<["-"], "clear-ast-before-backend">,
+  HelpText<"Clear the Clang AST before running backend code generation">,
+  MarshallingInfoFlag>;
 def enable_noundef_analysis : Flag<["-"], "enable-noundef-analysis">, Group,

[PATCH] D110663: [Driver] Support Debian multiarch style lib/clang/14.0.0/x86_64-linux-gnu runtime path and include/x86_64-linux-gnu/c++/v1 libc++ path

2021-10-04 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.
Herald added a reviewer: ctetreau.

In D110663#3029577 , @phosek wrote:

> This is going to break Fuchsia as implemented. We assume that 
> `{x86_64,aarch64}-unknown-fuchsia` and `{x86_64,aarch64}-fuchsia` behave 
> identically and developers are allowed to use whichever spelling they prefer. 
> With this change that's no longer true. This may break other platforms that 
> make similar assumptions.

Are Fuchsia developers specifying `--target=` explicitly? I think that's the 
direction we don't want to support.

From my understanding of D110900 , if a Linux 
distro prefers `*-linux` to `*-linux-gnu`, we should drop `--target=` 
normalization to make this available.

I can special case Fuchsia to use the normalized triple, but that's code that I 
want to avoid.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110663

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


  1   2   >