[PATCH] D10833: Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface

2019-04-28 Thread Ian Sunamura via Phabricator via cfe-commits
kent08ian added a comment.

In D10833#1366117 , @schroedersi wrote:

> Ping. It would indeed be very helpful to have information about the kind of 
> an operator :-)


Any updates on this?


Repository:
  rC Clang

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

https://reviews.llvm.org/D10833



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


[PATCH] D61246: [analyzer][UninitializedObjectChecker] PR41611: Regard vector types as primitive

2019-04-28 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, dcoughlin, xazax.hun, rnkovacs, 
baloghadamsoftware, Charusso, alexfh, gribozavr.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, gamesh411, dkrupp, donat.nagy, jfb, 
mikhail.ramalho, a.sidorin, szepet, whisperity.

https://bugs.llvm.org/show_bug.cgi?id=41611

Similarly to D61106 , the checker ran over an 
`llvm_unreachable` for vector types:

  struct VectorSizeLong {
VectorSizeLong() {}
__attribute__((__vector_size__(16))) long x;
  };
  
  void __vector_size__LongTest() {
VectorSizeLong v;
  }

Since, according to my short research 
,

> The `vector_size` attribute is only applicable to integral and float scalars, 
> although arrays, pointers, and function return values are allowed in 
> conjunction with this construct.

vector types are safe to regard as primitive.


Repository:
  rC Clang

https://reviews.llvm.org/D61246

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
  test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
  test/Analysis/cxx-uninitialized-object.cpp


Index: test/Analysis/cxx-uninitialized-object.cpp
===
--- test/Analysis/cxx-uninitialized-object.cpp
+++ test/Analysis/cxx-uninitialized-object.cpp
@@ -1132,7 +1132,7 @@
 }
 
 
//===--===//
-// _Atomic tests.
+// "Esoteric" primitive type tests.
 
//===--===//
 
 struct MyAtomicInt {
@@ -1142,6 +1142,15 @@
   MyAtomicInt() {} // expected-warning{{1 uninitialized field}}
 };
 
-void entry() {
+void _AtomicTest() {
   MyAtomicInt b;
 }
+
+struct VectorSizeLong {
+  VectorSizeLong() {}
+  __attribute__((__vector_size__(16))) long x;
+};
+
+void __vector_size__LongTest() {
+  VectorSizeLong v;
+}
Index: test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===
--- test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -256,6 +256,28 @@
   CharPointerTest();
 }
 
+struct VectorSizePointer {
+  VectorSizePointer() {} // expected-warning{{1 uninitialized field}}
+  __attribute__((__vector_size__(8))) int *x; // expected-note{{uninitialized 
pointer 'this->x'}}
+  int dontGetFilteredByNonPedanticMode = 0;
+};
+
+void __vector_size__PointerTest() {
+  VectorSizePointer v;
+}
+
+struct VectorSizePointee {
+  using MyVectorType = __attribute__((__vector_size__(8))) int;
+  MyVectorType *x;
+
+  VectorSizePointee(decltype(x) x) : x(x) {}
+};
+
+void __vector_size__PointeeTest() {
+  VectorSizePointee::MyVectorType i;
+  VectorSizePointee v();
+}
+
 struct CyclicPointerTest1 {
   int *ptr; // expected-note{{object references itself 'this->ptr'}}
   int dontGetFilteredByNonPedanticMode = 0;
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
@@ -324,7 +324,8 @@
 inline bool isPrimitiveType(const QualType ) {
   return T->isBuiltinType() || T->isEnumeralType() ||
  T->isMemberPointerType() || T->isBlockPointerType() ||
- T->isFunctionType() || T->isAtomicType();
+ T->isFunctionType() || T->isAtomicType() ||
+ T->isVectorType();
 }
 
 inline bool isDereferencableType(const QualType ) {


Index: test/Analysis/cxx-uninitialized-object.cpp
===
--- test/Analysis/cxx-uninitialized-object.cpp
+++ test/Analysis/cxx-uninitialized-object.cpp
@@ -1132,7 +1132,7 @@
 }
 
 //===--===//
-// _Atomic tests.
+// "Esoteric" primitive type tests.
 //===--===//
 
 struct MyAtomicInt {
@@ -1142,6 +1142,15 @@
   MyAtomicInt() {} // expected-warning{{1 uninitialized field}}
 };
 
-void entry() {
+void _AtomicTest() {
   MyAtomicInt b;
 }
+
+struct VectorSizeLong {
+  VectorSizeLong() {}
+  __attribute__((__vector_size__(16))) long x;
+};
+
+void __vector_size__LongTest() {
+  VectorSizeLong v;
+}
Index: test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===
--- test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -256,6 +256,28 @@
   CharPointerTest();
 }
 
+struct VectorSizePointer {
+  VectorSizePointer() {} // expected-warning{{1 uninitialized field}}
+  __attribute__((__vector_size__(8))) int *x; // expected-note{{uninitialized 

[PATCH] D60934: [clang] adding explicit(bool) from c++2a

2019-04-28 Thread Tyker via Phabricator via cfe-commits
Tyker marked an inline comment as done.
Tyker added a comment.

Fixed based on Feedback from @rsmith @martong @Rakete.

feedback that weren't fixed have comment explaining why.




Comment at: clang/include/clang/AST/DeclCXX.h:2033
+
+  void setExplicitSpecifier(ExplicitSpecInfo ESI);
+

Tyker wrote:
> rsmith wrote:
> > Generally we don't want to have setters in the AST; the AST is intended to 
> > be immutable after creation. Is this necessary?
> this is used in 2 cases:
> - for deserialization.
> - for in `Sema::ActOnFunctionDeclarator` to make every declaration of the 
> same function have the same explicit specifier as the canonical one. there is 
> probably a better way to do this but i didn't find how.
> 
> the second use case will need to be changed because the constructor's 
> explicit specifier will be tail-allocated so the explicit specifier from the 
> canonical declaration will need to be recovered before construction to 
> allocate storage. 
> 
> how can we find the canonical declaration of a function before it is 
> constructed ?
i found a solution around that issue.
now setExplicitSpecifier is only used for deserialization.



Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:40
+def note_explicit_bool_breaking_change_cxx2a : Note<
+  "this expression is parsed as explicit(bool) since C++2a">;
+

rsmith wrote:
> This should be a warning in the `CXXPre2aCompat` group, phrased as 
> "explicit(bool) is incompatible with C++ standards before C++2a".
explicit(bool) can only be parse with the c++2a option because code like:
```
 struct C {
  explicit(C)(int);
 };
```
is correct before c++2a but is parsed as explicit(bool) and fail to complie in 
c++2a.
so i don't think this warning can be fired in any case. so i removed it.



Comment at: clang/lib/Parse/ParseDecl.cpp:3533
+  if (ExplicitExpr.isInvalid()) {
+Diag(ParenLoc, diag::note_explicit_bool_breaking_change_cxx2a)
+<< FixItHint::CreateReplacement(

rsmith wrote:
> Rakete wrote:
> > This is a useful diagnostic but you'll need to fix (a lot) of false 
> > positives:
> > 
> > ```
> > template  struct Foo { explicit(T{} +) Foo(); };
> > ```
> > 
> > gets me:
> > 
> > ```
> > main.cpp:1:50: error: expected expression
> > template  struct Foo { explicit(T{} +) Foo(); };
> >  ^
> > main.cpp:1:44: note: this expression is parsed as explicit(bool) since C++2a
> > template  struct Foo { explicit(T{} +) Foo(); };
> >^
> >explicit(true)
> > ```
> > 
> > Fixit hints should only be used when it is 100% the right fix that works, 
> > always.
> This "add a note after an error" construct is an anti-pattern, and will fail 
> in a bunch of cases (for example: if multiple diagnostics are produced, it 
> gets attached to the last one rather than the first; if a disabled warning / 
> remark is produced last, the note is not displayed at all).
> 
> As noted above, the conventional way to handle this is to unconditionally 
> produce a `-Wc++17-compat` warning when we see `explicit(`. Attaching a 
> context note to the diagnostic if building the expression fails (catching 
> both `Parse` and `Sema` diagnostics) will require more invasive changes and 
> I'd prefer to see that left to a separate patch (if we do it at all).
after the comment from rsmith i will remove it at least for now.



Comment at: clang/lib/Sema/SemaInit.cpp:9361
 // Only consider converting constructors.
-if (GD->isExplicit())
+if (!GD->isMaybeNotExplicit())
   continue;

rsmith wrote:
> We need to substitute into the deduction guide first to detect whether it 
> forms a "converting constructor", and that will need to be done inside 
> `AddTemplateOverloadCandidate`.
similarly as the previous if. this check removes deduction guide that are 
already resolve to be explicit when we are in a context that doesn't allow 
explicit.
every time the explicitness was checked before my change i replaced it by a 
check that removes already resolved explicit specifiers.



Comment at: clang/test/SemaCXX/cxx2a-compat.cpp:51
+#else
+// expected-error@-8 {{does not refer to a value}}
+// expected-error@-9 {{expected member name or ';'}}

Rakete wrote:
> A fixit hint for this would be great. Also it would be nice if there was a 
> nicer error message.
this had a fix it in the previous patch with the "this expression is parsed as 
explicit(bool) since C++2a" note. but i removed it because to much false 
positive and fixing it would make the patch even bigger.


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

https://reviews.llvm.org/D60934



___
cfe-commits mailing list

[PATCH] D60953: [clangd] Respect clang-tidy suppression comments

2019-04-28 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 197040.
nridge marked 3 inline comments as done.
nridge added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60953

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clangd/ClangdUnit.cpp
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h

Index: clang-tools-extra/clangd/Diagnostics.h
===
--- clang-tools-extra/clangd/Diagnostics.h
+++ clang-tools-extra/clangd/Diagnostics.h
@@ -113,16 +113,23 @@
 
   using DiagFixer = std::function(DiagnosticsEngine::Level,
const clang::Diagnostic &)>;
+  using DiagFilter =
+  std::function;
   /// If set, possibly adds fixes for diagnostics using \p Fixer.
   void contributeFixes(DiagFixer Fixer) { this->Fixer = Fixer; }
+  /// If set, ignore diagnostics for which \p Filter returns false.
+  void filterDiagnostics(DiagFilter Filter) { this->Filter = Filter; }
 
 private:
   void flushLastDiag();
 
   DiagFixer Fixer = nullptr;
+  DiagFilter Filter = nullptr;
   std::vector Output;
   llvm::Optional LangOpts;
   llvm::Optional LastDiag;
+  bool LastErrorWasIgnored = false;
 };
 
 } // namespace clangd
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -311,8 +311,17 @@
 return;
   }
 
+  if (LastErrorWasIgnored && DiagLevel == DiagnosticsEngine::Note)
+return;
+
   bool InsideMainFile = isInsideMainFile(Info);
 
+  if (Filter && !Filter(DiagLevel, Info, InsideMainFile)) {
+LastErrorWasIgnored = true;
+return;
+  }
+  LastErrorWasIgnored = false;
+
   auto FillDiagBase = [&](DiagBase ) {
 D.Range = diagnosticRange(Info, *LangOpts);
 llvm::SmallString<64> Message;
Index: clang-tools-extra/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/clangd/ClangdUnit.cpp
+++ clang-tools-extra/clangd/ClangdUnit.cpp
@@ -237,6 +237,40 @@
   const LangOptions 
 };
 
+// A wrapper around StoreDiags to handle suppression comments for
+// clang-tidy diagnostics (and possibly other clang-tidy customizations in the
+// future).
+class ClangdDiagnosticConsumer : public StoreDiags {
+public:
+  ClangdDiagnosticConsumer() {
+filterDiagnostics([this](DiagnosticsEngine::Level DiagLevel,
+ const clang::Diagnostic ,
+ bool IsInsideMainFile) {
+  if (CTContext) {
+bool isClangTidyDiag = !CTContext->getCheckName(Info.getID()).empty();
+// Skip the ShouldSuppressDiagnostic check for diagnostics not in
+// the main file, because we don't want that function to query the
+// source buffer for preamble files. For the same reason, we ask
+// ShouldSuppressDiagnostic not to follow macro expansions, since those
+// might take us into a preamble file as well.
+if (isClangTidyDiag && IsInsideMainFile &&
+tidy::ShouldSuppressDiagnostic(DiagLevel, Info, *CTContext,
+   /* CheckMacroExpansion = */ false)) {
+  return false;
+}
+  }
+  return true;
+});
+  }
+
+  void setClangTidyContext(tidy::ClangTidyContext *CTContext) {
+this->CTContext = CTContext;
+  }
+
+private:
+  tidy::ClangTidyContext *CTContext = nullptr;
+};
+
 } // namespace
 
 void dumpAST(ParsedAST , llvm::raw_ostream ) {
@@ -256,7 +290,7 @@
   const PrecompiledPreamble *PreamblePCH =
   Preamble ? >Preamble : nullptr;
 
-  StoreDiags ASTDiags;
+  ClangdDiagnosticConsumer ASTDiags;
   std::string Content = Buffer->getBuffer();
 
   auto Clang = prepareCompilerInstance(std::move(CI), PreamblePCH,
@@ -294,6 +328,7 @@
 CTContext->setASTContext(>getASTContext());
 CTContext->setCurrentFile(MainInput.getFile());
 CTFactories.createChecks(CTContext.getPointer(), CTChecks);
+ASTDiags.setClangTidyContext(CTContext.getPointer());
 Preprocessor *PP = >getPreprocessor();
 for (const auto  : CTChecks) {
   // FIXME: the PP callbacks skip the entire preamble.
Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
===
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -217,6 +217,23 @@
   bool AllowEnablingAnalyzerAlphaCheckers;
 };
 
+/// Check whether a given diagnostic should be suppressed due to the presence
+/// of a "NOLINT" suppression comment.
+/// This is exposed so that other tools that present clang-tidy diagnostics
+/// (such as 

[PATCH] D60953: [clangd] Respect clang-tidy suppression comments

2019-04-28 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:395
+ DiagLevel != DiagnosticsEngine::Fatal &&
+ LineIsMarkedWithNOLINTinMacro(Info.getSourceManager(),
+   Info.getLocation(), Info.getID(),

sammccall wrote:
> There may be a trap here for clangd.
> 
> When building an AST with a preamble (which is when we run clang-tidy 
> checks), the source code of the main file is mapped in the SourceManager as 
> usual, but headers are not.
> An attempt to get the buffer results in the SourceManager reading the file 
> from disk. If the content has changed then all sorts of invariants break and 
> clang will typically crash.
> 
> @ilya-biryukov knows the details here better than me.
> 
> Of course this is only true for trying to read from header file locations, 
> and we only run clang-tidy over main-file-decls. But:
>  - clang-tidy checks can emit diagnostics anywhere, even outside the AST 
> range they run over directly
>  - while StoreDiags does filter out diagnostics that aren't in the main file, 
> this is pretty nuanced (e.g. a note in the main file is sufficient to 
> include) and this logic runs after the filtering added by this patch
>  - the way that LineIsMarkedWithNOLINTinMacro loops suggests that even if the 
> diagnostic is in the main-file, we'll look for NOLINT in other files
> 
> Maybe this means we can't accurately calculate suppression for clang-tidy 
> warnings in macro locations, or outside the main file. I think *always* 
> filtering these out (on the clangd side) might be OK.
Thanks for pointing this out! This should be addressed in the updated patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60953



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


[PATCH] D61232: [libclang] Restore old clang_Cursor_isAnonymous behaviour

2019-04-28 Thread Jorn Vernee via Phabricator via cfe-commits
JornVernee updated this revision to Diff 197038.
JornVernee added a comment.

Incremented minor version


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

https://reviews.llvm.org/D61232

Files:
  include/clang-c/Index.h
  test/Index/print-type.c
  tools/c-index-test/c-index-test.c
  tools/libclang/CXType.cpp

Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -1253,6 +1253,16 @@
 
   return 0;
 }
+
+unsigned clang_Cursor_isAnonymousRecordDecl(CXCursor C){
+  if (!clang_isDeclaration(C.kind))
+return 0;
+  const Decl *D = cxcursor::getCursorDecl(C);
+  if (const RecordDecl *FD = dyn_cast_or_null(D))
+return FD->isAnonymousStructOrUnion();
+  return 0;
+}
+
 CXType clang_Type_getNamedType(CXType CT){
   QualType T = GetQualType(CT);
   const Type *TP = T.getTypePtrOrNull();
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1665,6 +1665,12 @@
   }
 }
 
+/* Print if it is an anonymous record decl */
+{
+  unsigned isAnonRecDecl = clang_Cursor_isAnonymousRecordDecl(cursor);
+  printf(" [isAnonRecDecl=%d]", isAnonRecDecl);
+}
+
 printf("\n");
   }
   return CXChildVisit_Recurse;
Index: test/Index/print-type.c
===
--- test/Index/print-type.c
+++ test/Index/print-type.c
@@ -15,6 +15,20 @@
 enum Enum{i}; enum Enum elaboratedEnumType();
 struct Struct{}; struct Struct elaboratedStructType();
 
+struct {
+  int x;
+  int y;
+} foo;
+
+struct {
+  struct {
+int x;
+int y;
+  };
+} bar;
+
+void fun(struct { int x; int y; } *param);
+
 // RUN: c-index-test -test-print-type %s | FileCheck %s
 // CHECK: FunctionDecl=f:3:6 (Definition) [type=int *(int *, char *, FooType, int *, void (*)(int))] [typekind=FunctionProto] [canonicaltype=int *(int *, char *, int, int *, void (*)(int))] [canonicaltypekind=FunctionProto] [resulttype=int *] [resulttypekind=Pointer] [args= [int *] [Pointer] [char *] [Pointer] [FooType] [Typedef] [int [5]] [ConstantArray] [void (*)(int)] [Pointer]] [isPOD=0]
 // CHECK: ParmDecl=p:3:13 (Definition) [type=int *] [typekind=Pointer] [isPOD=1] [pointeetype=int] [pointeekind=Int]
@@ -53,3 +67,7 @@
 // CHECK: StructDecl=Struct:16:8 (Definition) [type=struct Struct] [typekind=Record] [isPOD=1]
 // CHECK: FunctionDecl=elaboratedStructType:16:32 [type=struct Struct ()] [typekind=FunctionNoProto] [canonicaltype=struct Struct ()] [canonicaltypekind=FunctionNoProto] [resulttype=struct Struct] [resulttypekind=Elaborated] [isPOD=0]
 // CHECK: TypeRef=struct Struct:16:8 [type=struct Struct] [typekind=Record] [isPOD=1]
+// CHECK: StructDecl=:18:1 (Definition) [type=struct (anonymous at {{.*}}print-type.c:18:1)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=0]
+// CHECK: StructDecl=:23:1 (Definition) [type=struct (anonymous at {{.*}}print-type.c:23:1)] [typekind=Record] [isPOD=1] [nbFields=1] [isAnon=1] [isAnonRecDecl=0]
+// CHECK: StructDecl=:24:3 (Definition) [type=struct (anonymous at {{.*}}print-type.c:24:3)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=1]
+// CHECK: StructDecl=:30:10 (Definition) [type=struct (anonymous at {{.*}}print-type.c:30:10)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=0]
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 55
+#define CINDEX_VERSION_MINOR 56
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -3920,11 +3920,17 @@
  */
 CINDEX_LINKAGE long long clang_Cursor_getOffsetOfField(CXCursor C);
 
+/**
+ * Determine whether the given cursor represents an anonymous
+ * tag or namespace
+ */
+CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C);
+
 /**
  * Determine whether the given cursor represents an anonymous record
  * declaration.
  */
-CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C);
+CINDEX_LINKAGE unsigned clang_Cursor_isAnonymousRecordDecl(CXCursor C);
 
 enum CXRefQualifierKind {
   /** No ref-qualifier was provided. */
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61232: [libclang] Restore old clang_Cursor_isAnonymous behaviour

2019-04-28 Thread Jorn Vernee via Phabricator via cfe-commits
JornVernee marked an inline comment as done.
JornVernee added a comment.

No worries! I'm already glad there's someone who picked up the review for this 
so quickly ;)


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

https://reviews.llvm.org/D61232



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


[PATCH] D61232: [libclang] Restore old clang_Cursor_isAnonymous behaviour

2019-04-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

Thank you! Sorry that I forgot about the required minor version increment.
I will run tests tomorrow and then I can commit it for you.




Comment at: include/clang-c/Index.h:35
 #define CINDEX_VERSION_MAJOR 0
 #define CINDEX_VERSION_MINOR 55
 

We also need to increment the minor version because of the new function added.


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

https://reviews.llvm.org/D61232



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


[PATCH] D55793: [clang-tidy] Add duplicated access specifier readability check (PR25403)

2019-04-28 Thread Mateusz Maćkowski via Phabricator via cfe-commits
m4tx updated this revision to Diff 197028.
m4tx marked 5 inline comments as done.
m4tx added a comment.

Remove the accidentally added patch file


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

https://reviews.llvm.org/D55793

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability-redundant-access-specifiers.rst
  
clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers-check-first-declaration.cpp
  clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers.cpp

Index: clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers.cpp
@@ -0,0 +1,116 @@
+// RUN: %check_clang_tidy %s readability-redundant-access-specifiers %t
+
+class FooPublic {
+public:
+  int a;
+public: // comment-0
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-0{{$}}
+  int b;
+private:
+  int c;
+};
+
+struct StructPublic {
+public:
+  int a;
+public: // comment-1
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-1{{$}}
+  int b;
+private:
+  int c;
+};
+
+union UnionPublic {
+public:
+  int a;
+public: // comment-2
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-2{{$}}
+  int b;
+private:
+  int c;
+};
+
+class FooProtected {
+protected:
+  int a;
+protected: // comment-3
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-3{{$}}
+  int b;
+private:
+  int c;
+};
+
+class FooPrivate {
+private:
+  int a;
+private: // comment-4
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-4{{$}}
+  int b;
+public:
+  int c;
+};
+
+class FooMacro {
+private:
+  int a;
+#if defined(ZZ)
+  public:
+  int b;
+#endif
+private: // comment-5
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-8]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-5{{$}}
+  int c;
+protected:
+  int d;
+public:
+  int e;
+};
+
+class Valid {
+private:
+  int a;
+public:
+  int b;
+private:
+  int c;
+protected:
+  int d;
+public:
+  int e;
+};
+
+class ValidInnerClass {
+public:
+  int a;
+
+  class Inner {
+  public:
+int b;
+  };
+};
+
+#define MIXIN private: int b;
+
+class ValidMacro {
+private:
+  int a;
+MIXIN
+private:
+  int c;
+protected:
+  int d;
+public:
+  int e;
+};
Index: clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers-check-first-declaration.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers-check-first-declaration.cpp
@@ -0,0 +1,43 @@
+// RUN: %check_clang_tidy %s readability-redundant-access-specifiers %t -- \
+// RUN:   -config="{CheckOptions: [{key: readability-redundant-access-specifiers.CheckFirstDeclaration, value: 1}]}" --
+
+class FooPublic {
+private: // comment-0
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the implicit access specifier [readability-redundant-access-specifiers]
+  // CHECK-FIXES: {{^}}// comment-0{{$}}
+  int a;
+};
+
+struct StructPublic {
+public: // comment-1
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the implicit access specifier 

[PATCH] D55793: [clang-tidy] Add duplicated access specifier readability check (PR25403)

2019-04-28 Thread Mateusz Maćkowski via Phabricator via cfe-commits
m4tx marked 15 inline comments as done.
m4tx added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.cpp:35-36
+  for (DeclContext::specific_decl_iterator
+   AS(MatchedDecl->decls_begin()),
+   ASEnd(MatchedDecl->decls_end());
+   AS != ASEnd; ++AS) {

aaron.ballman wrote:
> I have a slight preference for using assignment operators here rather than 
> explicit constructor calls.
This is not possible here as specific_decl_iterator has the copy constructor 
marked as `explicit`.



Comment at: 
clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.cpp:54
+if (ASDecl->getAccess() == DefaultSpecifier) {
+  diag(ASDecl->getLocation(), "redundant access specifier")
+  << FixItHint::CreateRemoval(ASDecl->getSourceRange());

aaron.ballman wrote:
> This is a bit terse, how about: `redundant access specifier has the same 
> accessibility as the implicit access specifier`?
Sounds good, changed this in the latest revision.



Comment at: 
clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.cpp:69
+
+  diag(ASDecl->getLocation(), "duplicated access specifier")
+  << FixItHint::CreateRemoval(ASDecl->getSourceRange());

aaron.ballman wrote:
> This is a bit terse, how about: `redundant access specifier has the same 
> accessibility as the previous access specifier`?
As above.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability-redundant-access-specifiers.rst:6
+
+Finds classes, structs and unions containing redundant member access 
specifiers.
+

aaron.ballman wrote:
> structs and unions -> structs, and unions
> 
> One thing the docs leave unclear is which access specifiers you're talking 
> about. Currently, the check only cares about the access specifiers for 
> fields, but it seems reasonable that the check could also be talking about 
> access specifiers on base class specifiers. e.g.,
> ```
> struct Base {
>   int a, b;
> };
> 
> class C : private Base { // The 'private' here is redundant.
> };
> ```
> You should probably clarify this in the docs. Implementing this functionality 
> may or may not be useful, but if you want to implement it, you could do it in 
> a follow-up patch.
This is actually included in the documentation (*member* access specifier), but 
I've added explicit "field and method" clarification.



Comment at: 
clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers.cpp:71-72
+private: // comment-5
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: duplicated access specifier 
[readability-redundant-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-8]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-5{{$}}

aaron.ballman wrote:
> I think that diagnosing here is unfortunate. If the user defines `ZZ`, then 
> the access specifier is no longer redundant. However, it may not be easy for 
> you to handle this case when `ZZ` is not defined because the access specifier 
> will have been removed by the preprocessor.
I agree, but I think that we cannot do anything reasonable here. The code is 
removed by the preprocessor, and I believe the only behavior that would make 
sense would be to completely suppress the warnings if there is a preprocessor 
directive between the last access specifier and the current one. However, if 
I'm not mistaken, there is no way in clang-tidy to detect that.


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

https://reviews.llvm.org/D55793



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


[PATCH] D61239: [libclang] Allow field offset lookups in types with incomplete arrays.

2019-04-28 Thread Jorn Vernee via Phabricator via cfe-commits
JornVernee updated this revision to Diff 197024.
JornVernee added a comment.

Fixed the similar problem with `clang_Type_getAlignOf` since the patch is 
pretty small any ways.


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

https://reviews.llvm.org/D61239

Files:
  test/Index/print-type-size.c
  tools/libclang/CXType.cpp


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -895,7 +895,7 @@
   // [expr.alignof] p3: if reference type, return size of referenced type
   if (QT->isReferenceType())
 QT = QT.getNonReferenceType();
-  if (QT->isIncompleteType())
+  if (QT->isIncompleteType() && !QT->isIncompleteArrayType()) // IAT is okay 
here
 return CXTypeLayoutError_Incomplete;
   if (QT->isDependentType())
 return CXTypeLayoutError_Dependent;
@@ -953,7 +953,7 @@
 static long long visitRecordForValidation(const RecordDecl *RD) {
   for (const auto *I : RD->fields()){
 QualType FQT = I->getType();
-if (FQT->isIncompleteType())
+if (FQT->isIncompleteType() && !FQT->isIncompleteArrayType()) // IAT is 
okay here
   return CXTypeLayoutError_Incomplete;
 if (FQT->isDependentType())
   return CXTypeLayoutError_Dependent;
Index: test/Index/print-type-size.c
===
--- /dev/null
+++ test/Index/print-type-size.c
@@ -0,0 +1,30 @@
+struct Foo {
+int size;
+void* data[]; // incomplete array
+};
+
+struct Bar {
+int size;
+struct {
+int dummy;
+void* data[]; // incomplete array
+};
+};
+
+struct Baz {
+int size;
+union {
+void* data1[]; // incomplete array
+void* data2[]; // incomplete array
+};
+};
+
+// RUN: c-index-test -test-print-type-size %s | FileCheck %s
+// CHECK: FieldDecl=size:2:9 (Definition) [type=int] [typekind=Int] [sizeof=4] 
[alignof=4] [offsetof=0]
+// CHECK: FieldDecl=data:3:11 (Definition) [type=void *[]] 
[typekind=IncompleteArray] [sizeof=-2] [alignof=8] [offsetof=64]
+// CHECK: FieldDecl=size:7:9 (Definition) [type=int] [typekind=Int] [sizeof=4] 
[alignof=4] [offsetof=0]
+// CHECK: FieldDecl=dummy:9:13 (Definition) [type=int] [typekind=Int] 
[sizeof=4] [alignof=4] [offsetof=64/0]
+// CHECK: FieldDecl=data:10:15 (Definition) [type=void *[]] 
[typekind=IncompleteArray] [sizeof=-2] [alignof=8] [offsetof=128/64]
+// CHECK: FieldDecl=size:15:9 (Definition) [type=int] [typekind=Int] 
[sizeof=4] [alignof=4] [offsetof=0]
+// CHECK: FieldDecl=data1:17:15 (Definition) [type=void *[]] 
[typekind=IncompleteArray] [sizeof=-2] [alignof=8] [offsetof=64/0]
+// CHECK: FieldDecl=data2:18:15 (Definition) [type=void *[]] 
[typekind=IncompleteArray] [sizeof=-2] [alignof=8] [offsetof=64/0]
\ No newline at end of file


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -895,7 +895,7 @@
   // [expr.alignof] p3: if reference type, return size of referenced type
   if (QT->isReferenceType())
 QT = QT.getNonReferenceType();
-  if (QT->isIncompleteType())
+  if (QT->isIncompleteType() && !QT->isIncompleteArrayType()) // IAT is okay here
 return CXTypeLayoutError_Incomplete;
   if (QT->isDependentType())
 return CXTypeLayoutError_Dependent;
@@ -953,7 +953,7 @@
 static long long visitRecordForValidation(const RecordDecl *RD) {
   for (const auto *I : RD->fields()){
 QualType FQT = I->getType();
-if (FQT->isIncompleteType())
+if (FQT->isIncompleteType() && !FQT->isIncompleteArrayType()) // IAT is okay here
   return CXTypeLayoutError_Incomplete;
 if (FQT->isDependentType())
   return CXTypeLayoutError_Dependent;
Index: test/Index/print-type-size.c
===
--- /dev/null
+++ test/Index/print-type-size.c
@@ -0,0 +1,30 @@
+struct Foo {
+int size;
+void* data[]; // incomplete array
+};
+
+struct Bar {
+int size;
+struct {
+int dummy;
+void* data[]; // incomplete array
+};
+};
+
+struct Baz {
+int size;
+union {
+void* data1[]; // incomplete array
+void* data2[]; // incomplete array
+};
+};
+
+// RUN: c-index-test -test-print-type-size %s | FileCheck %s
+// CHECK: FieldDecl=size:2:9 (Definition) [type=int] [typekind=Int] [sizeof=4] [alignof=4] [offsetof=0]
+// CHECK: FieldDecl=data:3:11 (Definition) [type=void *[]] [typekind=IncompleteArray] [sizeof=-2] [alignof=8] [offsetof=64]
+// CHECK: FieldDecl=size:7:9 (Definition) [type=int] [typekind=Int] [sizeof=4] [alignof=4] [offsetof=0]
+// CHECK: FieldDecl=dummy:9:13 (Definition) [type=int] [typekind=Int] [sizeof=4] [alignof=4] [offsetof=64/0]
+// CHECK: FieldDecl=data:10:15 (Definition) [type=void *[]] [typekind=IncompleteArray] [sizeof=-2] [alignof=8] [offsetof=128/64]
+// CHECK: FieldDecl=size:15:9 (Definition) [type=int] 

[PATCH] D55793: [clang-tidy] Add duplicated access specifier readability check (PR25403)

2019-04-28 Thread Mateusz Maćkowski via Phabricator via cfe-commits
m4tx updated this revision to Diff 197025.
m4tx added a comment.

Updated per @aaron.ballman comments


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

https://reviews.llvm.org/D55793

Files:
  0001-clang-tidy-Add-duplicated-access-specifier-readabili.patch
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability-redundant-access-specifiers.rst
  
clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers-check-first-declaration.cpp
  clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers.cpp

Index: clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers.cpp
@@ -0,0 +1,116 @@
+// RUN: %check_clang_tidy %s readability-redundant-access-specifiers %t
+
+class FooPublic {
+public:
+  int a;
+public: // comment-0
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-0{{$}}
+  int b;
+private:
+  int c;
+};
+
+struct StructPublic {
+public:
+  int a;
+public: // comment-1
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-1{{$}}
+  int b;
+private:
+  int c;
+};
+
+union UnionPublic {
+public:
+  int a;
+public: // comment-2
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-2{{$}}
+  int b;
+private:
+  int c;
+};
+
+class FooProtected {
+protected:
+  int a;
+protected: // comment-3
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-3{{$}}
+  int b;
+private:
+  int c;
+};
+
+class FooPrivate {
+private:
+  int a;
+private: // comment-4
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-4{{$}}
+  int b;
+public:
+  int c;
+};
+
+class FooMacro {
+private:
+  int a;
+#if defined(ZZ)
+  public:
+  int b;
+#endif
+private: // comment-5
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
+  // CHECK-MESSAGES: :[[@LINE-8]]:1: note: previously declared here
+  // CHECK-FIXES: {{^}}// comment-5{{$}}
+  int c;
+protected:
+  int d;
+public:
+  int e;
+};
+
+class Valid {
+private:
+  int a;
+public:
+  int b;
+private:
+  int c;
+protected:
+  int d;
+public:
+  int e;
+};
+
+class ValidInnerClass {
+public:
+  int a;
+
+  class Inner {
+  public:
+int b;
+  };
+};
+
+#define MIXIN private: int b;
+
+class ValidMacro {
+private:
+  int a;
+MIXIN
+private:
+  int c;
+protected:
+  int d;
+public:
+  int e;
+};
Index: clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers-check-first-declaration.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers-check-first-declaration.cpp
@@ -0,0 +1,43 @@
+// RUN: %check_clang_tidy %s readability-redundant-access-specifiers %t -- \
+// RUN:   -config="{CheckOptions: [{key: readability-redundant-access-specifiers.CheckFirstDeclaration, value: 1}]}" --
+
+class FooPublic {
+private: // comment-0
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the implicit access specifier [readability-redundant-access-specifiers]
+  // CHECK-FIXES: {{^}}// comment-0{{$}}
+  int a;
+};
+
+struct StructPublic {
+public: // comment-1
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the implicit access specifier 

[PATCH] D61239: [libclang] Allow field offset lookups in types with incomplete arrays.

2019-04-28 Thread Jorn Vernee via Phabricator via cfe-commits
JornVernee created this revision.
JornVernee added reviewers: akyrtzi, aaron.ballman, rsmith.
JornVernee added a project: clang.
Herald added subscribers: arphaman, dexonsmith.

Currently, looking up the offset of a field in a type with an incomplete array, 
using `clang_Type_getOffsetOf` always returns `CXTypeLayoutError_Incomplete`. 
e.g. for the following:

  struct Foo {
  int size;
  void* data[]; // incomplete array
  };

This returns `CXTypeLayoutError_Incomplete` when looking up the offset of 
either the 'size' or the 'data' field.

But, since an incomplete array always appears at the end of a record, looking 
up the field offsets should be fine. Note that this also works fine using the 
offsetof macro.

The fix for this is to ignore incomplete array fields when doing the recursive 
type validation.


https://reviews.llvm.org/D61239

Files:
  test/Index/print-type-size.c
  tools/libclang/CXType.cpp


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -953,7 +953,7 @@
 static long long visitRecordForValidation(const RecordDecl *RD) {
   for (const auto *I : RD->fields()){
 QualType FQT = I->getType();
-if (FQT->isIncompleteType())
+if (FQT->isIncompleteType() && !FQT->isIncompleteArrayType()) // IAT is 
okay here
   return CXTypeLayoutError_Incomplete;
 if (FQT->isDependentType())
   return CXTypeLayoutError_Dependent;
Index: test/Index/print-type-size.c
===
--- /dev/null
+++ test/Index/print-type-size.c
@@ -0,0 +1,30 @@
+struct Foo {
+int size;
+void* data[]; // incomplete array
+};
+
+struct Bar {
+int size;
+struct {
+int dummy;
+void* data[]; // incomplete array
+};
+};
+
+struct Baz {
+int size;
+union {
+void* data1[]; // incomplete array
+void* data2[]; // incomplete array
+};
+};
+
+// RUN: c-index-test -test-print-type-size %s | FileCheck %s
+// CHECK: FieldDecl=size:2:9 (Definition) [type=int] [typekind=Int] [sizeof=4] 
[alignof=4] [offsetof=0]
+// CHECK: FieldDecl=data:3:11 (Definition) [type=void *[]] 
[typekind=IncompleteArray] [sizeof=-2] [alignof=-2] [offsetof=64]
+// CHECK: FieldDecl=size:7:9 (Definition) [type=int] [typekind=Int] [sizeof=4] 
[alignof=4] [offsetof=0]
+// CHECK: FieldDecl=dummy:9:13 (Definition) [type=int] [typekind=Int] 
[sizeof=4] [alignof=4] [offsetof=64/0]
+// CHECK: FieldDecl=data:10:15 (Definition) [type=void *[]] 
[typekind=IncompleteArray] [sizeof=-2] [alignof=-2] [offsetof=128/64]
+// CHECK: FieldDecl=size:15:9 (Definition) [type=int] [typekind=Int] 
[sizeof=4] [alignof=4] [offsetof=0]
+// CHECK: FieldDecl=data1:17:15 (Definition) [type=void *[]] 
[typekind=IncompleteArray] [sizeof=-2] [alignof=-2] [offsetof=64/0]
+// CHECK: FieldDecl=data2:18:15 (Definition) [type=void *[]] 
[typekind=IncompleteArray] [sizeof=-2] [alignof=-2] [offsetof=64/0]
\ No newline at end of file


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -953,7 +953,7 @@
 static long long visitRecordForValidation(const RecordDecl *RD) {
   for (const auto *I : RD->fields()){
 QualType FQT = I->getType();
-if (FQT->isIncompleteType())
+if (FQT->isIncompleteType() && !FQT->isIncompleteArrayType()) // IAT is okay here
   return CXTypeLayoutError_Incomplete;
 if (FQT->isDependentType())
   return CXTypeLayoutError_Dependent;
Index: test/Index/print-type-size.c
===
--- /dev/null
+++ test/Index/print-type-size.c
@@ -0,0 +1,30 @@
+struct Foo {
+int size;
+void* data[]; // incomplete array
+};
+
+struct Bar {
+int size;
+struct {
+int dummy;
+void* data[]; // incomplete array
+};
+};
+
+struct Baz {
+int size;
+union {
+void* data1[]; // incomplete array
+void* data2[]; // incomplete array
+};
+};
+
+// RUN: c-index-test -test-print-type-size %s | FileCheck %s
+// CHECK: FieldDecl=size:2:9 (Definition) [type=int] [typekind=Int] [sizeof=4] [alignof=4] [offsetof=0]
+// CHECK: FieldDecl=data:3:11 (Definition) [type=void *[]] [typekind=IncompleteArray] [sizeof=-2] [alignof=-2] [offsetof=64]
+// CHECK: FieldDecl=size:7:9 (Definition) [type=int] [typekind=Int] [sizeof=4] [alignof=4] [offsetof=0]
+// CHECK: FieldDecl=dummy:9:13 (Definition) [type=int] [typekind=Int] [sizeof=4] [alignof=4] [offsetof=64/0]
+// CHECK: FieldDecl=data:10:15 (Definition) [type=void *[]] [typekind=IncompleteArray] [sizeof=-2] [alignof=-2] [offsetof=128/64]
+// CHECK: FieldDecl=size:15:9 (Definition) [type=int] [typekind=Int] [sizeof=4] [alignof=4] [offsetof=0]
+// CHECK: FieldDecl=data1:17:15 (Definition) [type=void *[]] [typekind=IncompleteArray] [sizeof=-2] [alignof=-2] [offsetof=64/0]
+// CHECK: 

[PATCH] D61232: [libclang] Restore old clang_Cursor_isAnonymous behaviour

2019-04-28 Thread Jorn Vernee via Phabricator via cfe-commits
JornVernee updated this revision to Diff 197019.
JornVernee marked an inline comment as done.

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

https://reviews.llvm.org/D61232

Files:
  include/clang-c/Index.h
  test/Index/print-type.c
  tools/c-index-test/c-index-test.c
  tools/libclang/CXType.cpp


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -1253,6 +1253,16 @@
 
   return 0;
 }
+
+unsigned clang_Cursor_isAnonymousRecordDecl(CXCursor C){
+  if (!clang_isDeclaration(C.kind))
+return 0;
+  const Decl *D = cxcursor::getCursorDecl(C);
+  if (const RecordDecl *FD = dyn_cast_or_null(D))
+return FD->isAnonymousStructOrUnion();
+  return 0;
+}
+
 CXType clang_Type_getNamedType(CXType CT){
   QualType T = GetQualType(CT);
   const Type *TP = T.getTypePtrOrNull();
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1665,6 +1665,12 @@
   }
 }
 
+/* Print if it is an anonymous record decl */
+{
+  unsigned isAnonRecDecl = clang_Cursor_isAnonymousRecordDecl(cursor);
+  printf(" [isAnonRecDecl=%d]", isAnonRecDecl);
+}
+
 printf("\n");
   }
   return CXChildVisit_Recurse;
Index: test/Index/print-type.c
===
--- test/Index/print-type.c
+++ test/Index/print-type.c
@@ -15,6 +15,20 @@
 enum Enum{i}; enum Enum elaboratedEnumType();
 struct Struct{}; struct Struct elaboratedStructType();
 
+struct {
+  int x;
+  int y;
+} foo;
+
+struct {
+  struct {
+int x;
+int y;
+  };
+} bar;
+
+void fun(struct { int x; int y; } *param);
+
 // RUN: c-index-test -test-print-type %s | FileCheck %s
 // CHECK: FunctionDecl=f:3:6 (Definition) [type=int *(int *, char *, FooType, 
int *, void (*)(int))] [typekind=FunctionProto] [canonicaltype=int *(int *, 
char *, int, int *, void (*)(int))] [canonicaltypekind=FunctionProto] 
[resulttype=int *] [resulttypekind=Pointer] [args= [int *] [Pointer] [char *] 
[Pointer] [FooType] [Typedef] [int [5]] [ConstantArray] [void (*)(int)] 
[Pointer]] [isPOD=0]
 // CHECK: ParmDecl=p:3:13 (Definition) [type=int *] [typekind=Pointer] 
[isPOD=1] [pointeetype=int] [pointeekind=Int]
@@ -53,3 +67,7 @@
 // CHECK: StructDecl=Struct:16:8 (Definition) [type=struct Struct] 
[typekind=Record] [isPOD=1]
 // CHECK: FunctionDecl=elaboratedStructType:16:32 [type=struct Struct ()] 
[typekind=FunctionNoProto] [canonicaltype=struct Struct ()] 
[canonicaltypekind=FunctionNoProto] [resulttype=struct Struct] 
[resulttypekind=Elaborated] [isPOD=0]
 // CHECK: TypeRef=struct Struct:16:8 [type=struct Struct] [typekind=Record] 
[isPOD=1]
+// CHECK: StructDecl=:18:1 (Definition) [type=struct (anonymous at 
{{.*}}print-type.c:18:1)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] 
[isAnonRecDecl=0]
+// CHECK: StructDecl=:23:1 (Definition) [type=struct (anonymous at 
{{.*}}print-type.c:23:1)] [typekind=Record] [isPOD=1] [nbFields=1] [isAnon=1] 
[isAnonRecDecl=0]
+// CHECK: StructDecl=:24:3 (Definition) [type=struct (anonymous at 
{{.*}}print-type.c:24:3)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] 
[isAnonRecDecl=1]
+// CHECK: StructDecl=:30:10 (Definition) [type=struct (anonymous at 
{{.*}}print-type.c:30:10)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] 
[isAnonRecDecl=0]
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -3920,11 +3920,17 @@
  */
 CINDEX_LINKAGE long long clang_Cursor_getOffsetOfField(CXCursor C);
 
+/**
+ * Determine whether the given cursor represents an anonymous
+ * tag or namespace
+ */
+CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C);
+
 /**
  * Determine whether the given cursor represents an anonymous record
  * declaration.
  */
-CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C);
+CINDEX_LINKAGE unsigned clang_Cursor_isAnonymousRecordDecl(CXCursor C);
 
 enum CXRefQualifierKind {
   /** No ref-qualifier was provided. */


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -1253,6 +1253,16 @@
 
   return 0;
 }
+
+unsigned clang_Cursor_isAnonymousRecordDecl(CXCursor C){
+  if (!clang_isDeclaration(C.kind))
+return 0;
+  const Decl *D = cxcursor::getCursorDecl(C);
+  if (const RecordDecl *FD = dyn_cast_or_null(D))
+return FD->isAnonymousStructOrUnion();
+  return 0;
+}
+
 CXType clang_Type_getNamedType(CXType CT){
   QualType T = GetQualType(CT);
   const Type *TP = T.getTypePtrOrNull();
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c

[PATCH] D61232: [libclang] Restore old clang_Cursor_isAnonymous behaviour

2019-04-28 Thread Jorn Vernee via Phabricator via cfe-commits
JornVernee updated this revision to Diff 197018.

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

https://reviews.llvm.org/D61232

Files:
  include/clang-c/Index.h
  test/Index/print-type.c
  tools/c-index-test/c-index-test.c
  tools/libclang/CXType.cpp


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -1253,6 +1253,16 @@
 
   return 0;
 }
+
+unsigned clang_Cursor_isAnonymousRecordDecl(CXCursor C){
+  if (!clang_isDeclaration(C.kind))
+return 0;
+  const Decl *D = cxcursor::getCursorDecl(C);
+  if (const RecordDecl *FD = dyn_cast_or_null(D))
+return FD->isAnonymousStructOrUnion();
+  return 0;
+}
+
 CXType clang_Type_getNamedType(CXType CT){
   QualType T = GetQualType(CT);
   const Type *TP = T.getTypePtrOrNull();
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1665,6 +1665,12 @@
   }
 }
 
+/* Print if it is an anonymous record decl */
+{
+  unsigned isAnonRecDecl = clang_Cursor_isAnonymousRecordDecl(cursor);
+  printf(" [isAnonRecDecl=%d]", isAnonRecDecl);
+}
+
 printf("\n");
   }
   return CXChildVisit_Recurse;
Index: test/Index/print-type.c
===
--- test/Index/print-type.c
+++ test/Index/print-type.c
@@ -15,6 +15,20 @@
 enum Enum{i}; enum Enum elaboratedEnumType();
 struct Struct{}; struct Struct elaboratedStructType();
 
+struct {
+  int x;
+  int y;
+} foo;
+
+struct {
+  struct {
+int x;
+int y;
+  };
+} bar;
+
+void fun(struct { int x; int y; } *param);
+
 // RUN: c-index-test -test-print-type %s | FileCheck %s
 // CHECK: FunctionDecl=f:3:6 (Definition) [type=int *(int *, char *, FooType, 
int *, void (*)(int))] [typekind=FunctionProto] [canonicaltype=int *(int *, 
char *, int, int *, void (*)(int))] [canonicaltypekind=FunctionProto] 
[resulttype=int *] [resulttypekind=Pointer] [args= [int *] [Pointer] [char *] 
[Pointer] [FooType] [Typedef] [int [5]] [ConstantArray] [void (*)(int)] 
[Pointer]] [isPOD=0]
 // CHECK: ParmDecl=p:3:13 (Definition) [type=int *] [typekind=Pointer] 
[isPOD=1] [pointeetype=int] [pointeekind=Int]
@@ -53,3 +67,7 @@
 // CHECK: StructDecl=Struct:16:8 (Definition) [type=struct Struct] 
[typekind=Record] [isPOD=1]
 // CHECK: FunctionDecl=elaboratedStructType:16:32 [type=struct Struct ()] 
[typekind=FunctionNoProto] [canonicaltype=struct Struct ()] 
[canonicaltypekind=FunctionNoProto] [resulttype=struct Struct] 
[resulttypekind=Elaborated] [isPOD=0]
 // CHECK: TypeRef=struct Struct:16:8 [type=struct Struct] [typekind=Record] 
[isPOD=1]
+// CHECK: StructDecl=:18:1 (Definition) [type=struct (anonymous at 
{{*}}print-type.c:18:1)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] 
[isAnonRecDecl=0]
+// CHECK: StructDecl=:23:1 (Definition) [type=struct (anonymous at 
{{*}}print-type.c:23:1)] [typekind=Record] [isPOD=1] [nbFields=1] [isAnon=1] 
[isAnonRecDecl=0]
+// CHECK: StructDecl=:24:3 (Definition) [type=struct (anonymous at 
{{*}}print-type.c:24:3)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] 
[isAnonRecDecl=1]
+// CHECK: StructDecl=:30:10 (Definition) [type=struct (anonymous at 
{{*}}print-type.c:30:10)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] 
[isAnonRecDecl=0]
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -3920,11 +3920,17 @@
  */
 CINDEX_LINKAGE long long clang_Cursor_getOffsetOfField(CXCursor C);
 
+/**
+ * Determine whether the given cursor represents an anonymous
+ * tag or namespace
+ */
+CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C);
+
 /**
  * Determine whether the given cursor represents an anonymous record
  * declaration.
  */
-CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C);
+CINDEX_LINKAGE unsigned clang_Cursor_isAnonymousRecordDecl(CXCursor C);
 
 enum CXRefQualifierKind {
   /** No ref-qualifier was provided. */


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -1253,6 +1253,16 @@
 
   return 0;
 }
+
+unsigned clang_Cursor_isAnonymousRecordDecl(CXCursor C){
+  if (!clang_isDeclaration(C.kind))
+return 0;
+  const Decl *D = cxcursor::getCursorDecl(C);
+  if (const RecordDecl *FD = dyn_cast_or_null(D))
+return FD->isAnonymousStructOrUnion();
+  return 0;
+}
+
 CXType clang_Type_getNamedType(CXType CT){
   QualType T = GetQualType(CT);
   const Type *TP = T.getTypePtrOrNull();
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1665,6 +1665,12 @@
   }
 }
 
+/* 

[PATCH] D60507: [clang-tidy] new check: bugprone-unhandled-self-assignment

2019-04-28 Thread Tamás Zolnai via Phabricator via cfe-commits
ztamas updated this revision to Diff 197014.
ztamas added a comment.

Better handling of template and non-template self-copy


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60507

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-self-assignment.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/bugprone-unhandled-self-assignment.cpp

Index: clang-tools-extra/test/clang-tidy/bugprone-unhandled-self-assignment.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/bugprone-unhandled-self-assignment.cpp
@@ -0,0 +1,561 @@
+// RUN: %check_clang_tidy %s bugprone-unhandled-self-assignment %t
+
+namespace std {
+
+template 
+void swap(T x, T y) {
+}
+
+template 
+T &(T x) {
+}
+
+template 
+class unique_ptr {
+};
+
+template 
+class shared_ptr {
+};
+
+template 
+class weak_ptr {
+};
+
+template 
+class auto_ptr {
+};
+
+} // namespace std
+
+void assert(int expression){};
+
+///
+/// Test cases correctly caught by the check.
+
+class PtrField {
+public:
+  PtrField =(const PtrField );
+
+private:
+  int *p;
+};
+
+PtrField ::operator=(const PtrField ) {
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+  // ...
+  return *this;
+}
+
+// Class with an inline operator definition.
+class InlineDefinition {
+public:
+  InlineDefinition =(const InlineDefinition ) {
+// CHECK-MESSAGES: [[@LINE-1]]:21: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+// ...
+return *this;
+  }
+
+private:
+  int *p;
+};
+
+class UniquePtrField {
+public:
+  UniquePtrField =(const UniquePtrField ) {
+// CHECK-MESSAGES: [[@LINE-1]]:19: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+// ...
+return *this;
+  }
+
+private:
+  std::unique_ptr p;
+};
+
+class SharedPtrField {
+public:
+  SharedPtrField =(const SharedPtrField ) {
+// CHECK-MESSAGES: [[@LINE-1]]:19: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+// ...
+return *this;
+  }
+
+private:
+  std::shared_ptr p;
+};
+
+class WeakPtrField {
+public:
+  WeakPtrField =(const WeakPtrField ) {
+// CHECK-MESSAGES: [[@LINE-1]]:17: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+// ...
+return *this;
+  }
+
+private:
+  std::weak_ptr p;
+};
+
+class AutoPtrField {
+public:
+  AutoPtrField =(const AutoPtrField ) {
+// CHECK-MESSAGES: [[@LINE-1]]:17: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+// ...
+return *this;
+  }
+
+private:
+  std::auto_ptr p;
+};
+
+// Class with C array field.
+class CArrayField {
+public:
+  CArrayField =(const CArrayField ) {
+// CHECK-MESSAGES: [[@LINE-1]]:16: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+// ...
+return *this;
+  }
+
+private:
+  int array[256];
+};
+
+// Make sure to not ignore cases when the operator definition calls
+// a copy constructor of another class.
+class CopyConstruct {
+public:
+  CopyConstruct =(const CopyConstruct ) {
+// CHECK-MESSAGES: [[@LINE-1]]:18: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+WeakPtrField a;
+WeakPtrField b(a);
+// ...
+return *this;
+  }
+
+private:
+  int *p;
+};
+
+// Make sure to not ignore cases when the operator definition calls
+// a copy assignment operator of another class.
+class AssignOperator {
+public:
+  AssignOperator =(const AssignOperator ) {
+// CHECK-MESSAGES: [[@LINE-1]]:19: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+a.operator=(object.a);
+// ...
+return *this;
+  }
+
+private:
+  int *p;
+  WeakPtrField a;
+};
+
+class NotSelfCheck {
+public:
+  NotSelfCheck =(const NotSelfCheck ) {
+// CHECK-MESSAGES: [[@LINE-1]]:17: warning: operator=() might not handle self-assignment properly [bugprone-unhandled-self-assignment]
+if ( == this->doSomething()) {
+  // ...
+}
+return *this;
+  }
+
+  void *doSomething() {
+return p;
+  }
+
+private:
+  int *p;
+};
+
+template 
+class TemplatePtrField {
+public:
+  TemplatePtrField =(const TemplatePtrField ) {
+// CHECK-MESSAGES: 

[PATCH] D61232: [libclang] Restore old clang_Cursor_isAnonymous behaviour

2019-04-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

Could you please also upload diff with the full context? It's -U for git 
and quite similar for svn.
Otherwise looks ok.




Comment at: test/Index/print-type.c:70
 // CHECK: TypeRef=struct Struct:16:8 [type=struct Struct] [typekind=Record] 
[isPOD=1]
+// CHECK: StructDecl=:18:1 (Definition) [type=struct (anonymous at 
.\test\Index\print-type.c:18:1)] [typekind=Record] [isPOD=1] [nbFields=2] 
[isAnon=1] [isAnonRecDecl=0]
+// CHECK: StructDecl=:23:1 (Definition) [type=struct (anonymous at 
.\test\Index\print-type.c:23:1)] [typekind=Record] [isPOD=1] [nbFields=1] 
[isAnon=1] [isAnonRecDecl=0]

The path will be different depending on the machine and OS. You can 
{{.*}}print-type.cpp instead (like in https://reviews.llvm.org/D54996).


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

https://reviews.llvm.org/D61232



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


r359393 - [PowerPC][Clang] Add tests for PowerPC MMX intrinsics

2019-04-28 Thread Qiu Chaofan via cfe-commits
Author: chaofan
Date: Sat Apr 27 23:27:33 2019
New Revision: 359393

URL: http://llvm.org/viewvc/llvm-project?rev=359393=rev
Log:
[PowerPC][Clang] Add tests for PowerPC MMX intrinsics

Add the rest of test cases covering functions defined in mmintrin.h on PowerPC.

Reviewed By: Jinsong Ji

Modified:
cfe/trunk/test/CodeGen/ppc-mmintrin.c

Modified: cfe/trunk/test/CodeGen/ppc-mmintrin.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ppc-mmintrin.c?rev=359393=359392=359393=diff
==
--- cfe/trunk/test/CodeGen/ppc-mmintrin.c (original)
+++ cfe/trunk/test/CodeGen/ppc-mmintrin.c Sat Apr 27 23:27:33 2019
@@ -1,16 +1,508 @@
 // REQUIRES: powerpc-registered-target
 
 // RUN: %clang -S -emit-llvm -target powerpc64-gnu-linux -mcpu=pwr8 
-DNO_WARN_X86_INTRINSICS %s \
-// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | 
llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | 
llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK-P8,CHECK,CHECK-BE
 // RUN: %clang -S -emit-llvm -target powerpc64le-gnu-linux -mcpu=pwr8 
-DNO_WARN_X86_INTRINSICS %s \
-// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | 
llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,CHECK-LE
+// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | 
llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK-P8,CHECK,CHECK-LE
+// RUN: %clang -S -emit-llvm -target powerpc64-gnu-linux -mcpu=pwr9 
-DNO_WARN_X86_INTRINSICS %s \
+// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | 
llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK-P9,CHECK,CHECK-BE
+// RUN: %clang -S -emit-llvm -target powerpc64le-gnu-linux -mcpu=pwr9 
-DNO_WARN_X86_INTRINSICS %s \
+// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | 
llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK-P9,CHECK,CHECK-LE
 
 #include 
 
 unsigned long long int ull1, ull2;
+int i1, i2;
+short s[4];
+signed char c[8];
+long long int ll1;
 __m64 m1, m2, res;
 
 void __attribute__((noinline))
+test_add() {
+  res = _mm_add_pi32(m1, m2);
+  res = _mm_add_pi16(m1, m2);
+  res = _mm_add_pi8(m1, m2);
+  res = _mm_adds_pu16(m1, m2);
+  res = _mm_adds_pu8(m1, m2);
+  res = _mm_adds_pi16(m1, m2);
+  res = _mm_adds_pi8(m1, m2);
+}
+
+// CHECK-LABEL: @test_add
+
+// CHECK: define available_externally i64 @_mm_add_pi32
+
+// CHECK-P9: [[REG1:[0-9a-zA-Z_%.]+]] = call <2 x i64> @vec_splats(unsigned 
long long)
+// CHECK-P9-NEXT: [[REG2:[0-9a-zA-Z_%.]+]] = bitcast <2 x i64> [[REG1]] to <4 
x i32>
+// CHECK-P9-NEXT: store <4 x i32> [[REG2]], <4 x i32>* 
[[REG3:[0-9a-zA-Z_%.]+]], align 16
+// CHECK-P9-NEXT: [[REG4:[0-9a-zA-Z_%.]+]] = load i64, i64* 
{{[0-9a-zA-Z_%.]+}}, align 8
+// CHECK-P9-NEXT: [[REG5:[0-9a-zA-Z_%.]+]] = call <2 x i64> 
@vec_splats(unsigned long long)
+// CHECK-P9-NEXT: [[REG6:[0-9a-zA-Z_%.]+]] = bitcast <2 x i64> [[REG5]] to <4 
x i32>
+// CHECK-P9-NEXT: store <4 x i32> [[REG6]], <4 x i32>* 
[[REG7:[0-9a-zA-Z_%.]+]], align 16
+// CHECK-P9-NEXT: [[REG8:[0-9a-zA-Z_%.]+]] = load <4 x i32>, <4 x i32>* 
[[REG3]], align 16
+// CHECK-P9-NEXT: [[REG9:[0-9a-zA-Z_%.]+]] = load <4 x i32>, <4 x i32>* 
[[REG7]], align 16
+// CHECK-P9-NEXT: [[REG10:[0-9a-zA-Z_%.]+]] = call <4 x i32> @vec_add(int 
vector[4], int vector[4])(<4 x i32> [[REG8]], <4 x i32> [[REG9]])
+// CHECK-P9-NEXT: store <4 x i32> [[REG10]], <4 x i32>* 
[[REG11:[0-9a-zA-Z_%.]+]], align 16
+// CHECK-P9-NEXT: [[REG12:[0-9a-zA-Z_%.]+]] = load <4 x i32>, <4 x i32>* 
[[REG11]], align 16
+// CHECK-P9-NEXT: [[REG13:[0-9a-zA-Z_%.]+]] = bitcast <4 x i32> %6 to <2 x i64>
+// CHECK-P9-NEXT: [[REG14:[0-9a-zA-Z_%.]+]] = extractelement <2 x i64> 
[[REG13]], i32 0
+// CHECK-P9-NEXT: ret i64 [[REG14]]
+
+// CHECK-P8: [[REG15:[0-9a-zA-Z_%.]+]] = getelementptr inbounds [2 x i32], [2 
x i32]* {{[0-9a-zA-Z_%.]+}}, i64 0, i64 0
+// CHECK-P8-NEXT: [[REG16:[0-9a-zA-Z_%.]+]] = load i32, i32* [[REG15]]
+// CHECK-P8: [[REG17:[0-9a-zA-Z_%.]+]] = getelementptr inbounds [2 x i32], [2 
x i32]* {{[0-9a-zA-Z_%.]+}}, i64 0, i64 0
+// CHECK-P8-NEXT: [[REG18:[0-9a-zA-Z_%.]+]] = load i32, i32* [[REG17]]
+// CHECK-P8-NEXT: add nsw i32 [[REG16]], [[REG18]]
+// CHECK-P8: [[REG19:[0-9a-zA-Z_%.]+]] = getelementptr inbounds [2 x i32], [2 
x i32]* {{[0-9a-zA-Z_%.]+}}, i64 0, i64 1
+// CHECK-P8-NEXT: [[REG20:[0-9a-zA-Z_%.]+]] = load i32, i32* [[REG19]]
+// CHECK-P8: [[REG21:[0-9a-zA-Z_%.]+]] = getelementptr inbounds [2 x i32], [2 
x i32]* {{[0-9a-zA-Z_%.]+}}, i64 0, i64 1
+// CHECK-P8-NEXT: [[REG22:[0-9a-zA-Z_%.]+]] = load i32, i32* [[REG21]]
+// CHECK-P8-NEXT: add nsw i32 [[REG20]], [[REG22]]
+
+// CHECK: define available_externally i64 @_mm_add_pi16
+// CHECK: [[REG23:[0-9a-zA-Z_%.]+]] = call <2 x i64> @vec_splats
+// CHECK-NEXT: [[REG24:[0-9a-zA-Z_%.]+]] = bitcast <2 x i64> [[REG23]] to <8 x 
i16>
+// CHECK-NEXT: store <8 x i16> [[REG24]], <8 x i16>*