[PATCH] D100879: [Clang] Propagate guaranteed alignment for malloc and others

2021-04-24 Thread Dave Green via Phabricator via cfe-commits
dmgreen added a comment.

Hello. Nice idea. Unfortunately this blocks tail folding, making codesize a bit 
bigger: https://godbolt.org/z/rncPvbh8d
I'm guessing it shouldn't? But the attribute isn't handled somewhere along the 
way. Any ideas where?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100879

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


[PATCH] D98726: [analyzer] Enabling MallocChecker to take up after SmartPtrModelling

2021-04-24 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

F16456099: 2021-04-24_733x821.png 

As you can see here, the bug note is attached in the second case (please refer 
to my previous comment), but somehow, it doesn't finally show up as a bug.
Weird.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98726

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


[PATCH] D100879: [Clang] Propagate guaranteed alignment for malloc and others

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

In D100879#2714431 , @dmgreen wrote:

> Hello. Nice idea. Unfortunately this blocks tail folding, making codesize a 
> bit bigger: https://godbolt.org/z/rncPvbh8d
> I'm guessing it shouldn't? But the attribute isn't handled somewhere along 
> the way. Any ideas where?



In D100879#2714431 , @dmgreen wrote:

> Hello. Nice idea. Unfortunately this blocks tail folding, making codesize a 
> bit bigger: https://godbolt.org/z/rncPvbh8d
> I'm guessing it shouldn't? But the attribute isn't handled somewhere along 
> the way. Any ideas where?

Hmm.. I know I think.

  diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp
  index 5d1b00463dc8..425e1b4e8e2d 100644
  --- a/llvm/lib/CodeGen/Analysis.cpp
  +++ b/llvm/lib/CodeGen/Analysis.cpp
  @@ -560,6 +560,8 @@ bool llvm::attributesPermitTailCall(const Function *F, 
const Instruction *I,
   
 // Following attributes are completely benign as far as calling convention
 // goes, they shouldn't affect whether the call is a tail call.
  +  CallerAttrs.removeAttribute(Attribute::Alignment);
  +  CalleeAttrs.removeAttribute(Attribute::Alignment);
 CallerAttrs.removeAttribute(Attribute::NoAlias);
 CalleeAttrs.removeAttribute(Attribute::NoAlias);
 CallerAttrs.removeAttribute(Attribute::NonNull);

Inspiration: 
https://github.com/llvm/llvm-project/commit/62ad2128255877ed41c714366861eee9c1da30dd

If you want you can fix it (or I can do that later today).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100879

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


[clang] c68f929 - [Clang] Added doc for malloc attribute

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

Author: Dávid Bolvanský
Date: 2021-04-24T15:27:48+02:00
New Revision: c68f92983600196e33e8abfbcd1aa19235f34c8d

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

LOG: [Clang] Added doc for malloc attribute

Taken mostly from LLVM langref.

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fcad24b83a05..08534ec61620 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1494,7 +1494,7 @@ def IFunc : Attr, TargetSpecificAttr {
 def Restrict : InheritableAttr {
   let Spellings = [Declspec<"restrict">, GCC<"malloc">];
   let Subjects = SubjectList<[Function]>;
-  let Documentation = [Undocumented];
+  let Documentation = [RestrictDocs];
 }
 
 def LayoutVersion : InheritableAttr, TargetSpecificAttr 
{

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 0af5b790d8a3..7b9d618c07ae 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3712,6 +3712,15 @@ system) and does not imply undefined behavior, making it 
more widely applicable.
   }];
 }
 
+def RestrictDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``malloc`` attribute indicates that the function acts like a system memory
+allocation function, returning a pointer to allocated storage disjoint from the
+storage for any other object accessible to the caller.
+  }];
+}
+
 def ReturnsNonNullDocs : Documentation {
   let Category = NullabilityDocs;
   let Content = [{



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


[clang] d29a53d - [Clang] Added heading to doc for malloc attribute

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

Author: Dávid Bolvanský
Date: 2021-04-24T15:35:16+02:00
New Revision: d29a53d9cabcb37621b793c5bf44076e75b8db88

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

LOG: [Clang] Added heading to doc for malloc attribute

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 7b9d618c07ae..1960596f1bfb 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3714,6 +3714,7 @@ system) and does not imply undefined behavior, making it 
more widely applicable.
 
 def RestrictDocs : Documentation {
   let Category = DocCatFunction;
+  let Heading = "malloc";
   let Content = [{
 The ``malloc`` attribute indicates that the function acts like a system memory
 allocation function, returning a pointer to allocated storage disjoint from the



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


[PATCH] D101192: Add support for #elifdef and #elifndef

2021-04-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 340283.
aaron.ballman marked 2 inline comments as done.
aaron.ballman added a comment.

Updated based on review feedback.


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

https://reviews.llvm.org/D101192

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Lex/DependencyDirectivesSourceMinimizer.h
  clang/include/clang/Lex/PPCallbacks.h
  clang/include/clang/Lex/PPConditionalDirectiveRecord.h
  clang/include/clang/Lex/PreprocessingRecord.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Index/IndexingAction.cpp
  clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/PPConditionalDirectiveRecord.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PreprocessingRecord.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/Index/complete-preprocessor.m
  clang/test/Preprocessor/elifdef.c
  clang/test/Preprocessor/if_warning.c
  clang/test/Preprocessor/ifdef-recover.c
  clang/test/Preprocessor/macro_misc.c
  clang/test/Preprocessor/macro_vaopt_check.cpp

Index: clang/test/Preprocessor/macro_vaopt_check.cpp
===
--- clang/test/Preprocessor/macro_vaopt_check.cpp
+++ clang/test/Preprocessor/macro_vaopt_check.cpp
@@ -68,7 +68,9 @@
 #if __VA_OPT__ // expected-warning {{__VA_OPT__ can only appear in the expansion of a variadic macro}}
 #endif
 
+// expected-warning@+2 {{__VA_OPT__ can only appear in the expansion of a variadic macro}}
 #ifdef __VA_OPT__ // expected-warning {{__VA_OPT__ can only appear in the expansion of a variadic macro}}
+#elifdef __VA_OPT__
 #endif
 
 #define BAD __VA_OPT__ // expected-warning {{__VA_OPT__ can only appear in the expansion of a variadic macro}}
Index: clang/test/Preprocessor/macro_misc.c
===
--- clang/test/Preprocessor/macro_misc.c
+++ clang/test/Preprocessor/macro_misc.c
@@ -2,6 +2,7 @@
 
 // This should not be rejected.
 #ifdef defined
+#elifdef defined
 #endif
 
 
Index: clang/test/Preprocessor/ifdef-recover.c
===
--- clang/test/Preprocessor/ifdef-recover.c
+++ clang/test/Preprocessor/ifdef-recover.c
@@ -19,4 +19,14 @@
 #if f(2
 #endif
 
+/* expected-error@+2 {{macro name missing}} */
+#ifdef FOO
+#elifdef
+#endif
+
+/* expected-error@+2 {{macro name must be an identifier}} */
+#ifdef FOO
+#elifdef !
+#endif
+
 int x;
Index: clang/test/Preprocessor/if_warning.c
===
--- clang/test/Preprocessor/if_warning.c
+++ clang/test/Preprocessor/if_warning.c
@@ -6,6 +6,7 @@
 #endif
 
 #ifdef foo
+#elifdef foo
 #endif
 
 #if defined(foo)
@@ -15,6 +16,7 @@
 // PR3938
 #if 0
 #ifdef D
+#elifdef D
 #else 1   // Should not warn due to C99 6.10p4
 #endif
 #endif
Index: clang/test/Preprocessor/elifdef.c
===
--- /dev/null
+++ clang/test/Preprocessor/elifdef.c
@@ -0,0 +1,98 @@
+// RUN: %clang_cc1 %s -Eonly -verify
+
+#ifdef FOO
+#elifdef BAR
+#error "did not expect to get here"
+#endif
+
+/* expected-error@+4 {{"got it"}} */
+#ifdef FOO
+#elifdef BAR
+#else
+#error "got it"
+#endif
+
+/* expected-error@+3 {{"got it"}} */
+#ifdef FOO
+#elifndef BAR
+#error "got it"
+#endif
+
+/* expected-error@+3 {{"got it"}} */
+#ifdef FOO
+#elifndef BAR
+#error "got it"
+#else
+#error "did not expect to get here"
+#endif
+
+#define BAR
+/* expected-error@+3 {{"got it"}} */
+#ifdef FOO
+#elifdef BAR
+#error "got it"
+#endif
+#undef BAR
+
+#ifdef FOO
+#elifdef BAR // test that comments aren't an issue
+#error "did not expect to get here"
+#endif
+
+/* expected-error@+4 {{"got it"}} */
+#ifdef FOO
+#elifdef BAR // test that comments aren't an issue
+#else
+#error "got it"
+#endif
+
+/* expected-error@+3 {{"got it"}} */
+#ifdef FOO
+#elifndef BAR // test that comments aren't an issue
+#error "got it"
+#endif
+
+/* expected-error@+3 {{"got it"}} */
+#ifdef FOO
+#elifndef BAR // test that comments aren't an issue
+#error "got it"
+#else
+#error "did not expect to get here"
+#endif
+
+#define BAR
+/* expected-error@+3 {{"got it"}} */
+#ifdef FOO
+#elifdef BAR // test that comments aren't an issue
+#error "got it"
+#endif
+#undef BAR
+
+#define BAR
+/* expected-error@+6 {{"got it"}} */
+#ifdef FOO
+#error "did not expect to get here"
+#elifndef BAR
+#error "did not expect to get here"
+#else
+#error "got it"
+#endif
+#undef BAR
+
+/* expected-error@+3 {{#elifdef after #else}} */
+#ifdef FOO
+#else
+#elifdef BAR
+#endif
+
+/* expected-error@+3 {{#elifndef after #else}} */
+#ifdef FOO
+#else
+#elifndef BAR
+#endif
+
+#elifdef FOO /* expected-error {{#elifdef without #if}} */
+#endif   /* expected-error {{#endif wit

[PATCH] D101192: Add support for #elifdef and #elifndef

2021-04-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Lex/PPDirectives.cpp:621
+if (CondInfo.FoundElse)
+Diag(Tok, diag::pp_err_elif_after_else) << (IsElifDef ? 1 : 2);
+

erichkeane wrote:
> As you know, I'm a giant fan of using enums for cases like this, so it would 
> be my preference to have something like that.  Sadly it looks like it would 
> have to be file-level here instead of functionlevel like is most convenient.
Given that all the diagnostics are in the same file, I suppose that's fine.



Comment at: clang/test/Preprocessor/elifdef.c:71
+
+/* expected-error@+3 {{#elifdef after #else}} */
+#ifdef FOO

erichkeane wrote:
> Are there any tests you could do to make sure this 'works'?  That is:
> 
> #define BAR
> // expected-error@+3 {{"AN ERROR!"}}
> #ifdef FOO
> #elifdef BAR
> #error "AN ERROR!"
> #endif
> 
> AND
> 
> // no error expected here!
> #ifdef FOO
> #elifndef BAR
> #error "AN ERROR!"
> #endif
> 
> And perhaps...
> 
> // expected-error@+4 {{"AN ERROR AGAIN!"}}
> #ifdef FOO
> #elifdef BAR
> #else
> #error "AN ERROR AGAIN!"
> #endif 
> 
> 
I think the first test is what's on lines 63-69, the third is what's on lines 
43-47, but I'll add the second test because I don't think that's covered yet. 
Thanks for the suggestion!


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

https://reviews.llvm.org/D101192

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


[PATCH] D101212: [AST][JSON] Fix null ptr crash dumping TemplateTemplateParmDecl

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

LGTM, thank you for the fix! Do you need me to commit on your behalf? If so, 
what email address and name would you like me to use for attribution?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101212

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


[PATCH] D69498: IR: Invert convergent attribute handling

2021-04-24 Thread Sameer Sahasrabuddhe via Phabricator via cfe-commits
sameerds added a comment.

In D69498#2712706 , @nhaehnle wrote:

> In D69498#2711396 , @foad wrote:
>
>> I don't have much to add to the conversation except to point out that this 
>> definition defines `noconvergent` in terms of divergent control flow, but 
>> the langref itself doesn't define what divergent control flow //is//, which 
>> makes it an incomplete spec. (Perhaps I'm just restating @arsenm's 
>> objections.) This seems unsatisfactory to me but I have no idea what to do 
>> about it. I agree with @sameerds that the current definition of `convergent` 
>> is too restrictive because in practice we really do want to be able to move 
>> convergent calls past uniform control flow.
>
> That is one of the things that D85603  
> addresses. I suspect Sameer was assuming the language from there in the 
> background.
>
> I agree with Matt that it would be best to avoid too much TTI dependence. The 
> existing situation with the intrinsics is already a bit of a strange one. I 
> wonder if it is possible to move to a world where isSourceOfDivergence need 
> not be target-dependent. (This requires e.g. new attributes on function 
> arguments as well as new information about address spaces in the data layout, 
> plus some new attributes to define intrinsic data flow. Likely beyond the 
> scope of this patch.)

In general, yes, it is great to avoid dependence on TTI. But this particular 
instance is actually a dependence on DA. The fact that DA depends on TTI is a 
separate problem. But I think that's a natural fallout of the fact that LLVM is 
not (and should not be) in the business of defining an execution model for 
multiple threads. Every optimization that affects control flow needs to be able 
to reason about an execution model that LLVM itself does not define. So what we 
end up with is an approximate model in the form of information gleaned from the 
frontend as well as the target. Neither source is "more correct" or "less 
ideal" than the other.


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

https://reviews.llvm.org/D69498

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


[PATCH] D100611: [Clang] Add clang attribute `clang_builtin_alias`.

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

LGTM aside from a small nit with the documentation wording.




Comment at: clang/include/clang/Basic/AttrDocs.td:5704
+
+This attribute is deprecated. Use clang_builtin_alias instead.
   }];

I'd like to avoid saying "deprecated" because then people may expect to see 
warnings about use of the ARM attribute. I don't know if the ARM folks are 
ready for it to be officially deprecated as opposed to just discouraged.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100611

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


[PATCH] D101212: [AST][JSON] Fix null ptr crash dumping TemplateTemplateParmDecl

2021-04-24 Thread David Tolnay via Phabricator via cfe-commits
dtolnay added a comment.

Yes, could you please commit for me? This is my first contribution. Please 
attribute to David Tolnay .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101212

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


[PATCH] D101236: [ASTImporter] Import definitions required for layout of [[no_unique_address]] from LLDB

2021-04-24 Thread Jan Kratochvil via Phabricator via cfe-commits
jankratochvil created this revision.
jankratochvil added reviewers: teemperor, shafik, dblaikie.
jankratochvil added a project: clang.
Herald added a subscriber: martong.
Herald added a reviewer: a.sidorin.
jankratochvil requested review of this revision.

When LLDB needs to use `[[no_unique_address]]` (which is in fact always but 
that is topic of the next patch) `FieldDecl::isZeroSize` was missing the 
`NoUniqueAddressAttr` attribute calculating wrong field offsets and thus 
failing on an assertion:
lldb: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp:802: void (anonymous 
namespace)::CGRecordLowering::insertPadding(): Assertion `Offset >= Size' 
failed.
After importing just the `NoUniqueAddressAttr` attribute various testcases were 
failing on:
clang/lib/AST/Decl.cpp:4163: bool clang::FieldDecl::isZeroSize(const 
clang::ASTContext &) const: Assertion `isInvalidDecl() && "valid field has 
incomplete type"' failed.
The LLDB testsuite exercises the patch fine. But the clang testcase I have 
provided here succeeds even with no patch applied. I expect I would need to 
import it X->Y->Z and not just X->Y but despite I tried some such code it was 
still working even without my patch.
Is it OK without a testcase or is there some suggestion how to write the clang 
testcase?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101236

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
@@ -6323,6 +6323,38 @@
 ToD->getTemplateSpecializationKind());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportNoUniqueAddress) {
+  auto SrcCode =
+  R"(
+  struct A {};
+  struct B {
+[[no_unique_address]] A a;
+  };
+  struct C : B {
+char c;
+  } c;
+  )";
+  Decl *FromTU = getTuDecl(SrcCode, Lang_CXX20);
+
+  // It does not fail even without the patch!
+  auto *BFromD = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("B")));
+  ASSERT_TRUE(BFromD);
+  auto *BToD = Import(BFromD, Lang_CXX20);
+  EXPECT_TRUE(BToD);
+  auto *BTo2D = Import(BToD, Lang_CXX20);
+  EXPECT_TRUE(BTo2D);
+
+  // It does not fail even without the patch!
+  auto *CFromD = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("C")));
+  ASSERT_TRUE(CFromD);
+  auto *CToD = Import(CFromD, Lang_CXX20);
+  EXPECT_TRUE(CToD);
+  auto *CTo2D = Import(CToD, Lang_CXX20);
+  EXPECT_TRUE(CTo2D);
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3673,6 +3673,28 @@
   D->getInClassInitStyle()))
 return ToField;
 
+  // FieldDecl::isZeroSize may need to check these.
+  if (auto FromAttr = D->getAttr()) {
+if (auto ToAttrOrErr = Importer.Import(FromAttr))
+  ToField->addAttr(*ToAttrOrErr);
+else
+  return ToAttrOrErr.takeError();
+RecordType *FromRT =
+const_cast(D->getType()->getAs());
+// Is this field a struct? FieldDecl::isZeroSize will need its definition.
+if (FromRT) {
+  RecordDecl *FromRD = FromRT->getDecl();
+  RecordType *ToRT =
+  const_cast(ToField->getType()->getAs());
+  assert(ToRT && "RecordType import has different type");
+  RecordDecl *ToRD = ToRT->getDecl();
+  if (FromRD->isCompleteDefinition() && !ToRD->isCompleteDefinition()) {
+if (Error Err = ImportDefinition(FromRD, ToRD, IDK_Basic))
+  return std::move(Err);
+  }
+}
+  }
+
   ToField->setAccess(D->getAccess());
   ToField->setLexicalDeclContext(LexicalDC);
   if (ToInitializer)
@@ -8445,6 +8467,8 @@
   // Make sure that ImportImpl registered the imported decl.
   assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
 
+  // There may have been NoUniqueAddressAttr for FieldDecl::isZeroSize.
+  ToD->dropAttrs();
   if (FromD->hasAttrs())
 for (const Attr *FromAttr : FromD->getAttrs()) {
   auto ToAttrOrErr = Import(FromAttr);


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -6323,6 +6323,38 @@
 ToD->getTemplateSpecializationKind());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportNoUniqueAddress) {
+  auto SrcCode =
+  R"(
+  struct A {};
+  struct B {
+[[no_unique_address]] A a;
+  };
+  struct C : B {
+char c;
+  } c;
+  )";
+  Decl *FromTU = getTuDecl(SrcCode, Lang_CXX20);
+
+  // It does not fail even without the patch!
+  auto *BFromD = Fi

[clang] 967ebad - Fix null ptr crash dumping TemplateTemplateParmDecl

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

Author: David Tolnay
Date: 2021-04-24T12:28:10-04:00
New Revision: 967ebad12521f3187014a722804c27a75d44e649

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

LOG: Fix null ptr crash dumping TemplateTemplateParmDecl

The following program winds up with
D->getDefaultArgStorage().getInheritedFrom() == nullptr
during dumping the TemplateTemplateParmDecl corresponding to the
template parameter of i.

  template 
  struct R;
  template  class = R>
  void i();

This patch fixes the null pointer dereference.

Added: 


Modified: 
clang/lib/AST/JSONNodeDumper.cpp
clang/test/AST/ast-dump-template-decls-json.cpp

Removed: 




diff  --git a/clang/lib/AST/JSONNodeDumper.cpp 
b/clang/lib/AST/JSONNodeDumper.cpp
index 7b99546bbe2d..5909812728a6 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -887,9 +887,10 @@ void JSONNodeDumper::VisitTemplateTemplateParmDecl(
 
   if (D->hasDefaultArgument())
 JOS.attributeObject("defaultArg", [=] {
+  const auto *InheritedFrom = D->getDefaultArgStorage().getInheritedFrom();
   Visit(D->getDefaultArgument().getArgument(),
-D->getDefaultArgStorage().getInheritedFrom()->getSourceRange(),
-D->getDefaultArgStorage().getInheritedFrom(),
+InheritedFrom ? InheritedFrom->getSourceRange() : SourceLocation{},
+InheritedFrom,
 D->defaultArgumentWasInherited() ? "inherited from" : "previous");
 });
 }

diff  --git a/clang/test/AST/ast-dump-template-decls-json.cpp 
b/clang/test/AST/ast-dump-template-decls-json.cpp
index f074d6f0137d..81b308e4fb74 100644
--- a/clang/test/AST/ast-dump-template-decls-json.cpp
+++ b/clang/test/AST/ast-dump-template-decls-json.cpp
@@ -55,6 +55,9 @@ template 
 template 
 void V::f() {}
 
+template  class = R>
+void i();
+
 // NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
 
 
@@ -2578,6 +2581,127 @@ void V::f() {}
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
 // CHECK-NEXT:]
+// CHECK-NEXT:   },
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "FunctionTemplateDecl",
+// CHECK-NEXT:"loc": {
+// CHECK-NEXT: "offset": 922,
+// CHECK-NEXT: "line": 59,
+// CHECK-NEXT: "col": 6,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT:},
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT:  "offset": 876,
+// CHECK-NEXT:  "line": 58,
+// CHECK-NEXT:  "col": 1,
+// CHECK-NEXT:  "tokLen": 8
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT:  "offset": 924,
+// CHECK-NEXT:  "line": 59,
+// CHECK-NEXT:  "col": 8,
+// CHECK-NEXT:  "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT:},
+// CHECK-NEXT:"name": "i",
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "TemplateTemplateParmDecl",
+// CHECK-NEXT:  "loc": {
+// CHECK-NEXT:   "offset": 912,
+// CHECK-NEXT:   "line": 58,
+// CHECK-NEXT:   "col": 37,
+// CHECK-NEXT:   "tokLen": 1
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:"offset": 886,
+// CHECK-NEXT:"col": 11,
+// CHECK-NEXT:"tokLen": 8
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:"offset": 914,
+// CHECK-NEXT:"col": 39,
+// CHECK-NEXT:"tokLen": 1
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "depth": 0,
+// CHECK-NEXT:  "index": 0,
+// CHECK-NEXT:  "defaultArg": {
+// CHECK-NEXT:   "kind": "TemplateArgument"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "inner": [
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "TemplateTypeParmDecl",
+// CHECK-NEXT:"loc": {
+// CHECK-NEXT: "offset": 904,
+// CHECK-NEXT: "col": 29,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT:},
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT:  "offset": 896,
+// CHECK-NEXT:  "col": 21,
+// CHECK-NEXT:  "tokLen": 8
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT:  "offset": 896,
+// CHECK-NEXT:  "col": 21,
+// CHECK-NEXT:  "tokLen": 8
+// CHECK-NEXT: }
+// CHECK-NEXT:},
+// CHECK-NEXT:"tagUsed": "typename",
+// CHECK-NEXT:"depth": 1,
+// CHECK-NEXT:"index": 0
+// CHECK-NEXT:   },
+// CHECK-NEXT:   {
+// CHECK-NEXT:"kind": "TemplateArgument",
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT:  "offset": 914,
+// CHECK-NEXT:  "col": 39,
+// CHECK-NEXT:  "to

[PATCH] D101212: [AST][JSON] Fix null ptr crash dumping TemplateTemplateParmDecl

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

In D101212#2714697 , @dtolnay wrote:

> Yes, could you please commit for me? This is my first contribution. Please 
> attribute to David Tolnay .

I've committed on your behalf in 967ebad12521f3187014a722804c27a75d44e649 
. Congrats 
on landing your first contribution!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101212

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


[PATCH] D101239: Enable IgnoreArray flag in pro-type-member-init rule

2021-04-24 Thread Hana Joo via Phabricator via cfe-commits
h-joo created this revision.
h-joo added a reviewer: alexfh.
h-joo added a project: clang-tools-extra.
Herald added subscribers: kbarton, nemanjai.
h-joo requested review of this revision.
Herald added a subscriber: cfe-commits.

The flag used to exist but wasn't implemented. Fixes b/47288 



https://reviews.llvm.org/D101239

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.ignorearrays.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.ignorearrays.cpp
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.ignorearrays.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s \
+// RUN: cppcoreguidelines-pro-type-member-init %t \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: cppcoreguidelines-pro-type-member-init.IgnoreArrays, value: 1} 
]}"
+
+struct HasArrayMember {
+  HasArrayMember() {}
+  // CHECK-MESSAGES: warning: constructor does not initialize these fields: 
Number
+  int Array[4];
+  int Number;
+};
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -402,6 +402,8 @@
   // Gather all fields (direct and indirect) that need to be initialized.
   SmallPtrSet FieldsToInit;
   forEachField(ClassDecl, ClassDecl.fields(), [&](const FieldDecl *F) {
+if (IgnoreArrays && F->getType()->isArrayType())
+  return;
 if (!F->hasInClassInitializer() &&
 utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
 Context) &&


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.ignorearrays.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.ignorearrays.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s \
+// RUN: cppcoreguidelines-pro-type-member-init %t \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: cppcoreguidelines-pro-type-member-init.IgnoreArrays, value: 1} ]}"
+
+struct HasArrayMember {
+  HasArrayMember() {}
+  // CHECK-MESSAGES: warning: constructor does not initialize these fields: Number
+  int Array[4];
+  int Number;
+};
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -402,6 +402,8 @@
   // Gather all fields (direct and indirect) that need to be initialized.
   SmallPtrSet FieldsToInit;
   forEachField(ClassDecl, ClassDecl.fields(), [&](const FieldDecl *F) {
+if (IgnoreArrays && F->getType()->isArrayType())
+  return;
 if (!F->hasInClassInitializer() &&
 utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
 Context) &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101192: Add support for #elifdef and #elifndef

2021-04-24 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

I reviewed the source minimizer sections, and the code looks correct.

It'd probably be good to have unit tests in 
clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp for the 
incremental changes.

- Do the new constructs stick around in the minimized source?
- Do they get paired correctly for the ppranges stuff? (I think you can modify 
or create new versions of SkippedPPRangesBasic and SkippedPPRangesNested.)




Comment at: clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp:909
   If,  // if/ifdef/ifndef
   Else // elif,else
 };

Please add the two new cases to this comment as well.



Comment at: clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp:924
 case pp_elif:
+case pp_elifdef:
+case pp_elifndef:

aaron.ballman wrote:
> erichkeane wrote:
> > Hrmph, not sure I understand this part either.
> I'm not 100% certain myself.
This part LGTM.


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

https://reviews.llvm.org/D101192

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


[clang] 1088643 - [Clang] Add clang attribute `clang_builtin_alias`.

2021-04-24 Thread Hsiangkai Wang via cfe-commits

Author: Hsiangkai Wang
Date: 2021-04-25T08:49:19+08:00
New Revision: 108864397d2639267f417cabc7f248431437

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

LOG: [Clang] Add clang attribute `clang_builtin_alias`.

In some cases, we want to provide the alias name for the clang builtins.
For example, the arguments must be constant integers for some RISC-V builtins.
If we use wrapper functions, we could not constrain the arguments be constant
integer. This attribute is used to achieve the purpose.

Besides this, use `clang_builtin_alias` is more efficient than using
wrapper functions. We use this attribute to deal with test time issue
reported in https://bugs.llvm.org/show_bug.cgi?id=49962.

In our downstream testing, it could decrease the testing time from 6.3
seconds to 3.7 seconds for vloxei.c test.

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

Added: 
clang/test/CodeGen/RISCV/riscv-attr-builtin-alias-err.c
clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/Decl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 08534ec61620..19ae88757033 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -642,6 +642,15 @@ def Alias : Attr {
   let Documentation = [Undocumented];
 }
 
+def BuiltinAlias : Attr {
+  let Spellings = [CXX11<"clang", "builtin_alias">,
+   C2x<"clang", "builtin_alias">,
+   GNU<"clang_builtin_alias">];
+  let Args = [IdentifierArgument<"BuiltinName">];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
+  let Documentation = [BuiltinAliasDocs];
+}
+
 def ArmBuiltinAlias : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Clang<"__clang_arm_builtin_alias">];
   let Args = [IdentifierArgument<"BuiltinName">];

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 1960596f1bfb..9cc4c837cc49 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4699,6 +4699,25 @@ the old mangled name and the new code will use the new 
mangled name with tags.
   }];
 }
 
+def BuiltinAliasDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+This attribute is used in the implementation of the C intrinsics.
+It allows the C intrinsic functions to be declared using the names defined
+in target builtins, and still be recognized as clang builtins equivalent to the
+underlying name. For example, ``riscv_vector.h`` declares the function ``vadd``
+with ``__attribute__((clang_builtin_alias(__builtin_rvv_vadd_vv_i8m1)))``.
+This ensures that both functions are recognized as that clang builtin,
+and in the latter case, the choice of which builtin to identify the
+function as can be deferred until after overload resolution.
+
+This attribute can only be used to set up the aliases for certain ARM/RISC-V
+C intrinsic functions; it is intended for use only inside ``arm_*.h`` and
+``riscv_*.h`` and is not a general mechanism for declaring arbitrary aliases
+for clang builtin functions.
+  }];
+}
+
 def PreferredNameDocs : Documentation {
   let Category = DocCatDecl;
   let Content = [{
@@ -5693,6 +5712,10 @@ This attribute can only be used to set up the aliases 
for certain Arm
 intrinsic functions; it is intended for use only inside ``arm_*.h``
 and is not a general mechanism for declaring arbitrary aliases for
 clang builtin functions.
+
+In order to avoid duplicating the attribute definitions for similar
+purpose for other architecture, there is a general form for the
+attribute `clang_builtin_alias`.
   }];
 }
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3a58d3dc5c4a..639565feb576 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4026,6 +4026,8 @@ def note_protocol_decl_undefined : Note<
 def err_attribute_preferred_name_arg_invalid : Error<
   "argument %0 to 'preferred_name' attribute is not a typedef for "
   "a specialization of %1">;
+def err_attribute_builtin_alias : Error<
+  "%0 attribute can only be applied to a ARM or RISC-V builtin">;
 
 // called-once attribute diagnostics.
 def err_called_once_attribute_wrong_type : Error<

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index fcda07dab604..f77acefb1781 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3265,6 +3265,8 @@ unsigned 

[PATCH] D100611: [Clang] Add clang attribute `clang_builtin_alias`.

2021-04-24 Thread Hsiangkai 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 rG108864397d26: [Clang] Add clang attribute 
`clang_builtin_alias`. (authored by HsiangKai).

Changed prior to commit:
  https://reviews.llvm.org/D100611?vs=340232&id=340319#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100611

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/RISCV/riscv-attr-builtin-alias-err.c
  clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test

Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -22,6 +22,7 @@
 // CHECK-NEXT: Assumption (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: Availability ((SubjectMatchRule_record, SubjectMatchRule_enum, SubjectMatchRule_enum_constant, SubjectMatchRule_field, SubjectMatchRule_function, SubjectMatchRule_namespace, SubjectMatchRule_objc_category, SubjectMatchRule_objc_implementation, SubjectMatchRule_objc_interface, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, SubjectMatchRule_objc_protocol, SubjectMatchRule_record, SubjectMatchRule_type_alias, SubjectMatchRule_variable))
 // CHECK-NEXT: BPFPreserveAccessIndex (SubjectMatchRule_record)
+// CHECK-NEXT: BuiltinAlias (SubjectMatchRule_function)
 // CHECK-NEXT: CFAuditedTransfer (SubjectMatchRule_function)
 // CHECK-NEXT: CFConsumed (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: CFICanonicalJumpTable (SubjectMatchRule_function)
Index: clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c
@@ -0,0 +1,36 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -emit-llvm -target-feature +experimental-v \
+// RUN:   %s -o - \
+// RUN:   | FileCheck %s
+
+#include 
+
+#define __rvv_generic \
+static inline __attribute__((__always_inline__, __nodebug__))
+
+__rvv_generic
+__attribute__((clang_builtin_alias(__builtin_rvv_vadd_vv_i8m1)))
+vint8m1_t vadd_generic (vint8m1_t op0, vint8m1_t op1, size_t op2);
+
+// CHECK-LABEL: @test(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[OP0_ADDR:%.*]] = alloca , align 1
+// CHECK-NEXT:[[OP1_ADDR:%.*]] = alloca , align 1
+// CHECK-NEXT:[[VL_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[RET:%.*]] = alloca , align 1
+// CHECK-NEXT:store  [[OP0:%.*]], * [[OP0_ADDR]], align 1
+// CHECK-NEXT:store  [[OP1:%.*]], * [[OP1_ADDR]], align 1
+// CHECK-NEXT:store i64 [[VL:%.*]], i64* [[VL_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load , * [[OP0_ADDR]], align 1
+// CHECK-NEXT:[[TMP1:%.*]] = load , * [[OP1_ADDR]], align 1
+// CHECK-NEXT:[[TMP2:%.*]] = load i64, i64* [[VL_ADDR]], align 8
+// CHECK-NEXT:[[TMP3:%.*]] = call  @llvm.riscv.vadd.nxv8i8.nxv8i8.i64( [[TMP0]],  [[TMP1]], i64 [[TMP2]])
+// CHECK-NEXT:store  [[TMP3]], * [[RET]], align 1
+// CHECK-NEXT:[[TMP4:%.*]] = load , * [[RET]], align 1
+// CHECK-NEXT:ret  [[TMP4]]
+//
+vint8m1_t test(vint8m1_t op0, vint8m1_t op1, size_t vl) {
+  vint8m1_t ret = vadd_generic(op0, op1, vl);
+  return ret;
+}
Index: clang/test/CodeGen/RISCV/riscv-attr-builtin-alias-err.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/riscv-attr-builtin-alias-err.c
@@ -0,0 +1,19 @@
+// REQUIRES: riscv-registered-target
+// RUN: not %clang_cc1 -triple riscv64 -fsyntax-only -verify \
+// RUN:   -target-feature +experimental-v %s 2>&1 \
+// RUN: | FileCheck %s
+
+#include 
+
+#define __rvv_generic \
+static inline __attribute__((__always_inline__, __nodebug__))
+
+__rvv_generic
+__attribute__((clang_builtin_alias(__builtin_rvv_vadd_vv_i8m1)))
+vint8m1_t vadd_generic (vint8m1_t op0, vint8m1_t op1, size_t op2);
+
+// CHECK: passing 'vint8m2_t' (aka '__rvv_int8m2_t') to parameter of incompatible type 'vint8m1_t'
+vint8m2_t test(vint8m2_t op0, vint8m2_t op1, size_t vl) {
+  vint8m2_t ret = vadd_generic(op0, op1, vl);
+  return ret;
+}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5120,6 +5120,7 @@
 #define GET_SVE_BUILTINS
 #define BUILTIN(name, types, attr) case SVE::BI##name:
 #include "clang/Basic/arm_sve_builtins.inc"
+#undef BUILTIN
 return

[PATCH] D101194: [Driver] Push multiarch path setup to individual drivers

2021-04-24 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D101194#2714206 , @MaskRay wrote:

>> Different platforms use different rules for multiarch triples so it's 
>> difficult to provide a single method for all platforms.
>
> Guess this is a Linux/Hurd/Fuchsia specific thing. I don't know much about 
> the runtime build but I hope the Linux hierarchy is not set in stone.
>
> Can you dump a diff how `addPathIfExists(D, getStdlibPath(), Paths);` and a 
> similar call will change `-L` paths in the linking stage?
> You can use `clang ... '-###' |& sed -E 's/ "?-L/\n&/g; s/ "?-[iI]/\n&/g'` to 
> break -L into multiple lines.

There's no difference, current behavior is already covered by tests and those 
are still passing. The difference is that `ToolChain::getRuntimePath()` and 
`ToolChain::getStdlibPath()` currently try various possible spellings of 
triples whereas with this patch that's no longer needed because each platform 
controls its own spelling so we save a few syscalls.

I checked and the multiarch runtimes layout is currently only used by Fuchsia, 
Linux and WebAssembly, other platforms use their own custom logic. If other 
platforms decide to pickup this layout as well, they can follow the same 
pattern.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101194

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


[clang] e6131f7 - [Clang] Fixup for D100611

2021-04-24 Thread Hsiangkai Wang via cfe-commits

Author: Hsiangkai Wang
Date: 2021-04-25T09:41:19+08:00
New Revision: e6131f7ee54e1660be519fc7172fbbbc2b4da803

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

LOG: [Clang] Fixup for D100611

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 9cc4c837cc49..cae9cec804ce 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4701,6 +4701,7 @@ the old mangled name and the new code will use the new 
mangled name with tags.
 
 def BuiltinAliasDocs : Documentation {
   let Category = DocCatFunction;
+  let Heading = "clang::builtin_alias, clang_builtin_alias";
   let Content = [{
 This attribute is used in the implementation of the C intrinsics.
 It allows the C intrinsic functions to be declared using the names defined



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


[PATCH] D101143: [RISCV] [1/2] Add IR intrinsic for Zbe extension

2021-04-24 Thread LevyHsu via Phabricator via cfe-commits
LevyHsu updated this revision to Diff 340322.
LevyHsu marked an inline comment as done.
LevyHsu added a comment.

1. llvm/lib/Target/RISCV/RISCVInstrInfoB.td
  - Format fix: Aligned SDT*** for:

  riscv_bcompress
riscv_bcompressw
riscv_bdecompress
riscv_bdecompressw


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101143

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbe.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbe.c
  llvm/include/llvm/IR/IntrinsicsRISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/Target/RISCV/RISCVInstrInfoB.td
  llvm/test/CodeGen/RISCV/rv32zbe-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv64zbe-intrinsic.ll

Index: llvm/test/CodeGen/RISCV/rv64zbe-intrinsic.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rv64zbe-intrinsic.ll
@@ -0,0 +1,69 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-b -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV64IB
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbe -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV64IBE
+
+declare i32 @llvm.riscv.bcompress.i32(i32 %a, i32 %b)
+
+define signext i32 @bcompress32(i32 signext %a, i32 signext %b) nounwind {
+; RV64IB-LABEL: bcompress32:
+; RV64IB:   # %bb.0:
+; RV64IB-NEXT:bcompressw a0, a0, a1
+; RV64IB-NEXT:ret
+;
+; RV64IBE-LABEL: bcompress32:
+; RV64IBE:   # %bb.0:
+; RV64IBE-NEXT:bcompressw a0, a0, a1
+; RV64IBE-NEXT:ret
+  %tmp = call i32 @llvm.riscv.bcompress.i32(i32 %a, i32 %b)
+ ret i32 %tmp
+}
+
+declare i32 @llvm.riscv.bdecompress.i32(i32 %a, i32 %b)
+
+define signext i32 @bdecompress32(i32 signext %a, i32 signext %b) nounwind {
+; RV64IB-LABEL: bdecompress32:
+; RV64IB:   # %bb.0:
+; RV64IB-NEXT:bdecompressw a0, a0, a1
+; RV64IB-NEXT:ret
+;
+; RV64IBE-LABEL: bdecompress32:
+; RV64IBE:   # %bb.0:
+; RV64IBE-NEXT:bdecompressw a0, a0, a1
+; RV64IBE-NEXT:ret
+  %tmp = call i32 @llvm.riscv.bdecompress.i32(i32 %a, i32 %b)
+ ret i32 %tmp
+}
+
+declare i64 @llvm.riscv.bcompress.i64(i64 %a, i64 %b)
+
+define i64 @bcompress64(i64 %a, i64 %b) nounwind {
+; RV64IB-LABEL: bcompress64:
+; RV64IB:   # %bb.0:
+; RV64IB-NEXT:bcompress a0, a0, a1
+; RV64IB-NEXT:ret
+;
+; RV64IBE-LABEL: bcompress64:
+; RV64IBE:   # %bb.0:
+; RV64IBE-NEXT:bcompress a0, a0, a1
+; RV64IBE-NEXT:ret
+  %tmp = call i64 @llvm.riscv.bcompress.i64(i64 %a, i64 %b)
+ ret i64 %tmp
+}
+
+declare i64 @llvm.riscv.bdecompress.i64(i64 %a, i64 %b)
+
+define i64 @bdecompress64(i64 %a, i64 %b) nounwind {
+; RV64IB-LABEL: bdecompress64:
+; RV64IB:   # %bb.0:
+; RV64IB-NEXT:bdecompress a0, a0, a1
+; RV64IB-NEXT:ret
+;
+; RV64IBE-LABEL: bdecompress64:
+; RV64IBE:   # %bb.0:
+; RV64IBE-NEXT:bdecompress a0, a0, a1
+; RV64IBE-NEXT:ret
+  %tmp = call i64 @llvm.riscv.bdecompress.i64(i64 %a, i64 %b)
+ ret i64 %tmp
+}
Index: llvm/test/CodeGen/RISCV/rv32zbe-intrinsic.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rv32zbe-intrinsic.ll
@@ -0,0 +1,37 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-b -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV32IB
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbe -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV32IBE
+
+declare i32 @llvm.riscv.bcompress.i32(i32 %a, i32 %b)
+
+define i32 @bcompress32(i32 %a, i32 %b) nounwind {
+; RV32IB-LABEL: bcompress32:
+; RV32IB:   # %bb.0:
+; RV32IB-NEXT:bcompress a0, a0, a1
+; RV32IB-NEXT:ret
+;
+; RV32IBE-LABEL: bcompress32:
+; RV32IBE:   # %bb.0:
+; RV32IBE-NEXT:bcompress a0, a0, a1
+; RV32IBE-NEXT:ret
+  %tmp = call i32 @llvm.riscv.bcompress.i32(i32 %a, i32 %b)
+ ret i32 %tmp
+}
+
+declare i32 @llvm.riscv.bdecompress.i32(i32 %a, i32 %b)
+
+define i32 @bdecompress32(i32 %a, i32 %b) nounwind {
+; RV32IB-LABEL: bdecompress32:
+; RV32IB:   # %bb.0:
+; RV32IB-NEXT:bdecompress a0, a0, a1
+; RV32IB-NEXT:ret
+;
+; RV32IBE-LABEL: bdecompress32:
+; RV32IBE:   # %bb.0:
+; RV32IBE-NEXT:bdecompress a0, a0, a1
+; RV32IBE-NEXT:ret
+  %tmp = call i32 @llvm.riscv.bdecompress.i32(i32 %a, i32 %b)
+ ret i32 %tmp
+}
Index: llvm/lib/Target/RISCV/RISCVInstrInfoB.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfoB.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfoB.td
@@ -33,6 +33,10 @@
 def riscv_shflw  : SDNode<"RISCVISD::SHFLW",  SDT_RISCVIntBinOpW>;
 def riscv_unshfl : SDNode<"

[PATCH] D97265: [clang] Allow clang-check to customize analyzer output file or dir name

2021-04-24 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie added a comment.

ping @sammccall again

Do I need to add other reviewers if you are busy doing your job?


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

https://reviews.llvm.org/D97265

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