[PATCH] D119648: [clang-format] Fix PointerAlignment within lambdas in a multi-variable declaration statement.

2022-02-13 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:8415-8417
+  verifyFormat("if (int *p, *q; p != q) {\n  p = p->next;\n}", Style);
+  verifyFormat("/*comment*/ if (int *p, *q; p != q) {\n  p = p->next;\n}",
+   Style);

owenpan wrote:
> Same as lines 8412-8414.
Some problem with the patch, it wasn't in this commit. Will fix after landing 
other revisions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119648

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


[PATCH] D119651: [clang] Fix evaluation context type for consteval function calls in instantiations

2022-02-13 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D119651#3317346 , @erichkeane 
wrote:

> I'm pretty sure @cor3ntin just messed with this quite a bit, so I'd like to 
> hear his thoughts on this. But this generally looks right on first blush.

Probably not as much as you haha.
There seems to be quite a number of consteval related issues still - 
https://reviews.llvm.org/D113859 is very similar - yet completely unrelated -

This patch does look okay to me, in so far as it fixes this issue, in a way 
that seems sensible to me. I'm just wondering if there are similar issues in 
other places...should we survey all the evaluation contexts to see see if that 
can occur in other places?
Should we maybe always treat `PotentiallyEvaluated` as `ConstantEvaluated` in 
constant evaluated contexts? could that work ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119651

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


[PATCH] D119646: [clang] Allow consteval functions in default arguments

2022-02-13 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

There is also https://reviews.llvm.org/D74130 which tries to address the same 
issue in a very different way.
I don't really understand the different approaches yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119646

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


[PATCH] D119481: run-clang-tidy: Fix infinite loop on windows

2022-02-13 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz added a comment.

Just a drive-by comment to say, thank you for taking the time to make this fix. 
It's a bug I've triggered many times. Great to see it being resolved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119481

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


[PATCH] D119648: [clang-format] Fix PointerAlignment within lambdas in a multi-variable declaration statement.

2022-02-13 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D119648#3317212 , @owenpan wrote:

> Does any C++ standard support init statements in `while` loops?

I actually thought there was. But that was a mistake. :)




Comment at: clang/lib/Format/TokenAnnotator.cpp:32
 static bool startsWithStatementWithInitializer(const AnnotatedLine &Line) {
   return Line.startsWith(tok::kw_for) || Line.startsWith(tok::kw_if);
 }

But switch can have such a statement.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119648

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


[PATCH] D119601: [analyzer] Refactor makeNull to makeNullWithWidth

2022-02-13 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Thanks for the comments. I'll address and revert back soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119601

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


[PATCH] D119650: [clang-format] Handle PointerAlignment in `if` statements with initializers (C++17) the same way as in `for` loops.

2022-02-13 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:32
+static bool startsWithStatementWithInitializer(const AnnotatedLine &Line) {
+  return Line.startsWith(tok::kw_for) || Line.startsWith(tok::kw_if);
+}

Here a switch? I'm confused in which patch the function is added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119650

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


[PATCH] D119599: Add option to align compound assignments like `+=`

2022-02-13 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/include/clang/Format/Format.h:157
+  ///   a   &= 2;
+  ///   bbb  = 2;
+  ///

sstwcw wrote:
> HazardyKnusperkeks wrote:
> > sstwcw wrote:
> > > HazardyKnusperkeks wrote:
> > > > curdeius wrote:
> > > > > I guess it would be complicated to avoid adding an additional space 
> > > > > here. I mean, it could be:
> > > > > ```
> > > > > a  &= 2;
> > > > > bbb = 2;
> > > > > ```
> > > > > And with 3-char operators, there's one more space.
> > > > That would be awesome, but it should be an option to turn off or on.
> > > > But I think this would really be complicated.
> > > I can do it either way. But I thought without the extra space the 
> > > formatted code looked ugly, especially when mixing `>>=` and `=`.  Which 
> > > way do you prefer?
> > > 
> > > 
> > > ```
> > > a >>= 2;
> > > bbb = 2;
> > > ```
> > I would prefer an option, to be able to do both.
> > I think I would use the variant which is more compact, but can't say for 
> > sure until I really have the option and tried it.
> You mean like a new entry under `AlignConsecutiveStyle` with the options to 
> align the left ends of the operators and to align the equal sign with and 
> without padding them to the same length? I don't want the new option to be 
> merged with `AlignCompound`, because we are working on adding support for a 
> language that uses both `=` and `<=` for regular assignments, and maybe 
> someone will want to support a language that has both `=` and `:=` in the 
> future.
Yeah. Basing on @MyDeveloperDay 's suggestion:
```
struct AlignConsecutiveStyle {
  bool Enabled;
  bool AcrossComments;
  bool AcrossEmptyLines;
  bool AlignCompound;
  bool CompactWhitespace; // This is just a suggestion, I'm open for better 
names.
};
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119599

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


[PATCH] D113369: [clang-format] Extend SpaceBeforeParens for requires

2022-02-13 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

I need a response here. :) @Quuxplusone are the names okay for you?


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

https://reviews.llvm.org/D113369

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


[PATCH] D119601: [analyzer] Refactor makeNull to makeNullWithWidth

2022-02-13 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

In D119601#3317317 , @NoQ wrote:

>> steakhal performed systems testing across a large set of open source 
>> projects.
>
> I'm curious if any findings there caused you to make changes in the patch. If 
> so it'd be great to reduce them into test cases so that other people didn't 
> make the same mistake when they edit your new code.

This patch was driven mostly by the negative cases we uncovered as represented 
in patch https://reviews.llvm.org/D118050. Basically, we have an internal 
proprietary multicore CPU with a CPU-local address space and a "global" common 
address space. We support memcpy intrinsics to copy to/from these memories with 
the different address space pointers - which also happen to be different 
pointer widths. The CString checker does an overlap check, and an assert caught 
a pointer comparison using different pointer widths. So the basic fix is to 
avoid overlap checks when the pointers are of different address spaces, and 
then that change ripples into these changes and the required supporting test 
cases. We also see similar problems in the SMTConv layer that we're just 
patching up internally for now in a non-principled way that are not suitable 
for upstreaming.

Since our target is downstream, it's challenging to find equivalent and 
relevant test cases, but we've made some headway since we found some GPUs also 
have similar properties. https://reviews.llvm.org/D118050 has one such test 
case. Perhaps it makes sense to squash that change with this one? @NoQ, do you 
have thoughts or a recommendation for squashing these two changes?

I believe some of the changes local to this patch can be covered with 
equivalent GPU test cases, I'll see if that can be created and add them.

As always, thanks for the guidance. Best


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119601

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


[clang] 4b43209 - [clang][sema] Use castAs<> instead of getAs<> to avoid dereference of nullptr

2022-02-13 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-02-13T13:14:05Z
New Revision: 4b432096839e719ec0b78cd0299e7950a59dce0b

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

LOG: [clang][sema] Use castAs<> instead of getAs<> to avoid dereference of 
nullptr

The pointers are referenced immediately, so assert the cast is correct instead 
of returning nullptr

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6629f3e061f80..22b3f371afe79 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3022,7 +3022,7 @@ Sema::PerformObjectMemberConversion(Expr *From,
 QualType QType = QualType(Qualifier->getAsType(), 0);
 assert(QType->isRecordType() && "lookup done with non-record type");
 
-QualType QRecordType = QualType(QType->getAs(), 0);
+QualType QRecordType = QualType(QType->castAs(), 0);
 
 // In C++98, the qualifier type doesn't actually have to be a base
 // type of the object type, in which case we just ignore it.
@@ -10035,7 +10035,7 @@ static bool tryGCCVectorConvertAndSplat(Sema &S, 
ExprResult *Scalar,
 ExprResult *Vector) {
   QualType ScalarTy = Scalar->get()->getType().getUnqualifiedType();
   QualType VectorTy = Vector->get()->getType().getUnqualifiedType();
-  const VectorType *VT = VectorTy->getAs();
+  const auto *VT = VectorTy->castAs();
 
   assert(!isa(VT) &&
  "ExtVectorTypes should not be handled here!");



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


[PATCH] D119646: [clang] Allow consteval functions in default arguments

2022-02-13 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added a comment.

In D119646#3317473 , @cor3ntin wrote:

> There is also https://reviews.llvm.org/D74130 which tries to address the same 
> issue in a very different way.
> I don't really understand the different approaches yet.

Thanks! I spent some time researching this review (but tbh I don't fully 
understand it yet too). I can say why this patch seems to be so different.

The author aims to make this snippet working

  consteval int f1() { return 0; }
  consteval auto g() { return f1; }
  consteval int h(int (*p)() = g()) { return p(); } // should work

That is, they want to make usable pointers to consteval function in default 
arguments. My patch doesn't compile this code now (the behaviour is same as in 
trunk).
As far as I see, the main problem is that the evaluation of ParmVarDecl's 
ConstantExpr is "isolated" from the evaluation of the consteval function body. 
Therefore the pointer "breaks the constexpr wall" and "falls out" to run-time, 
that's illegal. I'm not sure if my explanation is clear...

I wonder if it could be a different pull request later if someone will want to 
make pointers working? The review you mentioned is 2 years old, pretty massive 
and still has failing tests.




Comment at: clang/lib/AST/Decl.cpp:2816
   if (auto *E = dyn_cast_or_null(Arg))
-return E->getSubExpr();
+if (!isa(E))
+  return E->getSubExpr();

erichkeane wrote:
> So what is happening here?  I would still expect us to give the proper 
> default-arg in this case?  What subtly am I missing?
If we have nested ConstantExprs within the default argument expression, like 
here
```
consteval int Fun(int x) { return x; }

struct Test {
  Test(int loc = Fun(1) * 3 + Fun(2)) {}
  // or, for example, Test(int loc = 0 + Fun(4));
};
```
Then the patch fixes it fine with just `void VisitConstantExpr...` (the snippet 
where you said //"This part makes sense to me."//).

The AST for ParmVarDecl looks like this - [[ 
https://gist.githubusercontent.com/Izaron/7b49d4814a04d16c8014d973bd397ac4/raw/fd5948ca164a381ed13950f04934cb19f847141d/nested.ast
 | snippet on gist.github.com ]]. Clang will fold the ConstantExprs.

---

However, if the ConstantExpr is top-level, that is, the code looks like this:
```
struct Test {
  Test(int loc = Fun(4)) {}
};
```
Then the AST looks like this - [[ 
https://gist.githubusercontent.com/Izaron/dec1f3f0b62769c8fe4f4cb961c211d7/raw/79c5b9364e93de7ebc3d905f87162e000c6e695b/top-level.ast
 | snippet on gist.github.com ]].

There are some places in the code where we call `ParmVarDecl::getDefaultArg()` 
(CodeGen/etc.) The callee will "jump over" the ConstantExpr (since it is 
derived from FullExpr) and give you the nested CallExpr. That's quite incorrent 
because we aren't going to evaluate this CallExpr in run-time. For example, if 
we don't patch this place, the CodeGen will declare `Fun` at LLVM IR, and 
everything breaks.

So I decided that we shouldn't "jump over" ConstantExpr, otherwise it 
incorrectly says to the caller that we are supposed to calculate it in run-time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119646

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


[PATCH] D119651: [clang] Fix evaluation context type for consteval function calls in instantiations

2022-02-13 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added a comment.

> Should we maybe always treat `PotentiallyEvaluated` as `ConstantEvaluated` in 
> constant evaluated contexts? could that work ?

Indeed, within this patch we can prevent similars bugs to appear. I researched 
other places where a new context is pushed, and haven't find other bugs, but 
nevertheless.
In my subjective opinion, the architecture of `ExprEvalContext` is pretty 
fragile... We could add an assert before this line 
,
 ensuring that we don't push a (runtime) evaluated context after an immediate 
context. Or should we just don't push the new context in this case?... I wonder 
what is better, can't say right now =(

In D119651#3317458 , @cor3ntin wrote:

> There seems to be quite a number of consteval related issues still - 
> https://reviews.llvm.org/D113859 is very similar - yet completely unrelated -
>
> This patch does look okay to me, in so far as it fixes this issue, in a way 
> that seems sensible to me. I'm just wondering if there are similar issues in 
> other places...

BTW after looking at consteval-related issues on github 
, 
I've made four bite-sized patches. The issues are indeed completely unrelated 
to each other and do not have common source of errors.

https://reviews.llvm.org/D119095 Extra constructor call - a fix in 
`RemoveNestedImmediateInvocation`.
https://reviews.llvm.org/D119375 Trying to evaluate value-dependent 
ConstantExpr - a fix in `CheckForImmediateInvocation` (approved)
https://reviews.llvm.org/D119646 Trying to mark declarations as "referenced" 
inside a ConstantExpr in default arguments - a fix in the custom def. arg. AST 
visitor.
https://reviews.llvm.org/D119651 (This patch) a `PotentiallyEvaluated` context 
is created within a `ConstantEvaluated` context - remove where we do this.

As far as I see, the consteval bugs rarely have common source... They mostly 
require ad-hoc solutions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119651

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


[PATCH] D119525: [clang] Fix crash when array size is missing in initializer

2022-02-13 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added a comment.

In D119525#3314383 , @aaron.ballman 
wrote:

> Can you also add a release note for the change?

Would this go in the "libclang" section in `clang/docs/ReleaseNotes.rst`? Or 
somewhere else?


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

https://reviews.llvm.org/D119525

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


[PATCH] D119664: Check for the overloadable attribute in all the appropriate syntactic locations

2022-02-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: erichkeane, cor3ntin, rsmith.
aaron.ballman requested review of this revision.
Herald added a project: clang.

When forming the function type from a declarator, we look for an overloadable 
attribute before issuing a diagnostic in C about a function signature 
containing only `...`. When the attribute is present, we allow such a 
declaration for compatibility with the overloading rules in C++. However, we 
were not looking for the attribute in all of the places it is legal to write it 
on a declarator and so we only accepted the signature in some forms and 
incorrectly rejected the signature in others.

We now check for the attribute preceding the declarator instead of only being 
applied to the declarator directly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119664

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaType.cpp
  clang/test/Sema/overloadable.c


Index: clang/test/Sema/overloadable.c
===
--- clang/test/Sema/overloadable.c
+++ clang/test/Sema/overloadable.c
@@ -248,3 +248,14 @@
   // if take_fn is passed a void (**)(void *), we'll get a warning.
   take_fn(fn);
 }
+
+// PR53805
+// We previously failed to consider the attribute being written before the
+// declaration when considering whether to allow a variadic signature with no
+// other parameters, and so we handled these cases differently.
+__attribute__((overloadable)) void can_overload_1(...); // ok, was previously 
rejected
+void can_overload_2(...) __attribute__((overloadable)); // ok
+[[clang::overloadable]] void can_overload_3(...);   // ok, was previously 
rejected
+void can_overload_4 [[clang::overloadable]] (...);  // ok
+void cannot_overload(...) [[clang::overloadable]];  // expected-error 
{{ISO C requires a named parameter before '...'}} \
+// expected-error 
{{'overloadable' attribute cannot be applied to types}}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5237,7 +5237,9 @@
 // function is marked with the "overloadable" attribute. Scan
 // for this attribute now.
 if (!FTI.NumParams && FTI.isVariadic && !LangOpts.CPlusPlus)
-  if (!D.getAttributes().hasAttribute(ParsedAttr::AT_Overloadable))
+  if (!D.getAttributes().hasAttribute(ParsedAttr::AT_Overloadable) &&
+  !D.getDeclSpec().getAttributes().hasAttribute(
+  ParsedAttr::AT_Overloadable))
 S.Diag(FTI.getEllipsisLoc(), diag::err_ellipsis_first_param);
 
 if (FTI.NumParams && FTI.Params[0].Param == nullptr) {
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -77,6 +77,9 @@
 
 - Added support for parameter pack expansion in `clang::annotate`.
 
+- The ``overloadable`` attribute can now be written in all of the syntactic
+  locations a declaration attribute may appear. Fixes PR53805.
+
 Windows Support
 ---
 


Index: clang/test/Sema/overloadable.c
===
--- clang/test/Sema/overloadable.c
+++ clang/test/Sema/overloadable.c
@@ -248,3 +248,14 @@
   // if take_fn is passed a void (**)(void *), we'll get a warning.
   take_fn(fn);
 }
+
+// PR53805
+// We previously failed to consider the attribute being written before the
+// declaration when considering whether to allow a variadic signature with no
+// other parameters, and so we handled these cases differently.
+__attribute__((overloadable)) void can_overload_1(...); // ok, was previously rejected
+void can_overload_2(...) __attribute__((overloadable)); // ok
+[[clang::overloadable]] void can_overload_3(...);   // ok, was previously rejected
+void can_overload_4 [[clang::overloadable]] (...);  // ok
+void cannot_overload(...) [[clang::overloadable]];  // expected-error {{ISO C requires a named parameter before '...'}} \
+// expected-error {{'overloadable' attribute cannot be applied to types}}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5237,7 +5237,9 @@
 // function is marked with the "overloadable" attribute. Scan
 // for this attribute now.
 if (!FTI.NumParams && FTI.isVariadic && !LangOpts.CPlusPlus)
-  if (!D.getAttributes().hasAttribute(ParsedAttr::AT_Overloadable))
+  if (!D.getAttributes().hasAttribute(ParsedAttr::AT_Overloadable) &&
+  !D.getDeclSpec().getAttributes().hasAttribute(
+  ParsedAttr::AT_Overloadable))
 S.Diag(F

[PATCH] D118070: Make lld-link work in a non-MSVC shell

2022-02-13 Thread Nico Weber via Phabricator via cfe-commits
thakis reopened this revision.
thakis added a comment.
This revision is now accepted and ready to land.

(reopening for fixing things + relanding)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

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


[PATCH] D118070: Make lld-link work in a non-MSVC shell

2022-02-13 Thread Nico Weber via Phabricator via cfe-commits
thakis requested changes to this revision.
thakis added a comment.
This revision now requires changes to proceed.

(also marking as "request changes" for the Optional change we need)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

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


[PATCH] D119664: Check for the overloadable attribute in all the appropriate syntactic locations

2022-02-13 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM
(I didn't know `can_overload_4` was a valid place to put a C attribute)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119664

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


[PATCH] D119407: [PowerPC] [Clang] Add SSE4 and BMI compatible intrinsics implementation for PowerPC

2022-02-13 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf planned changes to this revision.
qiucf added a comment.

This breaks existing smm/tmm tests, will update/clean-up them before this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119407

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


[PATCH] D119670: [clang] Warn on unqualified calls to std::move and std::forward

2022-02-13 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.

This adds a diagnostic when an unqualified call is resolved
to std::move or std::forward.

This follows some C++ committee discussions where some
people where concerns that this might be an usual anti pattern
particularly britle worth warning about - both because move
is a common name and because these functions accept any values.

This warns inconditionnally of whether the current context is in
std:: or not, as implementations probably want to always qualify
these calls too, to avoid triggering adl accidentally.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119670

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/unqualified-std-call-fixits.cpp
  clang/test/SemaCXX/unqualified-std-call.cpp
  clang/test/SemaCXX/warn-self-move.cpp

Index: clang/test/SemaCXX/warn-self-move.cpp
===
--- clang/test/SemaCXX/warn-self-move.cpp
+++ clang/test/SemaCXX/warn-self-move.cpp
@@ -17,7 +17,8 @@
   (x) = std::move(x);  // expected-warning{{explicitly moving}}
 
   using std::move;
-  x = move(x);  // expected-warning{{explicitly moving}}
+  x = move(x); // expected-warning{{explicitly moving}} \
+   expected-warning {{unqualified call to std::move}}
 }
 
 int global;
@@ -26,7 +27,8 @@
   (global) = std::move(global);  // expected-warning{{explicitly moving}}
 
   using std::move;
-  global = move(global);  // expected-warning{{explicitly moving}}
+  global = move(global); // expected-warning{{explicitly moving}} \
+ expected-warning {{unqualified call to std::move}}
 }
 
 class field_test {
Index: clang/test/SemaCXX/unqualified-std-call.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/unqualified-std-call.cpp
@@ -0,0 +1,92 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall -std=c++11 %s
+
+namespace std {
+
+template 
+void dummy(T &&) {}
+template 
+void move(T &&) {}
+template 
+void move(T &&, U &&) {}
+template 
+void forward(T &) {}
+
+} // namespace std
+
+namespace global {
+
+using namespace std;
+
+void f() {
+  int i = 0;
+  std::move(i);
+  move(i);   // expected-warning{{unqualified call to std::move}}
+  (move)(i); // expected-warning{{unqualified call to std::move}}
+  std::dummy(1);
+  dummy(1);
+  std::move(1, 2);
+  move(1, 2);
+}
+
+template 
+void g(T &&foo) {
+  std::move(foo);
+  move(foo); // expected-warning{{unqualified call to std::move}}
+
+  std::forward(foo);
+  forward(foo); // expected-warning{{unqualified call to std::forward}}
+  move(1, 2);
+  dummy(foo);
+}
+
+void call() {
+  g(0); //expected-note {{here}}
+}
+
+} // namespace global
+
+namespace named {
+
+using std::forward;
+using std::move;
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning{{unqualified call to std::move}}
+  move(1, 2);
+}
+
+template 
+void g(T &&foo) {
+  move(foo); // expected-warning{{unqualified call to std::move}}
+  forward(foo);   // expected-warning{{unqualified call to std::forward}}
+  (forward)(foo); // expected-warning{{unqualified call to std::forward}}
+  move(1, 2);
+}
+
+void call() {
+  g(0); //expected-note {{here}}
+}
+
+} // namespace named
+
+namespace overload {
+using namespace std;
+template 
+int move(T &&);
+void f() {
+  int i = 0;
+  move(i);
+}
+} // namespace overload
+
+namespace test_alias {
+namespace alias = std;
+using namespace alias;
+void f() {
+  int i = 0;
+  move(i); // expected-warning{{unqualified call to std::move}}
+  move(1, 2);
+}
+
+} // namespace test_alias
Index: clang/test/SemaCXX/unqualified-std-call-fixits.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/unqualified-std-call-fixits.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -verify -std=c++20 -Wall %s
+// RUN: cp %s %t
+// RUN: %clang_cc1 -x c++ -std=c++20 -fixit %t
+// RUN: %clang_cc1 -Wall -Werror -x c++ -std=c++20 %t
+// RUN: cat %t | FileCheck %s
+
+namespace std {
+
+void move(auto &&a) {}
+
+void forward(auto &a) {}
+
+} // namespace std
+
+using namespace std;
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning {{unqualified call to std::move}}
+  // CHECK: {{^}}  std::
+  forward(i); // expected-warning {{unqualified call to std::forward}}
+  // CHECK: {{^}}  std::
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -6416,6 +6416,39 @@
   }
 }
 
+// Once a call is fully resolved, warn for unqualified calls to specific
+// C++ standard functions, like move and forward
+static void DiagnosedUnqualifiedCallsToStdFunctions(Sema &S, CallExpr *Call) {
+  // We are only checking move and forward so e

[PATCH] D119670: [clang] Warn on unqualified calls to std::move and std::forward

2022-02-13 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

There may be some things worth considering here:

- libc++ own tests and build is affected, I have not addressed these yet.
- other standard libs are affected but because they are considered system 
headers, no warning is emitted

I think this is a worth while first approach. We might want to consider a "warn 
on adl calls" attribute, or something of that nature, but it would be added to 
probably a lot of functions, so maybe we want the opposite but that might also 
be very noisy.
I'm also itching to warn of using namespace at file scope, but maybe that's 
better left in clang tidy?

Anyway, the current proposed solution should have no false positive or false 
negative, and we can expand from there as needed if people find the warning 
useful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119670

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


[PATCH] D119670: [clang] Warn on unqualified calls to std::move and std::forward

2022-02-13 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:4812
+def warn_unqualified_call_to_std_function : Warning<
+  "unqualified call to %0">, InGroup>;
+

This should probably be named `-Wunqualified-std-move` resp. 
`-Wunqualified-std-forward`, so that we preserve our ability to add a more 
generalized `-Wunqualified-std-call` diagnostic (probably not enabled by 
default) in the future.

I'd actually like to go ahead and add the generalized diagnostic right now, 
since it would be about 10 extra lines of code, and at least //I// would use it 
as soon as it landed in trunk! But I'm prepared for that to be controversial 
and wouldn't necessarily pick that hill to die on. :)  (Ah, and I'm reminded 
that the generalized diagnostic would need a bigger list of hard-coded 
functions to ignore, such as `swap` and `begin` and `end` and so on.)



Comment at: clang/test/SemaCXX/unqualified-std-call.cpp:34
+  std::move(foo);
+  move(foo); // expected-warning{{unqualified call to std::move}}
+

I'd like to see a test where the template finds `move` via ADL, rather than 
being directly in the scope of a `using namespace std` directive. This is the 
most important case AIUI, because we can train people not to `using namespace` 
but we can't so easily train them not to accidentally forget a `std::`.
I'd like to see a couple of tests where the (function, resp. template) is 
itself located inside `namespace std`. (You mention you deliberately want to 
warn on this, and I think that's good, but I don't see any tests for it.)
I'd like to see a test where the `std::move` that is found by lookup is 
actually `std::__1::move` with an inline namespace, because that's what libc++ 
actually does in practice. (This should still warn.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119670

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


[PATCH] D119670: [clang] Warn on unqualified calls to std::move and std::forward

2022-02-13 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

Thanks for working on this! I'm overall very happy, but I don't see a test case 
for a unary `move` originating from another namespace.




Comment at: clang/lib/Sema/SemaExpr.cpp:6422
+static void DiagnosedUnqualifiedCallsToStdFunctions(Sema &S, CallExpr *Call) {
+  // We are only checking move and forward so exit early here
+  if (Call->getNumArgs() != 1)





Comment at: clang/lib/Sema/SemaExpr.cpp:6442
+  static constexpr llvm::StringRef SpecialFunctions[] = {"move", "forward"};
+  auto it = std::find(std::begin(SpecialFunctions), std::end(SpecialFunctions),
+  D->getName());

There's a range-based `llvm::find` in `llvm/STLExtras.h`.



Comment at: clang/test/SemaCXX/warn-self-move.cpp:19
 
   using std::move;
+  x = move(x); // expected-warning{{explicitly moving}} \

Perhaps this should warn if the algorithm `std::move` isn't seen by the 
compiler (that isn't a request for this patch).



Comment at: clang/test/SemaCXX/warn-self-move.cpp:20-21
   using std::move;
-  x = move(x);  // expected-warning{{explicitly moving}}
+  x = move(x); // expected-warning{{explicitly moving}} \
+   expected-warning {{unqualified call to std::move}}
 }

Rationale: there's less mental gymnastics when backslashes aren't involved.



Comment at: clang/test/SemaCXX/warn-self-move.cpp:30-31
   using std::move;
-  global = move(global);  // expected-warning{{explicitly moving}}
+  global = move(global); // expected-warning{{explicitly moving}} \
+ expected-warning {{unqualified call to std::move}}
 }




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119670

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


[PATCH] D117929: [XRay] Add support for RISCV

2022-02-13 Thread Ashwin Poduval via Phabricator via cfe-commits
ashwin98 added a comment.

In D117929#3314355 , @ashwin98 wrote:

> In D117929#3299751 , @dberris wrote:
>
>> In D117929#3276843 , @ashwin98 
>> wrote:
>>
>>> Fixed another lint issue, they should all be done for now hopefully.
>>>
>>> @dberris Sorry, I'm a little confused, do you mean I need to update some of 
>>> the clang tests for XRay instrumentation to test compilation and linking, 
>>> or add new ones for the llvm-xray tool under llvm/test/tools?
>>
>> Yes to both. :)
>>
>> There are already some tests that ensure the supported triples build with 
>> XRay instrumentation and that we can get the instrumentation map with the 
>> tooling on binaries generated with clang+lld. Extending those to support 
>> risc64 and ensure we're able to find the instrumentation with the tooling 
>> gives us higher confidence that this will work when the patch is accepted.
>
> Before running the tests, I've been testing some of the subcommands with the 
> generated logs. When xray account or stack was run directly on the log file, 
> the data for the instrumented functions was output (I believe the XRay tool 
> recognizes it as a YAML file and processes it as such). However, when passing 
> the --instr_map flag, issues crop up. I originally ran into an error about 
> the executable not being an ELF binary. I confirmed that clang was generating 
> ELF binaries. There was a test checking the triple architecture in 
> InstrumentationMap.cpp that seemed to be causing this.
>
> On including RISCV64 to the check, I see new issues while reading the 
> instrumentation map. How do I verify that the instrumentation map is being 
> generated correctly (or if there is a problem with it), and where is the code 
> that is responsible for the generation of the instrumentation map (is it in 
> xray_init.cpp)? I'm not sure if this is a RISCV compatibility issue with the 
> xray tool, or if I've missed something that is causing problems during the 
> instrumentation map initialization.

I traced the root cause of the issue.  It seems to be stemming from the 
instrumentation map's relocation handling, specifically, at line 129 of 
InstrumentationMap.cpp, when we try to extract the load address of the symbol. 
I believe that section of the code was written keeping AArch64 in mind, but I'm 
not too sure about what changes will need to be made to add RISCV 
compatibility, I'm trying to figure it out.


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

https://reviews.llvm.org/D117929

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


[PATCH] D119675: Also remove the empty StoredDeclsList entry from the lookup table

2022-02-13 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.
v.g.vassilev added reviewers: rsmith, balazske.
Herald added a reviewer: shafik.
v.g.vassilev requested review of this revision.

In case where we have removed all declarations for a given declaration name 
entry we should remove the whole StoredDeclsMap entry. This patch improves 
consistency in the lookup tables and helps cling/clang-repl error recovery.


Repository:
  rC Clang

https://reviews.llvm.org/D119675

Files:
  clang/lib/AST/DeclBase.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4243,6 +4243,10 @@
   // This asserts in the old implementation.
   DC->removeDecl(A0);
   EXPECT_FALSE(DC->containsDecl(A0));
+
+  // Make sure we do not leave a StoredDeclsList with no entries.
+  DC->removeDecl(A1);
+  ASSERT_EQ(Map->find(A1->getDeclName()), Map->end());
 }
 
 struct ImportFunctionTemplateSpecializations
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1524,7 +1524,11 @@
   if (Map) {
 StoredDeclsMap::iterator Pos = Map->find(ND->getDeclName());
 assert(Pos != Map->end() && "no lookup entry for decl");
-Pos->second.remove(ND);
+StoredDeclsList &List = Pos->second;
+List.remove(ND);
+// Clean up the entry if there are no more decls.
+if (List.isNull())
+  Map->erase(Pos);
   }
 } while (DC->isTransparentContext() && (DC = DC->getParent()));
   }


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4243,6 +4243,10 @@
   // This asserts in the old implementation.
   DC->removeDecl(A0);
   EXPECT_FALSE(DC->containsDecl(A0));
+
+  // Make sure we do not leave a StoredDeclsList with no entries.
+  DC->removeDecl(A1);
+  ASSERT_EQ(Map->find(A1->getDeclName()), Map->end());
 }
 
 struct ImportFunctionTemplateSpecializations
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1524,7 +1524,11 @@
   if (Map) {
 StoredDeclsMap::iterator Pos = Map->find(ND->getDeclName());
 assert(Pos != Map->end() && "no lookup entry for decl");
-Pos->second.remove(ND);
+StoredDeclsList &List = Pos->second;
+List.remove(ND);
+// Clean up the entry if there are no more decls.
+if (List.isNull())
+  Map->erase(Pos);
   }
 } while (DC->isTransparentContext() && (DC = DC->getParent()));
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9cb9445 - [clang-format] Correctly format loops and `if` statements even if preceded with comments.

2022-02-13 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-02-13T21:22:17+01:00
New Revision: 9cb944597907458ce9c2f6bd0ecc9723b674b77f

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

LOG: [clang-format] Correctly format loops and `if` statements even if preceded 
with comments.

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

Braces in loops and in `if` statements with leading (block) comments were 
formatted according to `BraceWrapping.AfterFunction` and not 
`AllowShortBlocksOnASingleLine`/`AllowShortLoopsOnASingleLine`/`AllowShortIfStatementsOnASingleLine`.

Previously, the code:
```
while (true) {
  f();
}
/*comment*/ while (true) {
  f();
}
```

was incorrectly formatted to:
```
while (true) {
  f();
}
/*comment*/ while (true) { f(); }
```

when using config:
```
BasedOnStyle: LLVM
BreakBeforeBraces: Custom
BraceWrapping:
  AfterFunction: false
AllowShortBlocksOnASingleLine: false
AllowShortLoopsOnASingleLine: false
```

and it was (correctly but by chance) formatted to:
```
while (true) {
  f();
}
/*comment*/ while (true) {
  f();
}
```

when using enabling brace wrapping after functions:
```
BasedOnStyle: LLVM
BreakBeforeBraces: Custom
BraceWrapping:
  AfterFunction: true
AllowShortBlocksOnASingleLine: false
AllowShortLoopsOnASingleLine: false
```

Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 88efda487eeb6..883030cb3dc16 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -319,6 +319,15 @@ class LineJoiner {
 
 bool MergeShortFunctions = ShouldMergeShortFunctions();
 
+const FormatToken *FirstNonComment = TheLine->First;
+if (FirstNonComment->is(tok::comment)) {
+  FirstNonComment = FirstNonComment->getNextNonComment();
+  if (!FirstNonComment)
+return 0;
+}
+// FIXME: There are probably cases where we should use FirstNonComment
+// instead of TheLine->First.
+
 if (Style.CompactNamespaces) {
   if (auto nsToken = TheLine->First->getNamespaceToken()) {
 int i = 0;
@@ -358,9 +367,9 @@ class LineJoiner {
 if (TheLine->Last->is(TT_FunctionLBrace) && TheLine->First != 
TheLine->Last)
   return MergeShortFunctions ? tryMergeSimpleBlock(I, E, Limit) : 0;
 // Try to merge a control statement block with left brace unwrapped.
-if (TheLine->Last->is(tok::l_brace) && TheLine->First != TheLine->Last &&
-TheLine->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for,
-TT_ForEachMacro)) {
+if (TheLine->Last->is(tok::l_brace) && FirstNonComment != TheLine->Last &&
+FirstNonComment->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for,
+ TT_ForEachMacro)) {
   return Style.AllowShortBlocksOnASingleLine != FormatStyle::SBS_Never
  ? tryMergeSimpleBlock(I, E, Limit)
  : 0;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 0d315734bc951..40de29e58737f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1520,6 +1520,36 @@ TEST_F(FormatTest, FormatLoopsWithoutCompoundStatement) {
 
 TEST_F(FormatTest, FormatShortBracedStatements) {
   FormatStyle AllowSimpleBracedStatements = getLLVMStyle();
+  EXPECT_EQ(AllowSimpleBracedStatements.AllowShortBlocksOnASingleLine, false);
+  EXPECT_EQ(AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine,
+FormatStyle::SIS_Never);
+  EXPECT_EQ(AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine, false);
+  EXPECT_EQ(AllowSimpleBracedStatements.BraceWrapping.AfterFunction, false);
+  verifyFormat("for (;;) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("/*comment*/ for (;;) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("BOOST_FOREACH (int v, vec) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("/*comment*/ BOOST_FOREACH (int v, vec) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("while (true) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("/*comment*/ while (true) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("if (true) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("/*comment*/ if (true) {\n"
+   "  f();\n"
+   "}");
+
   AllowSimpleBracedStatements.IfMacros.push_back("MYIF");
   // Where line-lengths matter, a 2-letter synonym that m

[PATCH] D119649: [clang-format] Correctly format loops and `if` statements even if preceded with comments.

2022-02-13 Thread Marek Kurdej via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9cb944597907: [clang-format] Correctly format loops and `if` 
statements even if preceded with… (authored by curdeius).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119649

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1520,6 +1520,36 @@
 
 TEST_F(FormatTest, FormatShortBracedStatements) {
   FormatStyle AllowSimpleBracedStatements = getLLVMStyle();
+  EXPECT_EQ(AllowSimpleBracedStatements.AllowShortBlocksOnASingleLine, false);
+  EXPECT_EQ(AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine,
+FormatStyle::SIS_Never);
+  EXPECT_EQ(AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine, false);
+  EXPECT_EQ(AllowSimpleBracedStatements.BraceWrapping.AfterFunction, false);
+  verifyFormat("for (;;) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("/*comment*/ for (;;) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("BOOST_FOREACH (int v, vec) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("/*comment*/ BOOST_FOREACH (int v, vec) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("while (true) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("/*comment*/ while (true) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("if (true) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("/*comment*/ if (true) {\n"
+   "  f();\n"
+   "}");
+
   AllowSimpleBracedStatements.IfMacros.push_back("MYIF");
   // Where line-lengths matter, a 2-letter synonym that maintains line length.
   // Not IF to avoid any confusion that IF is somehow special.
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -319,6 +319,15 @@
 
 bool MergeShortFunctions = ShouldMergeShortFunctions();
 
+const FormatToken *FirstNonComment = TheLine->First;
+if (FirstNonComment->is(tok::comment)) {
+  FirstNonComment = FirstNonComment->getNextNonComment();
+  if (!FirstNonComment)
+return 0;
+}
+// FIXME: There are probably cases where we should use FirstNonComment
+// instead of TheLine->First.
+
 if (Style.CompactNamespaces) {
   if (auto nsToken = TheLine->First->getNamespaceToken()) {
 int i = 0;
@@ -358,9 +367,9 @@
 if (TheLine->Last->is(TT_FunctionLBrace) && TheLine->First != 
TheLine->Last)
   return MergeShortFunctions ? tryMergeSimpleBlock(I, E, Limit) : 0;
 // Try to merge a control statement block with left brace unwrapped.
-if (TheLine->Last->is(tok::l_brace) && TheLine->First != TheLine->Last &&
-TheLine->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for,
-TT_ForEachMacro)) {
+if (TheLine->Last->is(tok::l_brace) && FirstNonComment != TheLine->Last &&
+FirstNonComment->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for,
+ TT_ForEachMacro)) {
   return Style.AllowShortBlocksOnASingleLine != FormatStyle::SBS_Never
  ? tryMergeSimpleBlock(I, E, Limit)
  : 0;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1520,6 +1520,36 @@
 
 TEST_F(FormatTest, FormatShortBracedStatements) {
   FormatStyle AllowSimpleBracedStatements = getLLVMStyle();
+  EXPECT_EQ(AllowSimpleBracedStatements.AllowShortBlocksOnASingleLine, false);
+  EXPECT_EQ(AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine,
+FormatStyle::SIS_Never);
+  EXPECT_EQ(AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine, false);
+  EXPECT_EQ(AllowSimpleBracedStatements.BraceWrapping.AfterFunction, false);
+  verifyFormat("for (;;) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("/*comment*/ for (;;) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("BOOST_FOREACH (int v, vec) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("/*comment*/ BOOST_FOREACH (int v, vec) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("while (true) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("/*comment*/ while (true) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("if (true) {\n"
+   "  f();\n"
+   "}");
+  verifyFormat("/*co

[clang] 25282bd - [clang-format] Handle PointerAlignment in `if` and `switch` statements with initializers (C++17) the same way as in `for` loops.

2022-02-13 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-02-13T21:36:58+01:00
New Revision: 25282bd6c4bf54a21c0f8dbf00db6e70922c02fa

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

LOG: [clang-format] Handle PointerAlignment in `if` and `switch` statements 
with initializers (C++17) the same way as in `for` loops.

Reviewed By: MyDeveloperDay, owenpan

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index f1db5224fc55b..a6c6ddcad117b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -26,6 +26,13 @@ namespace format {
 
 namespace {
 
+/// Returns \c true if the line starts with a token that can start a statement
+/// with an initializer.
+static bool startsWithInitStatement(const AnnotatedLine &Line) {
+  return Line.startsWith(tok::kw_for) || Line.startsWith(tok::kw_if) ||
+ Line.startsWith(tok::kw_switch);
+}
+
 /// Returns \c true if the token can be used as an identifier in
 /// an Objective-C \c \@selector, \c false otherwise.
 ///
@@ -1135,7 +1142,7 @@ class AnnotatingParser {
   else if (Contexts.back().InInheritanceList)
 Tok->setType(TT_InheritanceComma);
   else if (Contexts.back().FirstStartOfName &&
-   (Contexts.size() == 1 || Line.startsWith(tok::kw_for))) {
+   (Contexts.size() == 1 || startsWithInitStatement(Line))) {
 Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = true;
 Line.IsMultiVariableDeclStmt = true;
   }
@@ -3090,7 +3097,7 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
 FormatStyle::PAS_Left ||
 (Line.IsMultiVariableDeclStmt &&
  (Left.NestingLevel == 0 ||
-  (Left.NestingLevel == 1 && Line.First->is(tok::kw_for);
+  (Left.NestingLevel == 1 && startsWithInitStatement(Line);
   }
   if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) &&
   (!Left.is(TT_PointerOrReference) ||

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 40de29e58737f..fc2b121faee02 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8396,6 +8396,12 @@ TEST_F(FormatTest, DeclarationsOfMultipleVariables) {
Style);
   verifyFormat("vector a, b;", Style);
   verifyFormat("for (int *p, *q; p != q; p = p->next) {\n}", Style);
+  verifyFormat("/*comment*/ for (int *p, *q; p != q; p = p->next) {\n}", 
Style);
+  verifyFormat("if (int *p, *q; p != q) {\n  p = p->next;\n}", Style);
+  verifyFormat("/*comment*/ if (int *p, *q; p != q) {\n  p = p->next;\n}",
+   Style);
+  verifyFormat("switch (int *p, *q; p != q) {\n  default:\nbreak;\n}", 
Style);
+  verifyFormat("/*comment*/ switch (int *p, *q; p != q) {\n  default:\n
break;\n}", Style);
 }
 
 TEST_F(FormatTest, ConditionalExpressionsInBrackets) {



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


[PATCH] D119650: [clang-format] Handle PointerAlignment in `if` and `switch` statements with initializers (C++17) the same way as in `for` loops.

2022-02-13 Thread Marek Kurdej via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
curdeius marked 2 inline comments as done.
Closed by commit rG25282bd6c4bf: [clang-format] Handle PointerAlignment in `if` 
and `switch` statements with… (authored by curdeius).

Changed prior to commit:
  https://reviews.llvm.org/D119650?vs=408216&id=408288#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119650

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8396,6 +8396,12 @@
Style);
   verifyFormat("vector a, b;", Style);
   verifyFormat("for (int *p, *q; p != q; p = p->next) {\n}", Style);
+  verifyFormat("/*comment*/ for (int *p, *q; p != q; p = p->next) {\n}", 
Style);
+  verifyFormat("if (int *p, *q; p != q) {\n  p = p->next;\n}", Style);
+  verifyFormat("/*comment*/ if (int *p, *q; p != q) {\n  p = p->next;\n}",
+   Style);
+  verifyFormat("switch (int *p, *q; p != q) {\n  default:\nbreak;\n}", 
Style);
+  verifyFormat("/*comment*/ switch (int *p, *q; p != q) {\n  default:\n
break;\n}", Style);
 }
 
 TEST_F(FormatTest, ConditionalExpressionsInBrackets) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -26,6 +26,13 @@
 
 namespace {
 
+/// Returns \c true if the line starts with a token that can start a statement
+/// with an initializer.
+static bool startsWithInitStatement(const AnnotatedLine &Line) {
+  return Line.startsWith(tok::kw_for) || Line.startsWith(tok::kw_if) ||
+ Line.startsWith(tok::kw_switch);
+}
+
 /// Returns \c true if the token can be used as an identifier in
 /// an Objective-C \c \@selector, \c false otherwise.
 ///
@@ -1135,7 +1142,7 @@
   else if (Contexts.back().InInheritanceList)
 Tok->setType(TT_InheritanceComma);
   else if (Contexts.back().FirstStartOfName &&
-   (Contexts.size() == 1 || Line.startsWith(tok::kw_for))) {
+   (Contexts.size() == 1 || startsWithInitStatement(Line))) {
 Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = true;
 Line.IsMultiVariableDeclStmt = true;
   }
@@ -3090,7 +3097,7 @@
 FormatStyle::PAS_Left ||
 (Line.IsMultiVariableDeclStmt &&
  (Left.NestingLevel == 0 ||
-  (Left.NestingLevel == 1 && Line.First->is(tok::kw_for);
+  (Left.NestingLevel == 1 && startsWithInitStatement(Line);
   }
   if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) &&
   (!Left.is(TT_PointerOrReference) ||


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8396,6 +8396,12 @@
Style);
   verifyFormat("vector a, b;", Style);
   verifyFormat("for (int *p, *q; p != q; p = p->next) {\n}", Style);
+  verifyFormat("/*comment*/ for (int *p, *q; p != q; p = p->next) {\n}", Style);
+  verifyFormat("if (int *p, *q; p != q) {\n  p = p->next;\n}", Style);
+  verifyFormat("/*comment*/ if (int *p, *q; p != q) {\n  p = p->next;\n}",
+   Style);
+  verifyFormat("switch (int *p, *q; p != q) {\n  default:\nbreak;\n}", Style);
+  verifyFormat("/*comment*/ switch (int *p, *q; p != q) {\n  default:\nbreak;\n}", Style);
 }
 
 TEST_F(FormatTest, ConditionalExpressionsInBrackets) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -26,6 +26,13 @@
 
 namespace {
 
+/// Returns \c true if the line starts with a token that can start a statement
+/// with an initializer.
+static bool startsWithInitStatement(const AnnotatedLine &Line) {
+  return Line.startsWith(tok::kw_for) || Line.startsWith(tok::kw_if) ||
+ Line.startsWith(tok::kw_switch);
+}
+
 /// Returns \c true if the token can be used as an identifier in
 /// an Objective-C \c \@selector, \c false otherwise.
 ///
@@ -1135,7 +1142,7 @@
   else if (Contexts.back().InInheritanceList)
 Tok->setType(TT_InheritanceComma);
   else if (Contexts.back().FirstStartOfName &&
-   (Contexts.size() == 1 || Line.startsWith(tok::kw_for))) {
+   (Contexts.size() == 1 || startsWithInitStatement(Line))) {
 Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = true;
 Line.IsMultiVariableDeclStmt = true;
   }
@@ -3090,7 +3097,7 @@
 FormatStyle::PAS_Left ||
 (Line.IsMultiVariableDeclStmt &&

[PATCH] D119648: [clang-format] Fix PointerAlignment within lambdas in a multi-variable declaration statement.

2022-02-13 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius updated this revision to Diff 408289.
curdeius marked an inline comment as done.
curdeius added a comment.

Rebased.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119648

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2031,6 +2031,10 @@
   verifyFormat("for (int x = 0; int &c : {1, 2, 3})", Style);
   verifyFormat("for (f(); auto &c : {1, 2, 3})", Style);
   verifyFormat("for (f(); int &c : {1, 2, 3})", Style);
+  verifyFormat(
+  "function res1 = [](int &a) { return 0; },\n"
+  " res2 = [](int &a) { return 0; };",
+  Style);
 
   Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
   verifyFormat("Const unsigned int *c;\n"
@@ -2068,6 +2072,10 @@
   verifyFormat("for (int x = 0; int& c : {1, 2, 3})", Style);
   verifyFormat("for (f(); auto& c : {1, 2, 3})", Style);
   verifyFormat("for (f(); int& c : {1, 2, 3})", Style);
+  verifyFormat(
+  "function res1 = [](int& a) { return 0; },\n"
+  "res2 = [](int& a) { return 0; };",
+  Style);
 
   Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
   verifyFormat("Const unsigned int* c;\n"
@@ -2121,6 +2129,10 @@
   verifyFormat("for (int x = 0; int & c : {1, 2, 3})", Style);
   verifyFormat("for (f(); auto & c : {1, 2, 3})", Style);
   verifyFormat("for (f(); int & c : {1, 2, 3})", Style);
+  verifyFormat(
+  "function res1 = [](int & a) { return 0; },\n"
+  " res2 = [](int & a) { return 0; };",
+  Style);
 
   Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
   verifyFormat("Const unsigned int*  c;\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3134,7 +3134,15 @@
   return false;
 if (getTokenPointerOrReferenceAlignment(Left) == FormatStyle::PAS_Right)
   return false;
-if (Line.IsMultiVariableDeclStmt)
+// FIXME: Setting IsMultiVariableDeclStmt for the whole line is 
error-prone,
+// because it does not take into account nested scopes like lambdas.
+// In multi-variable declaration statements, attach */& to the variable
+// independently of the style. However, avoid doing it if we are in a 
nested
+// scope, e.g. lambda. We still need to special-case statements with
+// initializers.
+if (Line.IsMultiVariableDeclStmt &&
+(Left.NestingLevel == Line.First->NestingLevel ||
+ startsWithInitStatement(Line)))
   return false;
 return Left.Previous && !Left.Previous->isOneOf(
 tok::l_paren, tok::coloncolon, tok::l_square);


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2031,6 +2031,10 @@
   verifyFormat("for (int x = 0; int &c : {1, 2, 3})", Style);
   verifyFormat("for (f(); auto &c : {1, 2, 3})", Style);
   verifyFormat("for (f(); int &c : {1, 2, 3})", Style);
+  verifyFormat(
+  "function res1 = [](int &a) { return 0; },\n"
+  " res2 = [](int &a) { return 0; };",
+  Style);
 
   Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
   verifyFormat("Const unsigned int *c;\n"
@@ -2068,6 +2072,10 @@
   verifyFormat("for (int x = 0; int& c : {1, 2, 3})", Style);
   verifyFormat("for (f(); auto& c : {1, 2, 3})", Style);
   verifyFormat("for (f(); int& c : {1, 2, 3})", Style);
+  verifyFormat(
+  "function res1 = [](int& a) { return 0; },\n"
+  "res2 = [](int& a) { return 0; };",
+  Style);
 
   Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
   verifyFormat("Const unsigned int* c;\n"
@@ -2121,6 +2129,10 @@
   verifyFormat("for (int x = 0; int & c : {1, 2, 3})", Style);
   verifyFormat("for (f(); auto & c : {1, 2, 3})", Style);
   verifyFormat("for (f(); int & c : {1, 2, 3})", Style);
+  verifyFormat(
+  "function res1 = [](int & a) { return 0; },\n"
+  " res2 = [](int & a) { return 0; };",
+  Style);
 
   Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
   verifyFormat("Const unsigned int*  c;\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3134,7 +3134,15 @@
   

[clang] 09559bc - Avoid a vulgarism. NFC.

2022-02-13 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-02-13T22:01:06+01:00
New Revision: 09559bc59a718e597725c7d9747350e9c649fd0e

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

LOG: Avoid a vulgarism. NFC.

Added: 


Modified: 
clang/unittests/Format/FormatTestComments.cpp

Removed: 




diff  --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 282bc46cd048..dcfd219484fa 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -3660,17 +3660,17 @@ TEST_F(FormatTestComments, SpaceAtLineCommentBegin) {
 format(WrapCode, Style));
 
   Style = getLLVMStyleWithColumns(20);
-  StringRef AShitloadOfSpaces = "//  This are more spaces "
-"than the ColumnLimit, what now?\n"
-"\n"
-"//   Comment\n"
-"\n"
-"// This is a text to split in multiple "
-"lines, please. Thank you very much!\n"
-"\n"
-"// A comment with\n"
-"//   some indentation that has to be split.\n"
-"// And now without";
+  StringRef LotsOfSpaces = "//  This are more spaces "
+   "than the ColumnLimit, what now?\n"
+   "\n"
+   "//   Comment\n"
+   "\n"
+   "// This is a text to split in multiple "
+   "lines, please. Thank you very much!\n"
+   "\n"
+   "// A comment with\n"
+   "//   some indentation that has to be split.\n"
+   "// And now without";
   EXPECT_EQ("//  This are more spaces "
 "than the ColumnLimit, what now?\n"
 "\n"
@@ -3688,7 +3688,7 @@ TEST_F(FormatTestComments, SpaceAtLineCommentBegin) {
 "//   that has to be\n"
 "//   split.\n"
 "// And now without",
-format(AShitloadOfSpaces, Style));
+format(LotsOfSpaces, Style));
 
   Style.SpacesInLineCommentPrefix = {0, 0};
   EXPECT_EQ("//This are more\n"
@@ -3709,7 +3709,7 @@ TEST_F(FormatTestComments, SpaceAtLineCommentBegin) {
 "//  that has to be\n"
 "//  split.\n"
 "//And now without",
-format(AShitloadOfSpaces, Style));
+format(LotsOfSpaces, Style));
 
   Style.SpacesInLineCommentPrefix = {3, 3};
   EXPECT_EQ("//   This are more\n"
@@ -3731,7 +3731,7 @@ TEST_F(FormatTestComments, SpaceAtLineCommentBegin) {
 "// that has to\n"
 "// be split.\n"
 "//   And now without",
-format(AShitloadOfSpaces, Style));
+format(LotsOfSpaces, Style));
 
   Style.SpacesInLineCommentPrefix = {30, -1u};
   EXPECT_EQ("//  This are more spaces than the "
@@ -3746,7 +3746,7 @@ TEST_F(FormatTestComments, SpaceAtLineCommentBegin) {
 "//some indentation that has to be 
"
 "split.\n"
 "//  And now without",
-format(AShitloadOfSpaces, Style));
+format(LotsOfSpaces, Style));
 
   Style.SpacesInLineCommentPrefix = {2, 4};
   EXPECT_EQ("//  A Comment to be\n"



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


[PATCH] D119601: [analyzer] Refactor makeNull to makeNullWithWidth

2022-02-13 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

I explored some test cases, and the rabbit hole gets deeper :)  Continuing to 
explore. Best


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119601

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


[PATCH] D119680: [clang-format] Fix SpacesInLineCommentPrefix deleting tokens.

2022-02-13 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius created this revision.
curdeius added reviewers: MyDeveloperDay, HazardyKnusperkeks, owenpan.
curdeius requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119680

Files:
  clang/lib/Format/BreakableToken.cpp
  clang/unittests/Format/FormatTestComments.cpp


Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -3645,6 +3645,11 @@
 "   // World\n"
 "}",
 format(WrapCode, Style));
+  EXPECT_EQ("// x\n"
+"// y",
+format("//   x\n"
+   "// y",
+   Style));
 
   Style.SpacesInLineCommentPrefix = {3, 3};
   EXPECT_EQ("//   Lorem ipsum\n"
Index: clang/lib/Format/BreakableToken.cpp
===
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -747,6 +747,7 @@
   assert(Tok.is(TT_LineComment) &&
  "line comment section must start with a line comment");
   FormatToken *LineTok = nullptr;
+  const int Minimum = Style.SpacesInLineCommentPrefix.Minimum;
   // How many spaces we changed in the first line of the section, this will be
   // applied in all following lines
   int FirstLineSpaceChange = 0;
@@ -769,7 +770,7 @@
   Lines[i] = Lines[i].ltrim(Blanks);
   StringRef IndentPrefix = getLineCommentIndentPrefix(Lines[i], Style);
   OriginalPrefix[i] = IndentPrefix;
-  const unsigned SpacesInPrefix = llvm::count(IndentPrefix, ' ');
+  const int SpacesInPrefix = llvm::count(IndentPrefix, ' ');
 
   // This lambda also considers multibyte character that is not handled in
   // functions like isPunctuation provided by CharInfo.
@@ -792,12 +793,11 @@
   // e.g. from "///" to "//".
   if (i == 0 || OriginalPrefix[i].rtrim(Blanks) !=
 OriginalPrefix[i - 1].rtrim(Blanks)) {
-if (SpacesInPrefix < Style.SpacesInLineCommentPrefix.Minimum &&
-Lines[i].size() > IndentPrefix.size() &&
+if (SpacesInPrefix < Minimum && Lines[i].size() > IndentPrefix.size() 
&&
 !NoSpaceBeforeFirstCommentChar()) {
-  FirstLineSpaceChange =
-  Style.SpacesInLineCommentPrefix.Minimum - SpacesInPrefix;
-} else if (SpacesInPrefix > Style.SpacesInLineCommentPrefix.Maximum) {
+  FirstLineSpaceChange = Minimum - SpacesInPrefix;
+} else if (static_cast(SpacesInPrefix) >
+   Style.SpacesInLineCommentPrefix.Maximum) {
   FirstLineSpaceChange =
   Style.SpacesInLineCommentPrefix.Maximum - SpacesInPrefix;
 } else {
@@ -808,10 +808,9 @@
   if (Lines[i].size() != IndentPrefix.size()) {
 PrefixSpaceChange[i] = FirstLineSpaceChange;
 
-if (SpacesInPrefix + PrefixSpaceChange[i] <
-Style.SpacesInLineCommentPrefix.Minimum) {
-  PrefixSpaceChange[i] += Style.SpacesInLineCommentPrefix.Minimum -
-  (SpacesInPrefix + PrefixSpaceChange[i]);
+if (SpacesInPrefix + PrefixSpaceChange[i] < Minimum) {
+  PrefixSpaceChange[i] +=
+  Minimum - (SpacesInPrefix + PrefixSpaceChange[i]);
 }
 
 assert(Lines[i].size() > IndentPrefix.size());


Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -3645,6 +3645,11 @@
 "   // World\n"
 "}",
 format(WrapCode, Style));
+  EXPECT_EQ("// x\n"
+"// y",
+format("//   x\n"
+   "// y",
+   Style));
 
   Style.SpacesInLineCommentPrefix = {3, 3};
   EXPECT_EQ("//   Lorem ipsum\n"
Index: clang/lib/Format/BreakableToken.cpp
===
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -747,6 +747,7 @@
   assert(Tok.is(TT_LineComment) &&
  "line comment section must start with a line comment");
   FormatToken *LineTok = nullptr;
+  const int Minimum = Style.SpacesInLineCommentPrefix.Minimum;
   // How many spaces we changed in the first line of the section, this will be
   // applied in all following lines
   int FirstLineSpaceChange = 0;
@@ -769,7 +770,7 @@
   Lines[i] = Lines[i].ltrim(Blanks);
   StringRef IndentPrefix = getLineCommentIndentPrefix(Lines[i], Style);
   OriginalPrefix[i] = IndentPrefix;
-  const unsigned SpacesInPrefix = llvm::count(IndentPrefix, ' ');
+  const int SpacesInPrefix = llvm::count(IndentPrefix, ' ');
 
 

[PATCH] D119680: [clang-format] Fix SpacesInLineCommentPrefix deleting tokens.

2022-02-13 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

I thought about using signed ints for Minimum and Maximum in the style, but 
then, we won't be able to use `-1` for Maximum the same way as now and signed 
int makes no sense for Minimum...




Comment at: clang/lib/Format/BreakableToken.cpp:799-800
+  FirstLineSpaceChange = Minimum - SpacesInPrefix;
+} else if (static_cast(SpacesInPrefix) >
+   Style.SpacesInLineCommentPrefix.Maximum) {
   FirstLineSpaceChange =

Not strictly necessary, but without the cast we have a signed/unsigned mismatch 
warning on comparison.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119680

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


[PATCH] D119655: [Driver][NetBSD] -r: imply -nostdlib like GCC

2022-02-13 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

I'm ambivalent about this change. To me, it falls into the category of "stop 
passing random ld options to the compiler driver".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119655

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


[PATCH] D119599: Add option to align compound assignments like `+=`

2022-02-13 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 408295.
sstwcw edited the summary of this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119599

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16392,6 +16392,157 @@
Alignment));
 }
 
+TEST_F(FormatTest, AlignCompoundAssignments) {
+  FormatStyle Alignment = getLLVMStyle();
+  Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
+  Alignment.AlignConsecutiveAssignmentsOptions.AlignCompound = true;
+  Alignment.AlignConsecutiveAssignmentsOptions.PadOperators = false;
+  verifyFormat("aa <= 5;\n"
+   "a   = 5;\n"
+   "bcd = 5;\n"
+   "ghtyf   = 5;\n"
+   "dvfvdb  = 5;\n"
+   "a   = 5;\n"
+   "vdsvsv  = 5;\n"
+   "sfdbddfbdfbb= 5;\n"
+   "dvsdsv  = 5;\n"
+   "int dsvvdvsdvvv = 123;",
+   Alignment);
+  verifyFormat("aa <= 5;\n"
+   "a  &= 5;\n"
+   "bcd*= 5;\n"
+   "ghtyf  += 5;\n"
+   "dvfvdb -= 5;\n"
+   "a  /= 5;\n"
+   "vdsvsv %= 5;\n"
+   "sfdbddfbdfbb   ^= 5;\n"
+   "dvsdsv |= 5;\n"
+   "int dsvvdvsdvvv = 123;",
+   Alignment);
+  verifyFormat("a  &= 5;\n"
+   "bcd*= 5;\n"
+   "ghtyf >>= 5;\n"
+   "dvfvdb -= 5;\n"
+   "a  /= 5;\n"
+   "aa <= 5;\n"
+   "vdsvsv %= 5;\n"
+   "sfdbddfbdfbb   ^= 5;\n"
+   "dvsdsv<<= 5;\n"
+   "int dsvvdvsdvvv = 123;",
+   Alignment);
+  Alignment.AlignConsecutiveAssignmentsOptions.PadOperators = true;
+  verifyFormat("aa <= 5;\n"
+   "a   = 5;\n"
+   "bcd = 5;\n"
+   "ghtyf   = 5;\n"
+   "dvfvdb  = 5;\n"
+   "a   = 5;\n"
+   "vdsvsv  = 5;\n"
+   "sfdbddfbdfbb= 5;\n"
+   "dvsdsv  = 5;\n"
+   "int dsvvdvsdvvv = 123;",
+   Alignment);
+  verifyFormat("aa <= 5;\n"
+   "a   &= 5;\n"
+   "bcd *= 5;\n"
+   "ghtyf   += 5;\n"
+   "dvfvdb  -= 5;\n"
+   "a   /= 5;\n"
+   "vdsvsv  %= 5;\n"
+   "sfdbddfbdfbb^= 5;\n"
+   "dvsdsv  |= 5;\n"
+   "int dsvvdvsdvvv  = 123;",
+   Alignment);
+  verifyFormat("a   &= 5;\n"
+   "bcd *= 5;\n"
+   "ghtyf  >>= 5;\n"
+   "dvfvdb  -= 5;\n"
+   "a   /= 5;\n"
+   "aa <= 5;\n"
+   "vdsvsv   %= 5;\n"
+   "sfdbddfbdfbb ^= 5;\n"
+   "dvsdsv  <<= 5;\n"
+   "int dsvvdvsdvvv   = 123;",
+   Alignment);
+  Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
+  EXPECT_EQ("int a   += 5;\n"
+"int one  = 1;\n"
+"\n"
+"int oneTwoThree = 123;\n",
+format("int a += 5;\n"
+   "int one = 1;\n"
+   "\n"
+   "int oneTwoThree = 123;\n",
+   Alignment));
+  EXPECT_EQ("int a   += 5;\n"
+"int one  = 1;\n"
+"//\n"
+"int oneTwoThree = 123;\n",
+format("int a += 5;\n"
+   "int one = 1;\n"
+   "//\n"
+   "int oneTwoThree = 123;\n",
+   Alignment));
+  Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_AcrossEmptyLines;
+  EXPECT_EQ("int a   += 5;\n"
+"int one  = 1;\n"
+"\n"
+"int oneTwoThree  = 123;\n",
+format("int a += 5;\n"
+   "int one = 1;\n"
+   "\n"
+   "int oneTwoThree = 123;\n",
+   Alignment));
+  EXPECT_EQ("int a   += 5;\n"
+"int one  = 1;\n"
+"//\n"
+"int oneTwoThree = 123;\n",
+format("int a += 5;\n"
+   "int one = 1;\n"
+   "//\n"
+   "int oneTwoThree = 123;\n",
+   Alignment));
+  Alignment.AlignConsecutiveAssignments = FormatStyle::A

[PATCH] D119625: Fix integer underflow bug when aligning code in clang-format

2022-02-13 Thread sstwcw via Phabricator via cfe-commits
sstwcw abandoned this revision.
sstwcw added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:16854
+  // that things still get aligned.
+  Alignment.ColumnLimit = 20;
   EXPECT_EQ("inta(int   x,\n"

HazardyKnusperkeks wrote:
> I disagree. Limit 0 and Limit != 0 behaves differently and you should not 
> remove the old test.
I hadn't noticed Limit != 0 behaves differently. Now I understand I don't need 
to change this test. I am going to close this diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119625

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


[PATCH] D119599: Add option to align compound assignments like `+=`

2022-02-13 Thread sstwcw via Phabricator via cfe-commits
sstwcw added inline comments.



Comment at: clang/include/clang/Format/Format.h:157
+  ///   a   &= 2;
+  ///   bbb  = 2;
+  ///

HazardyKnusperkeks wrote:
> sstwcw wrote:
> > HazardyKnusperkeks wrote:
> > > sstwcw wrote:
> > > > HazardyKnusperkeks wrote:
> > > > > curdeius wrote:
> > > > > > I guess it would be complicated to avoid adding an additional space 
> > > > > > here. I mean, it could be:
> > > > > > ```
> > > > > > a  &= 2;
> > > > > > bbb = 2;
> > > > > > ```
> > > > > > And with 3-char operators, there's one more space.
> > > > > That would be awesome, but it should be an option to turn off or on.
> > > > > But I think this would really be complicated.
> > > > I can do it either way. But I thought without the extra space the 
> > > > formatted code looked ugly, especially when mixing `>>=` and `=`.  
> > > > Which way do you prefer?
> > > > 
> > > > 
> > > > ```
> > > > a >>= 2;
> > > > bbb = 2;
> > > > ```
> > > I would prefer an option, to be able to do both.
> > > I think I would use the variant which is more compact, but can't say for 
> > > sure until I really have the option and tried it.
> > You mean like a new entry under `AlignConsecutiveStyle` with the options to 
> > align the left ends of the operators and to align the equal sign with and 
> > without padding them to the same length? I don't want the new option to be 
> > merged with `AlignCompound`, because we are working on adding support for a 
> > language that uses both `=` and `<=` for regular assignments, and maybe 
> > someone will want to support a language that has both `=` and `:=` in the 
> > future.
> Yeah. Basing on @MyDeveloperDay 's suggestion:
> ```
> struct AlignConsecutiveStyle {
>   bool Enabled;
>   bool AcrossComments;
>   bool AcrossEmptyLines;
>   bool AlignCompound;
>   bool CompactWhitespace; // This is just a suggestion, I'm open for better 
> names.
> };
> ```
I added the new option. Moving the old options into the struct turned out to be 
too much work for me on a weekend. If you can accept the configuration style in 
the current revision, I will probably move the old options into the struct at 
some later date. By the way, what is the purpose of `FormatStyle::operator==`? 
It looks like it does not compare`BraceWrapping`.



Comment at: clang/unittests/Format/FormatTest.cpp:16852
-  // otherwise the function parameters will be re-flowed onto a single line.
-  Alignment.ColumnLimit = 0;
   EXPECT_EQ("inta(int   x,\n"

sstwcw wrote:
> MyDeveloperDay wrote:
> > Huge `no` from me, don't change the tests because they break based on your 
> > change.
> Here is the problem in isolation: https://reviews.llvm.org/D119625.  What do 
> you suggest about this test?
I hadn't noticed that column limit = 0 meant no limit. This test doesn't really 
need to change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119599

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


[PATCH] D119599: Add option to align compound assignments like `+=`

2022-02-13 Thread sstwcw via Phabricator via cfe-commits
sstwcw marked 5 inline comments as done.
sstwcw added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:16872
+  // that things still get aligned.
+  Alignment.ColumnLimit = 20;
   EXPECT_EQ("inta(int   x,\n"

sstwcw wrote:
> curdeius wrote:
> > Is it something that can be done/fixed separately?
> I added a revision here https://reviews.llvm.org/D119625.  If you commit it 
> separately there will be a merge conflict though.
I hadn't noticed that column limit = 0 meant no limit. This test doesn't really 
need to change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119599

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


[PATCH] D119682: [clang-format][docs] Fix incorrect 'clang-format 13' configuration options markers

2022-02-13 Thread Krystian Kuzniarek via Phabricator via cfe-commits
kuzkry created this revision.
kuzkry added a reviewer: MyDeveloperDay.
kuzkry requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Note: Option 'IndentRequiresClause' was previously known as
'IndentRequires' but the version marker should still indicate
'clang-format 15' as this option most recent name wasn't accessible
earlier and it would produce:
error: unknown key 'IndentRequiresClause'


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119682

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1791,7 +1791,7 @@
   };
 
   /// The concept declaration style to use.
-  /// \version 13
+  /// \version 12
   BreakBeforeConceptDeclarationsStyle BreakBeforeConceptDeclarations;
 
   /// If ``true``, ternary operators will be placed after line breaks.
@@ -2185,7 +2185,7 @@
   };
 
   /// Defines in which cases to put empty line before access modifiers.
-  /// \version 13
+  /// \version 12
   EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier;
 
   /// If ``true``, clang-format detects whether function calls and
@@ -2538,7 +2538,7 @@
   ///  //
   ///}
   /// \endcode
-  /// \version 13
+  /// \version 15
   bool IndentRequiresClause;
 
   /// The number of columns to use for indentation.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1988,7 +1988,7 @@
 
 
 
-**BreakBeforeConceptDeclarations** (``BreakBeforeConceptDeclarationsStyle``) 
:versionbadge:`clang-format 13`
+**BreakBeforeConceptDeclarations** (``BreakBeforeConceptDeclarationsStyle``) 
:versionbadge:`clang-format 12`
   The concept declaration style to use.
 
   Possible values:
@@ -2278,7 +2278,7 @@
 
 
 
-**EmptyLineBeforeAccessModifier** (``EmptyLineBeforeAccessModifierStyle``) 
:versionbadge:`clang-format 13`
+**EmptyLineBeforeAccessModifier** (``EmptyLineBeforeAccessModifierStyle``) 
:versionbadge:`clang-format 12`
   Defines in which cases to put empty line before access modifiers.
 
   Possible values:
@@ -2706,7 +2706,7 @@
 
 
 
-**IndentRequiresClause** (``Boolean``) :versionbadge:`clang-format 13`
+**IndentRequiresClause** (``Boolean``) :versionbadge:`clang-format 15`
   Indent the requires clause in a template. This only applies when
   ``RequiresClausePosition`` is ``OwnLine``, or ``WithFollowing``.
 


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1791,7 +1791,7 @@
   };
 
   /// The concept declaration style to use.
-  /// \version 13
+  /// \version 12
   BreakBeforeConceptDeclarationsStyle BreakBeforeConceptDeclarations;
 
   /// If ``true``, ternary operators will be placed after line breaks.
@@ -2185,7 +2185,7 @@
   };
 
   /// Defines in which cases to put empty line before access modifiers.
-  /// \version 13
+  /// \version 12
   EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier;
 
   /// If ``true``, clang-format detects whether function calls and
@@ -2538,7 +2538,7 @@
   ///  //
   ///}
   /// \endcode
-  /// \version 13
+  /// \version 15
   bool IndentRequiresClause;
 
   /// The number of columns to use for indentation.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1988,7 +1988,7 @@
 
 
 
-**BreakBeforeConceptDeclarations** (``BreakBeforeConceptDeclarationsStyle``) :versionbadge:`clang-format 13`
+**BreakBeforeConceptDeclarations** (``BreakBeforeConceptDeclarationsStyle``) :versionbadge:`clang-format 12`
   The concept declaration style to use.
 
   Possible values:
@@ -2278,7 +2278,7 @@
 
 
 
-**EmptyLineBeforeAccessModifier** (``EmptyLineBeforeAccessModifierStyle``) :versionbadge:`clang-format 13`
+**EmptyLineBeforeAccessModifier** (``EmptyLineBeforeAccessModifierStyle``) :versionbadge:`clang-format 12`
   Defines in which cases to put empty line before access modifiers.
 
   Possible values:
@@ -2706,7 +2706,7 @@
 
 
 
-**IndentRequiresClause** (``Boolean``) :versionbadge:`clang-format 13`
+**IndentRequiresClause** (``Boolean``) :versionbadge:`clang-format 15`
   Indent the requires clause in a template. This only applies when
   ``RequiresClausePosition`` is ``OwnLine``, or ``WithFollowing``.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119541: [RISCV] Fix RISCVTargetInfo::initFeatureMap, add non-ISA features back after implication

2022-02-13 Thread JunMa via Phabricator via cfe-commits
junparser accepted this revision.
junparser added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for the fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119541

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


[PATCH] D112774: [RISCV] Support k-ext clang intrinsics

2022-02-13 Thread Shao-Ce SUN via Phabricator via cfe-commits
achieveartificialintelligence updated this revision to Diff 408310.
achieveartificialintelligence added a comment.

Ping & Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112774

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkx.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkx.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zksh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zksh.c
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c

Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -31,6 +31,17 @@
 // CHECK-NOT: __riscv_zfh
 // CHECK-NOT: __riscv_v
 // CHECK-NOT: __riscv_vector
+// CHECK-NOT: __riscv_zbkc
+// CHECK-NOT: __riscv_zbkx
+// CHECK-NOT: __riscv_zbkb
+// CHECK-NOT: __riscv_zkne
+// CHECK-NOT: __riscv_zknd
+// CHECK-NOT: __riscv_zknh
+// CHECK-NOT: __riscv_zksh
+// CHECK-NOT: __riscv_zksed
+// CHECK-NOT: __riscv_zkr
+// CHECK-NOT: __riscv_zkt
+// CHECK-NOT: __riscv_zk
 
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32im -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-M-EXT %s
@@ -343,3 +354,58 @@
 // CHECK-ZVE32X-EXT: __riscv_v_min_vlen 32
 // CHECK-ZVE32X-EXT: __riscv_vector 1
 // CHECK-ZVE32X-EXT: __riscv_zve32x 100{{$}}
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkc1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKC-EXT %s
+// CHECK-ZBKC-EXT: __riscv_zbkc
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkx1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKX-EXT %s
+// CHECK-ZBKX-EXT: __riscv_zbkx
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkb1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKB-EXT %s
+// CHECK-ZBKB-EXT: __riscv_zbkb
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izknd1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKND-EXT %s
+// CHECK-ZKND-EXT: __riscv_zknd
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkne1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKNE-EXT %s
+// CHECK-ZKNE-EXT: __riscv_zkne
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izknh1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKNH-EXT %s
+// CHECK-ZKNH-EXT: __riscv_zknh
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izksh1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKSH-EXT %s
+// CHECK-ZKSH-EXT: __riscv_zksh
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izksed1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKSED-EXT %s
+// CHECK-ZKSED-EXT: __riscv_zksed
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkr1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKR-EXT %s
+// CHECK-ZKR-EXT: __riscv_zkr
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkt1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKT-EXT %s
+// CHECK-ZKT-EXT: __riscv_zkt
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izk1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZK-EXT %s
+// CHECK-ZK-EXT: __riscv_zk
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -414,3 +414,47 @@
 // RUN: %clang -target riscv32-unknown-elf -march=rv32iv1p0_zvl32b1p0 -### %s -c 2>&1 | \
 // RUN:   FileCheck -check-prefix=RV32-ZVL-GOODVERS %s
 // RV32-ZVL-GOODVERS: "-target-feature" "+zvl32b"
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbkc1p0 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZBKC %s
+// RV32-ZBKC: 

[PATCH] D119409: [C++20] [Modules] Remain variable's definition in module interface

2022-02-13 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 408315.
ChuanqiXu added a comment.

Update test about inline variable in module


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

https://reviews.llvm.org/D119409

Files:
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
  clang/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp
  clang/test/CodeGenCXX/inline-variable-in-module.cpp
  clang/test/CodeGenCXX/static-variable-in-module.cpp

Index: clang/test/CodeGenCXX/static-variable-in-module.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/static-variable-in-module.cpp
@@ -0,0 +1,24 @@
+// RUN: rm -fr %t
+// RUN: mkdir %t
+// RUN: echo "struct S { S(); };" >> %t/foo.h
+// RUN: echo "static S s = S();" >> %t/foo.h
+// RUN: %clang_cc1 -std=c++20 -I%t %s -triple %itanium_abi_triple -S -emit-llvm -o - | FileCheck %s
+module;
+#include "foo.h"
+export module m;
+class A {
+public:
+  A();
+};
+static A a = A();
+
+// CHECK: @_ZL1s = internal global %struct.S zeroinitializer
+// CHECK: @_ZW1mE1a = {{(dso_local )?}}global %class.A zeroinitializer
+// CHECK: @llvm.global_ctors = appending global{{.*}}@_GLOBAL__sub_I_static_variable_in_module.cpp
+// CHECK: define {{.*}}__cxx_global_var_init[[SUFFIX:[^)]*]]
+// CHECK: call void @_ZN1SC1Ev
+// CHECK: define {{.*}}__cxx_global_var_init[[SUFFIX2:[^)]*]]
+// CHECK: call void @_ZW1mEN1AC1Ev
+// CHECK: define {{.*}}@_GLOBAL__sub_I_static_variable_in_module.cpp
+// CHECK: call void @__cxx_global_var_init[[SUFFIX]]
+// CHECK: call void @__cxx_global_var_init[[SUFFIX2]]
Index: clang/test/CodeGenCXX/inline-variable-in-module.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/inline-variable-in-module.cpp
@@ -0,0 +1,16 @@
+// RUN: rm -fr %t
+// RUN: mkdir %t
+// RUN: echo "struct S { S(); };" >> %t/foo.h
+// RUN: echo "inline S s = S();" >> %t/foo.h
+// RUN: %clang_cc1 -std=c++20 -I%t %s -triple %itanium_abi_triple -S -emit-llvm -o - | FileCheck %s
+module;
+#include "foo.h"
+export module m;
+class A {
+public:
+  A();
+};
+inline A a = A();
+
+// CHECK: @s = linkonce_odr global %struct.S zeroinitializer
+// CHECK: @_ZW1mE1a = linkonce_odr global %class.A zeroinitializer
Index: clang/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp
===
--- clang/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp
+++ clang/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 -fmodules-ts %s -triple %itanium_abi_triple -fmodule-file=%t -emit-llvm -o - | FileCheck %s --implicit-check-not=unused --implicit-check-not=global_module
 
 // CHECK-DAG: @extern_var_exported = external {{(dso_local )?}}global
-// CHECK-DAG: @inline_var_exported = linkonce_odr {{(dso_local )?}}global
+// CHECK-DAG: @inline_var_exported = available_externally {{(dso_local )?}}global
 // CHECK-DAG: @const_var_exported = available_externally {{(dso_local )?}}constant i32 3
 
 import Module;
Index: clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
===
--- clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
+++ clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
@@ -2,11 +2,11 @@
 // RUN: %clang_cc1 -fmodules-ts %s -triple %itanium_abi_triple -fmodule-file=%t -emit-llvm -o - | FileCheck %s --implicit-check-not=unused --implicit-check-not=global_module
 
 // CHECK-DAG: @extern_var_exported = external {{(dso_local )?}}global
-// CHECK-DAG: @inline_var_exported = linkonce_odr {{(dso_local )?}}global
+// CHECK-DAG: @inline_var_exported = available_externally {{(dso_local )?}}global
 // CHECK-DAG: @const_var_exported = available_externally {{(dso_local )?}}constant i32 3,
 //
 // CHECK-DAG: @_ZW6ModuleE25extern_var_module_linkage = external {{(dso_local )?}}global
-// CHECK-DAG: @_ZW6ModuleE25inline_var_module_linkage = linkonce_odr {{(dso_local )?}}global
+// CHECK-DAG: @_ZW6ModuleE25inline_var_module_linkage = available_externally {{(dso_local )?}}global
 // CHECK-DAG: @_ZW6ModuleE25static_var_module_linkage = available_externally {{(dso_local )?}}global i32 0,
 // CHECK-DAG: @_ZW6ModuleE24const_var_module_linkage = available_externally {{(dso_local )?}}constant i32 3,
 
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1022,15 +1022,18 @@
 if (Writer.WritingModule &&
 !D->getDescribedVarTemplate() && !D->getMemberSpecializationInfo() &&
 !isa(D)) {
-  // When building a C++ Modules TS module interface unit, a strong
-  // definition in the module interface is provided by the compilation of
-  // that module interface unit, not by its users. (Inline variables are
-

[PATCH] D112774: [RISCV] Support k-ext clang intrinsics

2022-02-13 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsRISCV.def:80
+// Zknd extension
+TARGET_BUILTIN(__builtin_riscv_aes32dsi, "ZiZiZiUc", "nc", "zknd")
+TARGET_BUILTIN(__builtin_riscv_aes32dsmi, "ZiZiZiUc", "nc", "zknd")

Uc -> IUc

The I will make the frontend only accept constant arguments.



Comment at: clang/include/clang/Basic/BuiltinsRISCV.def:87
+// Zknd & zkne
+TARGET_BUILTIN(__builtin_riscv_aes64ks1i, "WiWiUi", "nc", "zknd|zkne,64bit")
+TARGET_BUILTIN(__builtin_riscv_aes64ks2, "WiWiWi", "nc", "zknd|zkne,64bit")

Ui -> IUi



Comment at: clang/include/clang/Basic/BuiltinsRISCV.def:91
+// Zkne extension
+TARGET_BUILTIN(__builtin_riscv_aes32esi, "ZiZiZiUc", "nc", "zkne")
+TARGET_BUILTIN(__builtin_riscv_aes32esmi, "ZiZiZiUc", "nc", "zkne")

Uc -> IUc



Comment at: clang/include/clang/Basic/BuiltinsRISCV.def:114
+// Zksed extension
+TARGET_BUILTIN(__builtin_riscv_sm4ed, "LiLiLiUc", "nc", "zksed")
+TARGET_BUILTIN(__builtin_riscv_sm4ks, "LiLiLiUc", "nc", "zksed")

Uc -> IUc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112774

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


[PATCH] D119409: [C++20] [Modules] Remain variable's definition in module interface

2022-02-13 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 408317.
ChuanqiXu added a comment.

Handle named module explicitly for better readability.


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

https://reviews.llvm.org/D119409

Files:
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
  clang/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp
  clang/test/CodeGenCXX/inline-variable-in-module.cpp
  clang/test/CodeGenCXX/static-variable-in-module.cpp
  clang/test/CodeGenCXX/use-inline-variable-in-module.cpp

Index: clang/test/CodeGenCXX/use-inline-variable-in-module.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/use-inline-variable-in-module.cpp
@@ -0,0 +1,11 @@
+// RUN: rm -fr %t
+// RUN: mkdir %t
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \
+// RUN:  -emit-module-interface %S/inline-variable-in-module.cpp -o %t/m.pcm
+// RUN: %clang_cc1 -std=c++20 -I%t %s -fprebuilt-module-path=%t \
+// RUN: -triple %itanium_abi_triple -S -emit-llvm -o - | FileCheck %s
+import m;
+void use() {
+  (void)&a;
+}
+// CHECK: @a = available_externally global %class.A zeroinitializer
Index: clang/test/CodeGenCXX/static-variable-in-module.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/static-variable-in-module.cpp
@@ -0,0 +1,24 @@
+// RUN: rm -fr %t
+// RUN: mkdir %t
+// RUN: echo "struct S { S(); };" >> %t/foo.h
+// RUN: echo "static S s = S();" >> %t/foo.h
+// RUN: %clang_cc1 -std=c++20 -I%t %s -triple %itanium_abi_triple -S -emit-llvm -o - | FileCheck %s
+module;
+#include "foo.h"
+export module m;
+class A {
+public:
+  A();
+};
+static A a = A();
+
+// CHECK: @_ZL1s = internal global %struct.S zeroinitializer
+// CHECK: @_ZW1mE1a = {{(dso_local )?}}global %class.A zeroinitializer
+// CHECK: @llvm.global_ctors = appending global{{.*}}@_GLOBAL__sub_I_static_variable_in_module.cpp
+// CHECK: define {{.*}}__cxx_global_var_init[[SUFFIX:[^)]*]]
+// CHECK: call void @_ZN1SC1Ev
+// CHECK: define {{.*}}__cxx_global_var_init[[SUFFIX2:[^)]*]]
+// CHECK: call void @_ZW1mEN1AC1Ev
+// CHECK: define {{.*}}@_GLOBAL__sub_I_static_variable_in_module.cpp
+// CHECK: call void @__cxx_global_var_init[[SUFFIX]]
+// CHECK: call void @__cxx_global_var_init[[SUFFIX2]]
Index: clang/test/CodeGenCXX/inline-variable-in-module.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/inline-variable-in-module.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -fr %t
+// RUN: mkdir %t
+// RUN: %clang_cc1 -std=c++20 -I%t %s -triple %itanium_abi_triple -S -emit-llvm -o - | FileCheck %s
+module;
+# 3 __FILE__ 1
+struct S {
+  S();
+};
+inline S s = S();
+# 6 "" 2
+export module m;
+class A {
+public:
+  A();
+};
+export inline A a = A();
+
+// CHECK: @s = linkonce_odr global %struct.S zeroinitializer
+// CHECK: @a = linkonce_odr global %class.A zeroinitializer
Index: clang/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp
===
--- clang/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp
+++ clang/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 -fmodules-ts %s -triple %itanium_abi_triple -fmodule-file=%t -emit-llvm -o - | FileCheck %s --implicit-check-not=unused --implicit-check-not=global_module
 
 // CHECK-DAG: @extern_var_exported = external {{(dso_local )?}}global
-// CHECK-DAG: @inline_var_exported = linkonce_odr {{(dso_local )?}}global
+// CHECK-DAG: @inline_var_exported = available_externally {{(dso_local )?}}global
 // CHECK-DAG: @const_var_exported = available_externally {{(dso_local )?}}constant i32 3
 
 import Module;
Index: clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
===
--- clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
+++ clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
@@ -2,11 +2,11 @@
 // RUN: %clang_cc1 -fmodules-ts %s -triple %itanium_abi_triple -fmodule-file=%t -emit-llvm -o - | FileCheck %s --implicit-check-not=unused --implicit-check-not=global_module
 
 // CHECK-DAG: @extern_var_exported = external {{(dso_local )?}}global
-// CHECK-DAG: @inline_var_exported = linkonce_odr {{(dso_local )?}}global
+// CHECK-DAG: @inline_var_exported = available_externally {{(dso_local )?}}global
 // CHECK-DAG: @const_var_exported = available_externally {{(dso_local )?}}constant i32 3,
 //
 // CHECK-DAG: @_ZW6ModuleE25extern_var_module_linkage = external {{(dso_local )?}}global
-// CHECK-DAG: @_ZW6ModuleE25inline_var_module_linkage = linkonce_odr {{(dso_local )?}}global
+// CHECK-DAG: @_ZW6ModuleE25inline_var_module_linkage = available_externally {{(dso_local )?}}global
 // CHECK-DAG: @_ZW6ModuleE25static_var_module_linkage = available_externally {{(dso_local )?}}global i32 0,
 // CHECK-DAG: @_ZW6ModuleE

[PATCH] D119686: [RISCV] Add the passthru operand for vadc/vsbc/vmerge/vfmerge IR intrinsics.

2022-02-13 Thread Zakk Chen via Phabricator via cfe-commits
khchen created this revision.
khchen added reviewers: craig.topper, rogfer01, frasercrmck, kito-cheng, 
arcbbb, monkchiang, eopXD.
Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, 
vkmr, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, 
psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, edward-jones, zzheng, 
jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
khchen requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, MaskRay.
Herald added projects: clang, LLVM.

The goal is support tail and mask policy in RVV builtins.
We focus on IR part first.
If the passthru operand is undef, we use tail agnostic, otherwise
use tail undisturbed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119686

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vadc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmerge.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmerge.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vsbc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vadc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfmerge.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmerge.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vsbc.c
  llvm/include/llvm/IR/IntrinsicsRISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
  llvm/test/CodeGen/RISCV/rvv/unmasked-tu.ll
  llvm/test/CodeGen/RISCV/rvv/vadc-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vadc-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vfmerge.ll
  llvm/test/CodeGen/RISCV/rvv/vmerge-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmerge-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vsbc-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vsbc-rv64.ll

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


[PATCH] D119409: [C++20] [Modules] Remain variable's definition in module interface

2022-02-13 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp:5
 // CHECK-DAG: @extern_var_exported = external {{(dso_local )?}}global
-// CHECK-DAG: @inline_var_exported = linkonce_odr {{(dso_local )?}}global
+// CHECK-DAG: @inline_var_exported = available_externally {{(dso_local 
)?}}global
 // CHECK-DAG: @const_var_exported = available_externally {{(dso_local 
)?}}constant i32 3,

urnathan wrote:
> I don;t think this is correct.  That should still be a linkonce odr, 
> otherwise you'll get conflicts with other module implementation units.
It is still linkonce_odr in the module it get defined. See the new added test 
case: inline-variable-in-module.cpp for example. The attribute 
`available_externally` is equivalent to external from the perspective of 
linker. See https://llvm.org/docs/LangRef.html#linkage-types. According to 
[dcl.inline]p7, inline variable attached to named module should be defined in 
that domain. Note that the variable attached to global module fragment and 
private module fragment shouldn't be accessed outside the module, so it implies 
that all the variable defined in the module could only be defined in the module 
unit itself.



Comment at: clang/test/CodeGenCXX/static-variable-in-module.cpp:2-8
+// RUN: mkdir %t
+// RUN: echo "struct S { S(); };" >> %t/foo.h
+// RUN: echo "static S s = S();" >> %t/foo.h
+// RUN: %clang -std=c++20 -I%t %s -S -emit-llvm -o - | FileCheck %s
+module;
+#include "foo.h"
+export module m;

urnathan wrote:
> rather than generate a foo.h file, why not (ab)use the preprocessor with 
> internal line directives?
> 
> ```
> module;
> # 3 __FILE__ 1 // use the next physical line number here (and below)
> struct S { S(); };
> static S s = S();
> # 6 "" 2
> export module m;
> ...
> ```
Yeah, the form is useful when we need to add expected-* diagnostic message to 
GMF. But I feel it is a little bit hacker. I guess the form mimics looks like 
user more wouldn't be worse personally.


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

https://reviews.llvm.org/D119409

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


[PATCH] D112774: [RISCV] Support k-ext clang intrinsics

2022-02-13 Thread Shao-Ce SUN via Phabricator via cfe-commits
achieveartificialintelligence updated this revision to Diff 408319.
achieveartificialintelligence marked 4 inline comments as done.
achieveartificialintelligence added a comment.

Address @craig.topper's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112774

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkx.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkx.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zksh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zksh.c
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c

Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -31,6 +31,17 @@
 // CHECK-NOT: __riscv_zfh
 // CHECK-NOT: __riscv_v
 // CHECK-NOT: __riscv_vector
+// CHECK-NOT: __riscv_zbkc
+// CHECK-NOT: __riscv_zbkx
+// CHECK-NOT: __riscv_zbkb
+// CHECK-NOT: __riscv_zkne
+// CHECK-NOT: __riscv_zknd
+// CHECK-NOT: __riscv_zknh
+// CHECK-NOT: __riscv_zksh
+// CHECK-NOT: __riscv_zksed
+// CHECK-NOT: __riscv_zkr
+// CHECK-NOT: __riscv_zkt
+// CHECK-NOT: __riscv_zk
 
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32im -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-M-EXT %s
@@ -343,3 +354,58 @@
 // CHECK-ZVE32X-EXT: __riscv_v_min_vlen 32
 // CHECK-ZVE32X-EXT: __riscv_vector 1
 // CHECK-ZVE32X-EXT: __riscv_zve32x 100{{$}}
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkc1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKC-EXT %s
+// CHECK-ZBKC-EXT: __riscv_zbkc
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkx1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKX-EXT %s
+// CHECK-ZBKX-EXT: __riscv_zbkx
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkb1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKB-EXT %s
+// CHECK-ZBKB-EXT: __riscv_zbkb
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izknd1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKND-EXT %s
+// CHECK-ZKND-EXT: __riscv_zknd
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkne1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKNE-EXT %s
+// CHECK-ZKNE-EXT: __riscv_zkne
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izknh1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKNH-EXT %s
+// CHECK-ZKNH-EXT: __riscv_zknh
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izksh1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKSH-EXT %s
+// CHECK-ZKSH-EXT: __riscv_zksh
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izksed1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKSED-EXT %s
+// CHECK-ZKSED-EXT: __riscv_zksed
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkr1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKR-EXT %s
+// CHECK-ZKR-EXT: __riscv_zkr
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkt1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKT-EXT %s
+// CHECK-ZKT-EXT: __riscv_zkt
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izk1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZK-EXT %s
+// CHECK-ZK-EXT: __riscv_zk
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -414,3 +414,47 @@
 // RUN: %clang -target riscv32-unknown-elf -march=rv32iv1p0_zvl32b1p0 -### %s -c 2>&1 | \
 // RUN:   FileCheck -check-prefix=RV32-ZVL-GOODVERS %s
 // RV32-ZVL-GOODVERS: "-target-feature" "+zvl32b"
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbkc1p0 -### %s \

[clang] 7f51a9e - [RISCV] Fix RISCVTargetInfo::initFeatureMap, add non-ISA features back after implication

2022-02-13 Thread via cfe-commits

Author: eopXD
Date: 2022-02-13T21:05:06-08:00
New Revision: 7f51a9e2730e32eec45ff2e91b3d7bae897893e4

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

LOG: [RISCV] Fix RISCVTargetInfo::initFeatureMap, add non-ISA features back 
after implication

Previously D113336 makes RISCVTargetInfo::initFeatureMap return the results
processed by RISCVISAInfo, which only consists of ISA features and misses
non-ISA features like `relax` and `save-restore`.

This patch fixes the problem.

Reviewed By: junparser

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

Added: 
clang/test/Driver/riscv-default-features.c

Modified: 
clang/lib/Basic/Targets/RISCV.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index ca72cf200d466..fd30551eb4e0d 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -232,8 +232,16 @@ bool RISCVTargetInfo::initFeatureMap(
 return false;
   }
 
-  return TargetInfo::initFeatureMap(Features, Diags, CPU,
-(*ParseResult)->toFeatureVector());
+  // RISCVISAInfo makes implications for ISA features
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  // Add non-ISA features like `relax` and `save-restore` back
+  for (std::string Feature : FeaturesVec) {
+if (std::find(begin(ImpliedFeatures), end(ImpliedFeatures), Feature) ==
+end(ImpliedFeatures))
+  ImpliedFeatures.push_back(Feature);
+  }
+
+  return TargetInfo::initFeatureMap(Features, Diags, CPU, ImpliedFeatures);
 }
 
 /// Return true if has this feature, need to sync with handleTargetFeatures.

diff  --git a/clang/test/Driver/riscv-default-features.c 
b/clang/test/Driver/riscv-default-features.c
new file mode 100644
index 0..07b0778cd9938
--- /dev/null
+++ b/clang/test/Driver/riscv-default-features.c
@@ -0,0 +1,9 @@
+// RUN: %clang -target riscv32-unknown-elf -S -emit-llvm %s -o - | FileCheck 
%s -check-prefix=RV32
+
+// RV32: "target-features"="+a,+c,+m,+relax,-save-restore"
+// RV64: "target-features"="+64bit,+a,+c,+m,+relax,-save-restore"
+
+// Dummy function
+int foo(){
+  return  3;
+}



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


[PATCH] D119541: [RISCV] Fix RISCVTargetInfo::initFeatureMap, add non-ISA features back after implication

2022-02-13 Thread Yueh-Ting Chen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7f51a9e2730e: [RISCV] Fix RISCVTargetInfo::initFeatureMap, 
add non-ISA features back after… (authored by eopXD).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119541

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-default-features.c


Index: clang/test/Driver/riscv-default-features.c
===
--- /dev/null
+++ clang/test/Driver/riscv-default-features.c
@@ -0,0 +1,9 @@
+// RUN: %clang -target riscv32-unknown-elf -S -emit-llvm %s -o - | FileCheck 
%s -check-prefix=RV32
+
+// RV32: "target-features"="+a,+c,+m,+relax,-save-restore"
+// RV64: "target-features"="+64bit,+a,+c,+m,+relax,-save-restore"
+
+// Dummy function
+int foo(){
+  return  3;
+}
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -232,8 +232,16 @@
 return false;
   }
 
-  return TargetInfo::initFeatureMap(Features, Diags, CPU,
-(*ParseResult)->toFeatureVector());
+  // RISCVISAInfo makes implications for ISA features
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  // Add non-ISA features like `relax` and `save-restore` back
+  for (std::string Feature : FeaturesVec) {
+if (std::find(begin(ImpliedFeatures), end(ImpliedFeatures), Feature) ==
+end(ImpliedFeatures))
+  ImpliedFeatures.push_back(Feature);
+  }
+
+  return TargetInfo::initFeatureMap(Features, Diags, CPU, ImpliedFeatures);
 }
 
 /// Return true if has this feature, need to sync with handleTargetFeatures.


Index: clang/test/Driver/riscv-default-features.c
===
--- /dev/null
+++ clang/test/Driver/riscv-default-features.c
@@ -0,0 +1,9 @@
+// RUN: %clang -target riscv32-unknown-elf -S -emit-llvm %s -o - | FileCheck %s -check-prefix=RV32
+
+// RV32: "target-features"="+a,+c,+m,+relax,-save-restore"
+// RV64: "target-features"="+64bit,+a,+c,+m,+relax,-save-restore"
+
+// Dummy function
+int foo(){
+  return  3;
+}
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -232,8 +232,16 @@
 return false;
   }
 
-  return TargetInfo::initFeatureMap(Features, Diags, CPU,
-(*ParseResult)->toFeatureVector());
+  // RISCVISAInfo makes implications for ISA features
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  // Add non-ISA features like `relax` and `save-restore` back
+  for (std::string Feature : FeaturesVec) {
+if (std::find(begin(ImpliedFeatures), end(ImpliedFeatures), Feature) ==
+end(ImpliedFeatures))
+  ImpliedFeatures.push_back(Feature);
+  }
+
+  return TargetInfo::initFeatureMap(Features, Diags, CPU, ImpliedFeatures);
 }
 
 /// Return true if has this feature, need to sync with handleTargetFeatures.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3e19ba3 - [X86][MS] Add 80bit long double support for Windows

2022-02-13 Thread Phoebe Wang via cfe-commits

Author: Phoebe Wang
Date: 2022-02-14T13:32:29+08:00
New Revision: 3e19ba36fca9fa0b6aba0de2767f26dfd463cb5a

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

LOG: [X86][MS] Add 80bit long double support for Windows

MSVC currently doesn't support 80 bits long double. But ICC does support
it on Windows. Besides, there're also some users asked for this feature.
We can find the discussions from stackoverflow, msdn etc.

Given Clang has already support `-mlong-double-80`, extending it to
support for Windows seems worthwhile.

Reviewed By: rnk, erichkeane

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

Added: 
clang/test/CodeGen/X86/long-double-config-size.c

Modified: 
clang/lib/Basic/TargetInfo.cpp
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index e3a2f30febe75..801961dc3b56a 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -449,6 +449,20 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, 
LangOptions &Opts) {
 } else if (Opts.LongDoubleSize == 128) {
   LongDoubleWidth = LongDoubleAlign = 128;
   LongDoubleFormat = &llvm::APFloat::IEEEquad();
+} else if (Opts.LongDoubleSize == 80) {
+  LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
+  if (getTriple().isWindowsMSVCEnvironment()) {
+LongDoubleWidth = 128;
+LongDoubleAlign = 128;
+  } else { // Linux
+if (getTriple().getArch() == llvm::Triple::x86) {
+  LongDoubleWidth = 96;
+  LongDoubleAlign = 32;
+} else {
+  LongDoubleWidth = 128;
+  LongDoubleAlign = 128;
+}
+  }
 }
   }
 

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index c42cae941634f..1b7448feb472b 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3456,6 +3456,8 @@ void CompilerInvocation::GenerateLangArgs(const 
LangOptions &Opts,
 GenerateArg(Args, OPT_mlong_double_128, SA);
   else if (Opts.LongDoubleSize == 64)
 GenerateArg(Args, OPT_mlong_double_64, SA);
+  else if (Opts.LongDoubleSize == 80)
+GenerateArg(Args, OPT_mlong_double_80, SA);
 
   // Not generating '-mrtd', it's just an alias for '-fdefault-calling-conv='.
 
@@ -3838,9 +3840,16 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding;
   if (!Opts.NoBuiltin)
 getAllNoBuiltinFuncValues(Args, Opts.NoBuiltinFuncs);
-  Opts.LongDoubleSize = Args.hasArg(OPT_mlong_double_128)
-? 128
-: Args.hasArg(OPT_mlong_double_64) ? 64 : 0;
+  if (Arg *A = Args.getLastArg(options::OPT_LongDouble_Group)) {
+if (A->getOption().matches(options::OPT_mlong_double_64))
+  Opts.LongDoubleSize = 64;
+else if (A->getOption().matches(options::OPT_mlong_double_80))
+  Opts.LongDoubleSize = 80;
+else if (A->getOption().matches(options::OPT_mlong_double_128))
+  Opts.LongDoubleSize = 128;
+else
+  Opts.LongDoubleSize = 0;
+  }
   if (Opts.FastRelaxedMath)
 Opts.setDefaultFPContractMode(LangOptions::FPM_Fast);
   llvm::sort(Opts.ModuleFeatures);

diff  --git a/clang/test/CodeGen/X86/long-double-config-size.c 
b/clang/test/CodeGen/X86/long-double-config-size.c
new file mode 100644
index 0..563a483ca8cd6
--- /dev/null
+++ b/clang/test/CodeGen/X86/long-double-config-size.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -mlong-double-64 
-o - | FileCheck %s --check-prefix=SIZE64
+// RUN: %clang_cc1 -triple i386-windows-msvc %s -emit-llvm -mlong-double-80 -o 
- | FileCheck %s --check-prefix=SIZE80
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -mlong-double-80 
-o - | FileCheck %s --check-prefix=SIZE80
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -mlong-double-128 
-o - | FileCheck %s --check-prefix=SIZE128
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -o - | FileCheck 
%s --check-prefix=SIZE64
+
+long double global;
+// SIZE64: @global = dso_local global double 0
+// SIZE80: @global = dso_local global x86_fp80 0xK{{0+}}, align 16
+// SIZE128: @global = dso_local global fp128 0
+
+long double func(long double param) {
+  // SIZE64: define dso_local double @func(double noundef %param)
+  // SIZE80: define dso_local x86_fp80 @func(x86_fp80 noundef %param)
+  // SIZE128: define dso_local fp128  @func(fp128 noundef %param)
+  long double local = param;
+  // SIZE64: alloca double
+  // SIZE80: alloca x86_fp80, align 16
+  // SIZE128: alloca fp128
+  local = param;
+  return local + param;
+}


   

[PATCH] D115441: [X86][MS] Add 80bit long double support for Windows

2022-02-13 Thread Phoebe Wang 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 rG3e19ba36fca9: [X86][MS] Add 80bit long double support for 
Windows (authored by pengfei).

Changed prior to commit:
  https://reviews.llvm.org/D115441?vs=395129&id=408328#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115441

Files:
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/X86/long-double-config-size.c


Index: clang/test/CodeGen/X86/long-double-config-size.c
===
--- /dev/null
+++ clang/test/CodeGen/X86/long-double-config-size.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -mlong-double-64 
-o - | FileCheck %s --check-prefix=SIZE64
+// RUN: %clang_cc1 -triple i386-windows-msvc %s -emit-llvm -mlong-double-80 -o 
- | FileCheck %s --check-prefix=SIZE80
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -mlong-double-80 
-o - | FileCheck %s --check-prefix=SIZE80
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -mlong-double-128 
-o - | FileCheck %s --check-prefix=SIZE128
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -o - | FileCheck 
%s --check-prefix=SIZE64
+
+long double global;
+// SIZE64: @global = dso_local global double 0
+// SIZE80: @global = dso_local global x86_fp80 0xK{{0+}}, align 16
+// SIZE128: @global = dso_local global fp128 0
+
+long double func(long double param) {
+  // SIZE64: define dso_local double @func(double noundef %param)
+  // SIZE80: define dso_local x86_fp80 @func(x86_fp80 noundef %param)
+  // SIZE128: define dso_local fp128  @func(fp128 noundef %param)
+  long double local = param;
+  // SIZE64: alloca double
+  // SIZE80: alloca x86_fp80, align 16
+  // SIZE128: alloca fp128
+  local = param;
+  return local + param;
+}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3456,6 +3456,8 @@
 GenerateArg(Args, OPT_mlong_double_128, SA);
   else if (Opts.LongDoubleSize == 64)
 GenerateArg(Args, OPT_mlong_double_64, SA);
+  else if (Opts.LongDoubleSize == 80)
+GenerateArg(Args, OPT_mlong_double_80, SA);
 
   // Not generating '-mrtd', it's just an alias for '-fdefault-calling-conv='.
 
@@ -3838,9 +3840,16 @@
   Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding;
   if (!Opts.NoBuiltin)
 getAllNoBuiltinFuncValues(Args, Opts.NoBuiltinFuncs);
-  Opts.LongDoubleSize = Args.hasArg(OPT_mlong_double_128)
-? 128
-: Args.hasArg(OPT_mlong_double_64) ? 64 : 0;
+  if (Arg *A = Args.getLastArg(options::OPT_LongDouble_Group)) {
+if (A->getOption().matches(options::OPT_mlong_double_64))
+  Opts.LongDoubleSize = 64;
+else if (A->getOption().matches(options::OPT_mlong_double_80))
+  Opts.LongDoubleSize = 80;
+else if (A->getOption().matches(options::OPT_mlong_double_128))
+  Opts.LongDoubleSize = 128;
+else
+  Opts.LongDoubleSize = 0;
+  }
   if (Opts.FastRelaxedMath)
 Opts.setDefaultFPContractMode(LangOptions::FPM_Fast);
   llvm::sort(Opts.ModuleFeatures);
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -449,6 +449,20 @@
 } else if (Opts.LongDoubleSize == 128) {
   LongDoubleWidth = LongDoubleAlign = 128;
   LongDoubleFormat = &llvm::APFloat::IEEEquad();
+} else if (Opts.LongDoubleSize == 80) {
+  LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
+  if (getTriple().isWindowsMSVCEnvironment()) {
+LongDoubleWidth = 128;
+LongDoubleAlign = 128;
+  } else { // Linux
+if (getTriple().getArch() == llvm::Triple::x86) {
+  LongDoubleWidth = 96;
+  LongDoubleAlign = 32;
+} else {
+  LongDoubleWidth = 128;
+  LongDoubleAlign = 128;
+}
+  }
 }
   }
 


Index: clang/test/CodeGen/X86/long-double-config-size.c
===
--- /dev/null
+++ clang/test/CodeGen/X86/long-double-config-size.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -mlong-double-64 -o - | FileCheck %s --check-prefix=SIZE64
+// RUN: %clang_cc1 -triple i386-windows-msvc %s -emit-llvm -mlong-double-80 -o - | FileCheck %s --check-prefix=SIZE80
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -mlong-double-80 -o - | FileCheck %s --check-prefix=SIZE80
+// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -mlong-double-128 -o - | FileCheck %s --check-prefix=SIZE128
+// RUN: %clang_cc1 -triple x86_64

[PATCH] D117929: [XRay] Add support for RISCV

2022-02-13 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris added a comment.

In D117929#3317813 , @ashwin98 wrote:

> In D117929#3314355 , @ashwin98 
> wrote:
>
>> On including RISCV64 to the check, I see new issues while reading the 
>> instrumentation map. How do I verify that the instrumentation map is being 
>> generated correctly (or if there is a problem with it), and where is the 
>> code that is responsible for the generation of the instrumentation map (is 
>> it in xray_init.cpp)? I'm not sure if this is a RISCV compatibility issue 
>> with the xray tool, or if I've missed something that is causing problems 
>> during the instrumentation map initialization.
>
> I traced the root cause of the issue.  It seems to be stemming from the 
> instrumentation map's relocation handling, specifically, at line 129 of 
> InstrumentationMap.cpp, when we try to extract the load address of the 
> symbol. I believe that part of code was written keeping AArch64 in mind, but 
> I'm not too sure about what changes will need to be made to add RISCV64 
> compatibility, I'm trying to figure it out.

If you can turn the relocations you're emitting in the assembly to be relative 
instead of absolute when building the instrumentation map like in other 
architectures, then the tooling will be able to resolve them. Maybe that helps?


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

https://reviews.llvm.org/D117929

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


[PATCH] D119210: [RISCV] Recover the implication between Zve* extensions and the V extension.

2022-02-13 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD added a comment.

Kindly reverse ping.
May you land this change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119210

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


[clang] 83028ad - [clang][AST][ASTImporter] Set record to complete during import of its members.

2022-02-13 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2022-02-14T08:27:44+01:00
New Revision: 83028ad934d60b024b5b0272cb68523232715dab

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

LOG: [clang][AST][ASTImporter] Set record to complete during import of its 
members.

At import of a member it may require that the record is already set to complete.
(For example 'computeDependence' at create of some Expr nodes.)
The record at this time may not be completely imported, the result of layout
calculations can be incorrect, but at least no crash occurs this way.

A good solution would be if fields of every encountered record are imported
before other members of all records. This is much more difficult to implement.

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

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 457465e87d935..063fe2bfdf5e3 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -2012,6 +2012,14 @@ Error ASTNodeImporter::ImportDefinition(
   }
 
   To->startDefinition();
+  // Set the definition to complete even if it is really not complete during
+  // import. Some AST constructs (expressions) require the record layout
+  // to be calculated (see 'clang::computeDependence') at the time they are
+  // constructed. Import of such AST node is possible during import of the
+  // same record, there is no way to have a completely defined record (all
+  // fields imported) at that time without multiple AST import passes.
+  if (!Importer.isMinimalImport())
+To->setCompleteDefinition(true);
   // Complete the definition even if error is returned.
   // The RecordDecl may be already part of the AST so it is better to
   // have it in complete state even if something is wrong with it.
@@ -2076,9 +2084,10 @@ Error ASTNodeImporter::ImportDefinition(
   ToCXX->setBases(Bases.data(), Bases.size());
   }
 
-  if (shouldForceImportDeclContext(Kind))
+  if (shouldForceImportDeclContext(Kind)) {
 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
   return Err;
+  }
 
   return Error::success();
 }

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 04da7988fc308..77c6d6ad2e19d 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -6809,7 +6809,8 @@ struct ImportWithExternalSource : 
ASTImporterOptionSpecificTestBase {
  bool MinimalImport,
  const std::shared_ptr &SharedState) {
   return new ASTImporter(ToContext, ToFileManager, FromContext,
- FromFileManager, MinimalImport,
+ // Use minimal import for these tests.
+ FromFileManager, /*MinimalImport=*/true,
  // We use the regular lookup.
  /*SharedState=*/nullptr);
 };
@@ -7475,6 +7476,57 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportDeductionGuideDifferentOrder) {
 ToDGOther);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportRecordWithLayoutRequestingExpr) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  R"(
+  struct A {
+int idx;
+static void foo(A x) {
+  (void)&"text"[x.idx];
+}
+  };
+  )",
+  Lang_CXX11);
+
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+
+  // Test that during import of 'foo' the record layout can be obtained without
+  // crash.
+  auto *ToA = Import(FromA, Lang_CXX11);
+  EXPECT_TRUE(ToA);
+  EXPECT_TRUE(ToA->isCompleteDefinition());
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportRecordWithLayoutRequestingExprDifferentRecord) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  R"(
+  struct B;
+  struct A {
+int idx;
+B *b;
+  };
+  struct B {
+static void foo(A x) {
+  (void)&"text"[x.idx];
+}
+  };
+  )",
+  Lang_CXX11);
+
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+
+  // Test that during import of 'foo' the record layout (of 'A') can be 
obtained
+  // without crash. It is not possible to have all of the fields of 'A' 
imported
+  // at that time (without big code changes).
+  auto *ToA = Import(FromA, Lang_CXX11);
+  EXPECT_TRUE(ToA);
+  EXPECT_TRUE(ToA->isCompleteDefinition());
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 



___
cfe-commits mailing list
cfe-

[PATCH] D116155: [clang][AST][ASTImporter] Set record to complete during import of its members.

2022-02-13 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG83028ad934d6: [clang][AST][ASTImporter] Set record to 
complete during import of its members. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116155

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -6809,7 +6809,8 @@
  bool MinimalImport,
  const std::shared_ptr &SharedState) {
   return new ASTImporter(ToContext, ToFileManager, FromContext,
- FromFileManager, MinimalImport,
+ // Use minimal import for these tests.
+ FromFileManager, /*MinimalImport=*/true,
  // We use the regular lookup.
  /*SharedState=*/nullptr);
 };
@@ -7475,6 +7476,57 @@
 ToDGOther);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportRecordWithLayoutRequestingExpr) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  R"(
+  struct A {
+int idx;
+static void foo(A x) {
+  (void)&"text"[x.idx];
+}
+  };
+  )",
+  Lang_CXX11);
+
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+
+  // Test that during import of 'foo' the record layout can be obtained without
+  // crash.
+  auto *ToA = Import(FromA, Lang_CXX11);
+  EXPECT_TRUE(ToA);
+  EXPECT_TRUE(ToA->isCompleteDefinition());
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportRecordWithLayoutRequestingExprDifferentRecord) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  R"(
+  struct B;
+  struct A {
+int idx;
+B *b;
+  };
+  struct B {
+static void foo(A x) {
+  (void)&"text"[x.idx];
+}
+  };
+  )",
+  Lang_CXX11);
+
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+
+  // Test that during import of 'foo' the record layout (of 'A') can be obtained
+  // without crash. It is not possible to have all of the fields of 'A' imported
+  // at that time (without big code changes).
+  auto *ToA = Import(FromA, Lang_CXX11);
+  EXPECT_TRUE(ToA);
+  EXPECT_TRUE(ToA->isCompleteDefinition());
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -2012,6 +2012,14 @@
   }
 
   To->startDefinition();
+  // Set the definition to complete even if it is really not complete during
+  // import. Some AST constructs (expressions) require the record layout
+  // to be calculated (see 'clang::computeDependence') at the time they are
+  // constructed. Import of such AST node is possible during import of the
+  // same record, there is no way to have a completely defined record (all
+  // fields imported) at that time without multiple AST import passes.
+  if (!Importer.isMinimalImport())
+To->setCompleteDefinition(true);
   // Complete the definition even if error is returned.
   // The RecordDecl may be already part of the AST so it is better to
   // have it in complete state even if something is wrong with it.
@@ -2076,9 +2084,10 @@
   ToCXX->setBases(Bases.data(), Bases.size());
   }
 
-  if (shouldForceImportDeclContext(Kind))
+  if (shouldForceImportDeclContext(Kind)) {
 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
   return Err;
+  }
 
   return Error::success();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119655: [Driver][NetBSD] -r: imply -nostdlib like GCC

2022-02-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

In D119655#3318003 , @joerg wrote:

> I'm ambivalent about this change. To me, it falls into the category of "stop 
> passing random ld options to the compiler driver".

It's not only about options, but also some crt files. Very few projects assume 
the behavior and for the few, not implying -nostdlib for -r will cause them 
some portability inconvenience.
Well, you maintain the NetBSD part and can certainly disagree :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119655

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


[PATCH] D119680: [clang-format] Fix SpacesInLineCommentPrefix deleting tokens.

2022-02-13 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

Never would have thought about that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119680

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


[PATCH] D119221: [clang][lexer] Allow u8 character literal prefixes in C2x

2022-02-13 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 408341.

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

https://reviews.llvm.org/D119221

Files:
  clang/lib/Lex/Lexer.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Lexer/utf8-char-literal.cpp


Index: clang/test/Lexer/utf8-char-literal.cpp
===
--- clang/test/Lexer/utf8-char-literal.cpp
+++ clang/test/Lexer/utf8-char-literal.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -fsyntax-only 
-verify %s
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c11 -x c -fsyntax-only 
-verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c2x -DC2X -x c 
-fsyntax-only -verify %s
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++1z -fsyntax-only 
-verify %s
 
 int array0[u'ñ' == u'\xf1'? 1 : -1];
@@ -12,4 +13,16 @@
 char d = u8'\u1234'; // expected-error {{character too large for enclosing 
character literal type}}
 char e = u8'ሴ'; // expected-error {{character too large for enclosing 
character literal type}}
 char f = u8'ab'; // expected-error {{Unicode character literals may not 
contain multiple characters}}
+#elif defined(C2X)
+char a = u8'ñ';  // expected-error {{character too large for enclosing 
character literal type}}
+char b = u8'\x80';   // ok
+char c = u8'\u0080'; // expected-error {{universal character name refers to a 
control character}}
+char d = u8'\u1234'; // expected-error {{character too large for enclosing 
character literal type}}
+char e = u8'ሴ';  // expected-error {{character too large for enclosing 
character literal type}}
+char f = u8'ab'; // expected-error {{Unicode character literals may not 
contain multiple characters}}
+_Static_assert(
+_Generic(u8'a',
+ default : 0,
+ unsigned char : 1),
+"Surprise!");
 #endif
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -3551,6 +3551,8 @@
   QualType Ty;
   if (Literal.isWide())
 Ty = Context.WideCharTy; // L'x' -> wchar_t in C and C++.
+  else if (Literal.isUTF8() && getLangOpts().C2x)
+Ty = Context.UnsignedCharTy; // u8'x' -> unsigned char in C2x
   else if (Literal.isUTF8() && getLangOpts().Char8)
 Ty = Context.Char8Ty; // u8'x' -> char8_t when it exists.
   else if (Literal.isUTF16())
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -3459,7 +3459,10 @@
 MIOpt.ReadToken();
 return LexNumericConstant(Result, CurPtr);
 
-  case 'u':   // Identifier (uber) or C11/C++11 UTF-8 or UTF-16 string literal
+  // Identifer (e.g., uber), or
+  // UTF-8 (C2x/C++17) or UTF-16 (C11/C++11) character literal, or
+  // UTF-8 or UTF-16 string literal (C11/C++11).
+  case 'u':
 // Notify MIOpt that we read a non-whitespace/non-comment token.
 MIOpt.ReadToken();
 
@@ -3493,7 +3496,7 @@
ConsumeChar(ConsumeChar(CurPtr, SizeTmp, 
Result),
SizeTmp2, Result),
tok::utf8_string_literal);
-if (Char2 == '\'' && LangOpts.CPlusPlus17)
+if (Char2 == '\'' && (LangOpts.CPlusPlus17 || LangOpts.C2x))
   return LexCharConstant(
   Result, ConsumeChar(ConsumeChar(CurPtr, SizeTmp, Result),
   SizeTmp2, Result),
@@ -3517,7 +3520,7 @@
 // treat u like the start of an identifier.
 return LexIdentifierContinue(Result, CurPtr);
 
-  case 'U':   // Identifier (Uber) or C11/C++11 UTF-32 string literal
+  case 'U': // Identifier (e.g. Uber) or C11/C++11 UTF-32 string literal
 // Notify MIOpt that we read a non-whitespace/non-comment token.
 MIOpt.ReadToken();
 


Index: clang/test/Lexer/utf8-char-literal.cpp
===
--- clang/test/Lexer/utf8-char-literal.cpp
+++ clang/test/Lexer/utf8-char-literal.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -fsyntax-only -verify %s
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c11 -x c -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c2x -DC2X -x c -fsyntax-only -verify %s
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++1z -fsyntax-only -verify %s
 
 int array0[u'ñ' == u'\xf1'? 1 : -1];
@@ -12,4 +13,16 @@
 char d = u8'\u1234'; // expected-error {{character too large for enclosing character literal type}}
 char e = u8'ሴ'; // expected-error {{character too large for enclosing character literal type}}
 char f = u8'ab'; // expected-error {{Unicode character literals may not contain multiple characters}}
+#elif defined(C2X)
+char a = u8'ñ';  // expected-error {{character too large for enclosing character literal type}}
+char b = u8'\x80';   // ok
+char c = u8'\u0080'; /

[PATCH] D119210: [RISCV] Recover the implication between Zve* extensions and the V extension.

2022-02-13 Thread Jianjian Guan via Phabricator via cfe-commits
jacquesguan added a comment.

In D119210#3318348 , @eopXD wrote:

> Kindly reverse ping.
> May you land this change?

OK, right now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119210

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


[clang] bfb4c0c - [RISCV] Recover the implication between Zve* extensions and the V extension.

2022-02-13 Thread via cfe-commits

Author: jacquesguan
Date: 2022-02-14T15:52:07+08:00
New Revision: bfb4c0c37078aa5ce251752d99310ccb05e1296a

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

LOG: [RISCV] Recover the implication between Zve* extensions and the V 
extension.

This revision recover the implication between Zve* extensions and the V 
extension.

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

Added: 


Modified: 
clang/lib/Basic/Targets/RISCV.cpp
clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c
clang/utils/TableGen/RISCVVEmitter.cpp
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/RISCV.td
llvm/lib/Target/RISCV/RISCVSubtarget.h
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/attribute-arch.s

Removed: 




diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index fd30551eb4e0d..cc51bf78f0c1a 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -188,7 +188,7 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (ISAInfo->hasExtension("c"))
 Builder.defineMacro("__riscv_compressed");
 
-  if (ISAInfo->hasExtension("zve32x") || ISAInfo->hasExtension("v"))
+  if (ISAInfo->hasExtension("zve32x"))
 Builder.defineMacro("__riscv_vector");
 }
 

diff  --git a/clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c 
b/clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c
index 7de132e1ce6d0..4436744a3c26d 100644
--- a/clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c
+++ b/clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c
@@ -11,7 +11,7 @@
 // CHECK-RV64V-NEXT:ret i32 [[CONV]]
 //
 
-// CHECK-RV64-ERR: error: builtin requires at least one of the following 
extensions support to be enabled : 'Zve32x', 'V'
+// CHECK-RV64-ERR: error: builtin requires at least one of the following 
extensions support to be enabled : 'Zve32x'
 
 int test() {
   return __builtin_rvv_vsetvli(1, 0, 0);

diff  --git a/clang/utils/TableGen/RISCVVEmitter.cpp 
b/clang/utils/TableGen/RISCVVEmitter.cpp
index 4b80d6da72fa8..eb718ff8a49ea 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -1040,7 +1040,7 @@ void RVVEmitter::createBuiltins(raw_ostream &OS) {
 
   OS << "#if defined(TARGET_BUILTIN) && !defined(RISCVV_BUILTIN)\n";
   OS << "#define RISCVV_BUILTIN(ID, TYPE, ATTRS) TARGET_BUILTIN(ID, TYPE, "
-"ATTRS, \"zve32x|v\")\n";
+"ATTRS, \"zve32x\")\n";
   OS << "#endif\n";
   for (auto &Def : Defs) {
 auto P =

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 598eceaa6c274..7af375aef86b5 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -688,11 +688,9 @@ Error RISCVISAInfo::checkDependency() {
   bool HasE = Exts.count("e") != 0;
   bool HasD = Exts.count("d") != 0;
   bool HasF = Exts.count("f") != 0;
-  bool HasZve32x = Exts.count("zve32x") != 0;
+  bool HasVector = Exts.count("zve32x") != 0;
   bool HasZve32f = Exts.count("zve32f") != 0;
   bool HasZve64d = Exts.count("zve64d") != 0;
-  bool HasV = Exts.count("v") != 0;
-  bool HasVector = HasZve32x || HasV;
   bool HasZvl = MinVLen != 0;
 
   if (HasE && !IsRv32)
@@ -732,7 +730,7 @@ Error RISCVISAInfo::checkDependency() {
   return Error::success();
 }
 
-static const char *ImpliedExtsV[] = {"zvl128b", "f", "d"};
+static const char *ImpliedExtsV[] = {"zvl128b", "zve64d", "f", "d"};
 static const char *ImpliedExtsZfhmin[] = {"f"};
 static const char *ImpliedExtsZfh[] = {"f"};
 static const char *ImpliedExtsZve64d[] = {"zve64f"};
@@ -864,11 +862,6 @@ void RISCVISAInfo::updateMaxELen() {
   ExtName.getAsInteger(10, ZveELen);
   MaxELen = std::max(MaxELen, ZveELen);
 }
-if (ExtName == "v") {
-  MaxELenFp = 64;
-  MaxELen = 64;
-  return;
-}
   }
 }
 

diff  --git a/llvm/lib/Target/RISCV/RISCV.td b/llvm/lib/Target/RISCV/RISCV.td
index f036696915f5b..5486649106941 100644
--- a/llvm/lib/Target/RISCV/RISCV.td
+++ b/llvm/lib/Target/RISCV/RISCV.td
@@ -340,21 +340,21 @@ def FeatureStdExtZve64d
 def FeatureStdExtV
 : SubtargetFeature<"v", "HasStdExtV", "true",
"'V' (Vector Extension for Application Processors)",
-   [FeatureStdExtZvl128b, FeatureStdExtF, FeatureStdExtD]>;
+   [FeatureStdExtZvl128b, FeatureStdExtZve64d, 
FeatureStdExtF, FeatureStdExtD]>;
 
 def HasVInstructions: Predicate<"Subtarget->hasVInstructions()">,
   AssemblerPredicate<
-  (any_of FeatureStdExtZve32x, FeatureStdExtV),
+  (any_of FeatureStdExtZve32x),
   "'V' (Vector Extension for Application Processors), 'Zve32x' or "
   "'Zve64x' (Vector Extensions for Embedded Processors)">;
 def Has

[PATCH] D119210: [RISCV] Recover the implication between Zve* extensions and the V extension.

2022-02-13 Thread Jianjian Guan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbfb4c0c37078: [RISCV] Recover the implication between Zve* 
extensions and the V extension. (authored by jacquesguan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119210

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/CodeGen/RISCV/rvv-intrinsics/rvv-error.c
  clang/utils/TableGen/RISCVVEmitter.cpp
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -34,43 +34,43 @@
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0"
 
 .attribute arch, "rv32ivzvl32b"
-# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0"
 
 .attribute arch, "rv32ivzvl64b"
-# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0"
 
 .attribute arch, "rv32ivzvl128b"
-# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0"
 
 .attribute arch, "rv32ivzvl256b"
-# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zvl128b1p0_zvl256b1p0_zvl32b1p0_zvl64b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl256b1p0_zvl32b1p0_zvl64b1p0"
 
 .attribute arch, "rv32ivzvl512b"
-# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zvl128b1p0_zvl256b1p0_zvl32b1p0_zvl512b1p0_zvl64b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl256b1p0_zvl32b1p0_zvl512b1p0_zvl64b1p0"
 
 .attribute arch, "rv32ivzvl1024b"
-# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zvl1024b1p0_zvl128b1p0_zvl256b1p0_zvl32b1p0_zvl512b1p0_zvl64b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl1024b1p0_zvl128b1p0_zvl256b1p0_zvl32b1p0_zvl512b1p0_zvl64b1p0"
 
 .attribute arch, "rv32ivzvl2048b"
-# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zvl1024b1p0_zvl128b1p0_zvl2048b1p0_zvl256b1p0_zvl32b1p0_zvl512b1p0_zvl64b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl1024b1p0_zvl128b1p0_zvl2048b1p0_zvl256b1p0_zvl32b1p0_zvl512b1p0_zvl64b1p0"
 
 .attribute arch, "rv32ivzvl4096b"
-# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zvl1024b1p0_zvl128b1p0_zvl2048b1p0_zvl256b1p0_zvl32b1p0_zvl4096b1p0_zvl512b1p0_zvl64b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl1024b1p0_zvl128b1p0_zvl2048b1p0_zvl256b1p0_zvl32b1p0_zvl4096b1p0_zvl512b1p0_zvl64b1p0"
 
 .attribute arch, "rv32ivzvl8192b"
-# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zvl1024b1p0_zvl128b1p0_zvl2048b1p0_zvl256b1p0_zvl32b1p0_zvl4096b1p0_zvl512b1p0_zvl64b1p0_zvl8192b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl1024b1p0_zvl128b1p0_zvl2048b1p0_zvl256b1p0_zvl32b1p0_zvl4096b1p0_zvl512b1p0_zvl64b1p0_zvl8192b1p0"
 
 .attribute arch, "rv32ivzvl16384b"
-# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zvl1024b1p0_zvl128b1p0_zvl16384b1p0_zvl2048b1p0_zvl256b1p0_zvl32b1p0_zvl4096b1p0_zvl512b1p0_zvl64b1p0_zvl8192b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl1024b1p0_zvl128b1p0_zvl16384b1p0_zvl2048b1p0_zvl256b1p0_zvl32b1p0_zvl4096b1p0_zvl512b1p0_zvl64b1p0_zvl8192b1p0"
 
 .attribute arch, "rv32ivzvl32768b"
-# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zvl1024b1p0_zvl128b1p0_zvl16384b1p0_zvl2048b1p0_zvl256b1p0_zvl32768b1p0_zvl32b1p0_zvl4096b1p0_zvl512b1p0_zvl64b1p0_zvl8192b1p0"
+# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl1024b1p0_zvl128b1p0_zvl16384b1p0_zvl2048b1p0_zvl256b1p0_zvl32768b1p0_zvl32b1p0_zvl4096b1p0_zvl512b1p0_zvl64b1p0_zvl8192b1p0"
 
 .attribute arch, "rv32ivzvl65536b"
-# CHECK: attribute  5, "rv32i2p0_f2p0_d2p0_v1p0_zvl1024b1p0_zvl128b1p0_zvl16384b1p0_zvl204

[PATCH] D119210: [RISCV] Recover the implication between Zve* extensions and the V extension.

2022-02-13 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119210

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