r319881 - [libclang] Add function to get the buffer for a file

2017-12-06 Thread Erik Verbruggen via cfe-commits
Author: erikjv
Date: Wed Dec  6 01:02:52 2017
New Revision: 319881

URL: http://llvm.org/viewvc/llvm-project?rev=319881&view=rev
Log:
[libclang] Add function to get the buffer for a file

This can be used by clients in conjunction with an offset returned by
e.g. clang_getFileLocation. Now those clients do not need to also
open/read the file.

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

Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=319881&r1=319880&r2=319881&view=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Wed Dec  6 01:02:52 2017
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 43
+#define CINDEX_VERSION_MINOR 44
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -404,6 +404,21 @@ CINDEX_LINKAGE CXFile clang_getFile(CXTr
 const char *file_name);
 
 /**
+ * \brief Retrieve the buffer associated with the given file.
+ *
+ * \param tu the translation unit
+ *
+ * \param file the file for which to retrieve the buffer.
+ *
+ * \param size [out] if non-NULL, will be set to the size of the buffer.
+ *
+ * \returns a pointer to the buffer in memory that holds the contents of
+ * \p file, or a NULL pointer when the file is not loaded.
+ */
+CINDEX_LINKAGE const char *clang_getFileContents(CXTranslationUnit tu,
+ CXFile file, size_t *size);
+
+/**
  * \brief Returns non-zero if the \c file1 and \c file2 point to the same file,
  * or they are both NULL.
  */

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=319881&r1=319880&r2=319881&view=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Dec  6 01:02:52 2017
@@ -4162,6 +4162,27 @@ CXFile clang_getFile(CXTranslationUnit T
   return const_cast(FMgr.getFile(file_name));
 }
 
+const char *clang_getFileContents(CXTranslationUnit TU, CXFile file,
+  size_t *size) {
+  if (isNotUsableTU(TU)) {
+LOG_BAD_TU(TU);
+return nullptr;
+  }
+
+  const SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
+  FileID fid = SM.translateFile(static_cast(file));
+  bool Invalid = true;
+  llvm::MemoryBuffer *buf = SM.getBuffer(fid, &Invalid);
+  if (Invalid) {
+if (size)
+  *size = 0;
+return nullptr;
+  }
+  if (size)
+*size = buf->getBufferSize();
+  return buf->getBufferStart();
+}
+
 unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit TU,
 CXFile file) {
   if (isNotUsableTU(TU)) {


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


[PATCH] D40643: [libclang] Add function to get the buffer for a file

2017-12-06 Thread Erik Verbruggen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319881: [libclang] Add function to get the buffer for a file 
(authored by erikjv).

Changed prior to commit:
  https://reviews.llvm.org/D40643?vs=124904&id=125677#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40643

Files:
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/tools/libclang/CIndex.cpp


Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/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 43
+#define CINDEX_VERSION_MINOR 44
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -404,6 +404,21 @@
 const char *file_name);
 
 /**
+ * \brief Retrieve the buffer associated with the given file.
+ *
+ * \param tu the translation unit
+ *
+ * \param file the file for which to retrieve the buffer.
+ *
+ * \param size [out] if non-NULL, will be set to the size of the buffer.
+ *
+ * \returns a pointer to the buffer in memory that holds the contents of
+ * \p file, or a NULL pointer when the file is not loaded.
+ */
+CINDEX_LINKAGE const char *clang_getFileContents(CXTranslationUnit tu,
+ CXFile file, size_t *size);
+
+/**
  * \brief Returns non-zero if the \c file1 and \c file2 point to the same file,
  * or they are both NULL.
  */
Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -4162,6 +4162,27 @@
   return const_cast(FMgr.getFile(file_name));
 }
 
+const char *clang_getFileContents(CXTranslationUnit TU, CXFile file,
+  size_t *size) {
+  if (isNotUsableTU(TU)) {
+LOG_BAD_TU(TU);
+return nullptr;
+  }
+
+  const SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
+  FileID fid = SM.translateFile(static_cast(file));
+  bool Invalid = true;
+  llvm::MemoryBuffer *buf = SM.getBuffer(fid, &Invalid);
+  if (Invalid) {
+if (size)
+  *size = 0;
+return nullptr;
+  }
+  if (size)
+*size = buf->getBufferSize();
+  return buf->getBufferStart();
+}
+
 unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit TU,
 CXFile file) {
   if (isNotUsableTU(TU)) {


Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/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 43
+#define CINDEX_VERSION_MINOR 44
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -404,6 +404,21 @@
 const char *file_name);
 
 /**
+ * \brief Retrieve the buffer associated with the given file.
+ *
+ * \param tu the translation unit
+ *
+ * \param file the file for which to retrieve the buffer.
+ *
+ * \param size [out] if non-NULL, will be set to the size of the buffer.
+ *
+ * \returns a pointer to the buffer in memory that holds the contents of
+ * \p file, or a NULL pointer when the file is not loaded.
+ */
+CINDEX_LINKAGE const char *clang_getFileContents(CXTranslationUnit tu,
+ CXFile file, size_t *size);
+
+/**
  * \brief Returns non-zero if the \c file1 and \c file2 point to the same file,
  * or they are both NULL.
  */
Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -4162,6 +4162,27 @@
   return const_cast(FMgr.getFile(file_name));
 }
 
+const char *clang_getFileContents(CXTranslationUnit TU, CXFile file,
+  size_t *size) {
+  if (isNotUsableTU(TU)) {
+LOG_BAD_TU(TU);
+return nullptr;
+  }
+
+  const SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
+  FileID fid = SM.translateFile(static_cast(file));
+  bool Invalid = true;
+  llvm::MemoryBuffer *buf = SM.getBuffer(fid, &Invalid);
+  if (Invalid) {
+if (size)
+  *size = 0;
+return nullptr;
+  }
+  if (size)
+*size = buf->getBufferSize();
+  return buf->getBufferStart();
+}
+
 unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit TU,
 CXFile file) {
   if (isNotUsableTU(TU)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40884: [Index] Add setPreprocessor member to IndexDataConsumer.

2017-12-06 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.

This enables us to use information in Preprocessor when handling symbol
occurrences.


Repository:
  rC Clang

https://reviews.llvm.org/D40884

Files:
  include/clang/Index/IndexDataConsumer.h
  include/clang/Index/IndexingAction.h
  lib/Index/IndexingAction.cpp
  tools/libclang/CXIndexDataConsumer.h

Index: tools/libclang/CXIndexDataConsumer.h
===
--- tools/libclang/CXIndexDataConsumer.h
+++ tools/libclang/CXIndexDataConsumer.h
@@ -342,7 +342,7 @@
   CXTranslationUnit getCXTU() const { return CXTU; }
 
   void setASTContext(ASTContext &ctx);
-  void setPreprocessor(std::shared_ptr PP);
+  void setPreprocessor(std::shared_ptr PP) override;
 
   bool shouldSuppressRefs() const {
 return IndexOptions & CXIndexOpt_SuppressRedundantRefs;
Index: lib/Index/IndexingAction.cpp
===
--- lib/Index/IndexingAction.cpp
+++ lib/Index/IndexingAction.cpp
@@ -8,10 +8,11 @@
 //===--===//
 
 #include "clang/Index/IndexingAction.h"
-#include "clang/Index/IndexDataConsumer.h"
 #include "IndexingContext.h"
+#include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/MultiplexConsumer.h"
+#include "clang/Index/IndexDataConsumer.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Serialization/ASTReader.h"
 
@@ -42,16 +43,18 @@
 namespace {
 
 class IndexASTConsumer : public ASTConsumer {
+  std::shared_ptr PP;
   IndexingContext &IndexCtx;
 
 public:
-  IndexASTConsumer(IndexingContext &IndexCtx)
-: IndexCtx(IndexCtx) {}
+  IndexASTConsumer(std::shared_ptr PP, IndexingContext &IndexCtx)
+  : PP(std::move(PP)), IndexCtx(IndexCtx) {}
 
 protected:
   void Initialize(ASTContext &Context) override {
 IndexCtx.setASTContext(Context);
 IndexCtx.getDataConsumer().initialize(Context);
+IndexCtx.getDataConsumer().setPreprocessor(PP);
   }
 
   bool HandleTopLevelDecl(DeclGroupRef DG) override {
@@ -80,8 +83,10 @@
 : DataConsumer(std::move(dataConsumer)),
   IndexCtx(Opts, *DataConsumer) {}
 
-  std::unique_ptr createIndexASTConsumer() {
-return llvm::make_unique(IndexCtx);
+  std::unique_ptr
+  createIndexASTConsumer(CompilerInstance &CI) {
+return llvm::make_unique(CI.getPreprocessorPtr(),
+   IndexCtx);
   }
 
   void finish() {
@@ -98,7 +103,7 @@
 protected:
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
  StringRef InFile) override {
-return createIndexASTConsumer();
+return createIndexASTConsumer(CI);
   }
 
   void EndSourceFileAction() override {
@@ -142,7 +147,7 @@
 
   std::vector> Consumers;
   Consumers.push_back(std::move(OtherConsumer));
-  Consumers.push_back(createIndexASTConsumer());
+  Consumers.push_back(createIndexASTConsumer(CI));
   return llvm::make_unique(std::move(Consumers));
 }
 
@@ -173,6 +178,7 @@
   IndexingContext IndexCtx(Opts, *DataConsumer);
   IndexCtx.setASTContext(Unit.getASTContext());
   DataConsumer->initialize(Unit.getASTContext());
+  DataConsumer->setPreprocessor(Unit.getPreprocessorPtr());
   indexTranslationUnit(Unit, IndexCtx);
   DataConsumer->finish();
 }
@@ -198,7 +204,7 @@
   IndexCtx.setASTContext(Ctx);
   DataConsumer->initialize(Ctx);
 
-  for (const Decl *D :Reader.getModuleFileLevelDecls(Mod)) {
+  for (const Decl *D : Reader.getModuleFileLevelDecls(Mod)) {
 IndexCtx.indexTopLevelDecl(D);
   }
   DataConsumer->finish();
Index: include/clang/Index/IndexingAction.h
===
--- include/clang/Index/IndexingAction.h
+++ include/clang/Index/IndexingAction.h
@@ -11,6 +11,7 @@
 #define LLVM_CLANG_INDEX_INDEXINGACTION_H
 
 #include "clang/Basic/LLVM.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/ArrayRef.h"
 #include 
 
Index: include/clang/Index/IndexDataConsumer.h
===
--- include/clang/Index/IndexDataConsumer.h
+++ include/clang/Index/IndexDataConsumer.h
@@ -11,6 +11,7 @@
 #define LLVM_CLANG_INDEX_INDEXDATACONSUMER_H
 
 #include "clang/Index/IndexSymbol.h"
+#include "clang/Lex/Preprocessor.h"
 
 namespace clang {
   class ASTContext;
@@ -36,6 +37,8 @@
 
   virtual void initialize(ASTContext &Ctx) {}
 
+  virtual void setPreprocessor(std::shared_ptr PP) {}
+
   /// \returns true to continue indexing, or false to abort.
   virtual bool handleDeclOccurence(const Decl *D, SymbolRoleSet Roles,
ArrayRef Relations,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40884: [Index] Add setPreprocessor member to IndexDataConsumer.

2017-12-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: include/clang/Index/IndexingAction.h:14
 #include "clang/Basic/LLVM.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/ArrayRef.h"

Is this header being used in this file?


Repository:
  rC Clang

https://reviews.llvm.org/D40884



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


r319883 - [OpenCL] Fix layering violation by getOpenCLTypeAddrSpace

2017-12-06 Thread Sven van Haastregt via cfe-commits
Author: svenvh
Date: Wed Dec  6 02:11:28 2017
New Revision: 319883

URL: http://llvm.org/viewvc/llvm-project?rev=319883&view=rev
Log:
[OpenCL] Fix layering violation by getOpenCLTypeAddrSpace

Commit 7ac28eb0a5 / r310911 ("[OpenCL] Allow targets to select address
space per type", 2017-08-15) made Basic depend on AST, introducing a
circular dependency.  Break this dependency by adding the
OpenCLTypeKind enum in Basic and map from AST types to this enum in
ASTContext.

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

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets/AMDGPU.h
cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=319883&r1=319882&r2=319883&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed Dec  6 02:11:28 2017
@@ -1224,6 +1224,12 @@ public:
   /// pointer to blocks.
   QualType getBlockDescriptorExtendedType() const;
 
+  /// Map an AST Type to an OpenCLTypeKind enum value.
+  TargetInfo::OpenCLTypeKind getOpenCLTypeKind(const Type *T) const;
+
+  /// Get address space for OpenCL type.
+  LangAS getOpenCLTypeAddrSpace(const Type *T) const;
+
   void setcudaConfigureCallDecl(FunctionDecl *FD) {
 cudaConfigureCallDecl = FD;
   }

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=319883&r1=319882&r2=319883&view=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Wed Dec  6 02:11:28 2017
@@ -46,7 +46,6 @@ class MacroBuilder;
 class QualType;
 class SourceLocation;
 class SourceManager;
-class Type;
 
 namespace Builtin { struct Info; }
 
@@ -1057,8 +1056,19 @@ public:
   return getTargetOpts().SupportedOpenCLOptions;
   }
 
+  enum OpenCLTypeKind {
+OCLTK_Default,
+OCLTK_ClkEvent,
+OCLTK_Event,
+OCLTK_Image,
+OCLTK_Pipe,
+OCLTK_Queue,
+OCLTK_ReserveID,
+OCLTK_Sampler,
+  };
+
   /// \brief Get address space for OpenCL type.
-  virtual LangAS getOpenCLTypeAddrSpace(const Type *T) const;
+  virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const;
 
   /// \returns Target specific vtbl ptr address space.
   virtual unsigned getVtblPtrAddressSpace() const {

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=319883&r1=319882&r2=319883&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Dec  6 02:11:28 2017
@@ -1826,7 +1826,8 @@ TypeInfo ASTContext::getTypeInfoImpl(con
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
 case BuiltinType::Id:
 #include "clang/Basic/OpenCLImageTypes.def"
-  AS = getTargetAddressSpace(Target->getOpenCLTypeAddrSpace(T));
+  AS = getTargetAddressSpace(
+  Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T)));
   Width = Target->getPointerWidth(AS);
   Align = Target->getPointerAlign(AS);
   break;
@@ -5720,6 +5721,46 @@ QualType ASTContext::getBlockDescriptorE
   return getTagDeclType(BlockDescriptorExtendedType);
 }
 
+TargetInfo::OpenCLTypeKind ASTContext::getOpenCLTypeKind(const Type *T) const {
+  auto BT = dyn_cast(T);
+
+  if (!BT) {
+if (isa(T))
+  return TargetInfo::OCLTK_Pipe;
+
+return TargetInfo::OCLTK_Default;
+  }
+
+  switch (BT->getKind()) {
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   
\
+  case BuiltinType::Id:
\
+return TargetInfo::OCLTK_Image;
+#include "clang/Basic/OpenCLImageTypes.def"
+
+  case BuiltinType::OCLClkEvent:
+return TargetInfo::OCLTK_ClkEvent;
+
+  case BuiltinType::OCLEvent:
+return TargetInfo::OCLTK_Event;
+
+  case BuiltinType::OCLQueue:
+return TargetInfo::OCLTK_Queue;
+
+  case BuiltinType::OCLReserveID:
+return TargetInfo::OCLTK_ReserveID;
+
+  case BuiltinType::OCLSampler:
+return TargetInfo::OCLTK_Sampler;
+
+  default:
+return TargetInfo::OCLTK_Default;
+  }
+}
+
+LangAS ASTContext::getOpenCLTypeAddrSpace(const Type *T) const {
+  return Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T));
+}
+
 /// BlockRequiresCopying - Returns true if byref variable "D" of type "Ty"
 /// requires copy/dispose. Note that this must match the logic
 /// in buildByrefHelpers.

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Bas

[PATCH] D40838: [OpenCL] Fix layering violation by getOpenCLTypeAddrSpace

2017-12-06 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319883: [OpenCL] Fix layering violation by 
getOpenCLTypeAddrSpace (authored by svenvh).

Changed prior to commit:
  https://reviews.llvm.org/D40838?vs=125554&id=125682#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40838

Files:
  cfe/trunk/include/clang/AST/ASTContext.h
  cfe/trunk/include/clang/Basic/TargetInfo.h
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/Basic/TargetInfo.cpp
  cfe/trunk/lib/Basic/Targets/AMDGPU.h
  cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp

Index: cfe/trunk/include/clang/AST/ASTContext.h
===
--- cfe/trunk/include/clang/AST/ASTContext.h
+++ cfe/trunk/include/clang/AST/ASTContext.h
@@ -1224,6 +1224,12 @@
   /// pointer to blocks.
   QualType getBlockDescriptorExtendedType() const;
 
+  /// Map an AST Type to an OpenCLTypeKind enum value.
+  TargetInfo::OpenCLTypeKind getOpenCLTypeKind(const Type *T) const;
+
+  /// Get address space for OpenCL type.
+  LangAS getOpenCLTypeAddrSpace(const Type *T) const;
+
   void setcudaConfigureCallDecl(FunctionDecl *FD) {
 cudaConfigureCallDecl = FD;
   }
Index: cfe/trunk/include/clang/Basic/TargetInfo.h
===
--- cfe/trunk/include/clang/Basic/TargetInfo.h
+++ cfe/trunk/include/clang/Basic/TargetInfo.h
@@ -46,7 +46,6 @@
 class QualType;
 class SourceLocation;
 class SourceManager;
-class Type;
 
 namespace Builtin { struct Info; }
 
@@ -1057,8 +1056,19 @@
   return getTargetOpts().SupportedOpenCLOptions;
   }
 
+  enum OpenCLTypeKind {
+OCLTK_Default,
+OCLTK_ClkEvent,
+OCLTK_Event,
+OCLTK_Image,
+OCLTK_Pipe,
+OCLTK_Queue,
+OCLTK_ReserveID,
+OCLTK_Sampler,
+  };
+
   /// \brief Get address space for OpenCL type.
-  virtual LangAS getOpenCLTypeAddrSpace(const Type *T) const;
+  virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const;
 
   /// \returns Target specific vtbl ptr address space.
   virtual unsigned getVtblPtrAddressSpace() const {
Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -1826,7 +1826,8 @@
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
 case BuiltinType::Id:
 #include "clang/Basic/OpenCLImageTypes.def"
-  AS = getTargetAddressSpace(Target->getOpenCLTypeAddrSpace(T));
+  AS = getTargetAddressSpace(
+  Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T)));
   Width = Target->getPointerWidth(AS);
   Align = Target->getPointerAlign(AS);
   break;
@@ -5720,6 +5721,46 @@
   return getTagDeclType(BlockDescriptorExtendedType);
 }
 
+TargetInfo::OpenCLTypeKind ASTContext::getOpenCLTypeKind(const Type *T) const {
+  auto BT = dyn_cast(T);
+
+  if (!BT) {
+if (isa(T))
+  return TargetInfo::OCLTK_Pipe;
+
+return TargetInfo::OCLTK_Default;
+  }
+
+  switch (BT->getKind()) {
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   \
+  case BuiltinType::Id:\
+return TargetInfo::OCLTK_Image;
+#include "clang/Basic/OpenCLImageTypes.def"
+
+  case BuiltinType::OCLClkEvent:
+return TargetInfo::OCLTK_ClkEvent;
+
+  case BuiltinType::OCLEvent:
+return TargetInfo::OCLTK_Event;
+
+  case BuiltinType::OCLQueue:
+return TargetInfo::OCLTK_Queue;
+
+  case BuiltinType::OCLReserveID:
+return TargetInfo::OCLTK_ReserveID;
+
+  case BuiltinType::OCLSampler:
+return TargetInfo::OCLTK_Sampler;
+
+  default:
+return TargetInfo::OCLTK_Default;
+  }
+}
+
+LangAS ASTContext::getOpenCLTypeAddrSpace(const Type *T) const {
+  return Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T));
+}
+
 /// BlockRequiresCopying - Returns true if byref variable "D" of type "Ty"
 /// requires copy/dispose. Note that this must match the logic
 /// in buildByrefHelpers.
Index: cfe/trunk/lib/Basic/TargetInfo.cpp
===
--- cfe/trunk/lib/Basic/TargetInfo.cpp
+++ cfe/trunk/lib/Basic/TargetInfo.cpp
@@ -12,7 +12,6 @@
 //===--===//
 
 #include "clang/Basic/TargetInfo.h"
-#include "clang/AST/Type.h"
 #include "clang/Basic/AddressSpaces.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/LangOptions.h"
@@ -357,23 +356,13 @@
   return true;
 }
 
-LangAS TargetInfo::getOpenCLTypeAddrSpace(const Type *T) const {
-  auto BT = dyn_cast(T);
-
-  if (!BT) {
-if (isa(T))
-  return LangAS::opencl_global;
-
-return LangAS::Default;
-  }
-
-  switch (BT->getKind()) {
-#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   \
-  case BuiltinType::Id:\
+LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind T

[PATCH] D40838: [OpenCL] Fix layering violation by getOpenCLTypeAddrSpace

2017-12-06 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC319883: [OpenCL] Fix layering violation by 
getOpenCLTypeAddrSpace (authored by svenvh).

Repository:
  rC Clang

https://reviews.llvm.org/D40838

Files:
  include/clang/AST/ASTContext.h
  include/clang/Basic/TargetInfo.h
  lib/AST/ASTContext.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets/AMDGPU.h
  lib/CodeGen/CGOpenCLRuntime.cpp

Index: include/clang/AST/ASTContext.h
===
--- include/clang/AST/ASTContext.h
+++ include/clang/AST/ASTContext.h
@@ -1224,6 +1224,12 @@
   /// pointer to blocks.
   QualType getBlockDescriptorExtendedType() const;
 
+  /// Map an AST Type to an OpenCLTypeKind enum value.
+  TargetInfo::OpenCLTypeKind getOpenCLTypeKind(const Type *T) const;
+
+  /// Get address space for OpenCL type.
+  LangAS getOpenCLTypeAddrSpace(const Type *T) const;
+
   void setcudaConfigureCallDecl(FunctionDecl *FD) {
 cudaConfigureCallDecl = FD;
   }
Index: include/clang/Basic/TargetInfo.h
===
--- include/clang/Basic/TargetInfo.h
+++ include/clang/Basic/TargetInfo.h
@@ -46,7 +46,6 @@
 class QualType;
 class SourceLocation;
 class SourceManager;
-class Type;
 
 namespace Builtin { struct Info; }
 
@@ -1057,8 +1056,19 @@
   return getTargetOpts().SupportedOpenCLOptions;
   }
 
+  enum OpenCLTypeKind {
+OCLTK_Default,
+OCLTK_ClkEvent,
+OCLTK_Event,
+OCLTK_Image,
+OCLTK_Pipe,
+OCLTK_Queue,
+OCLTK_ReserveID,
+OCLTK_Sampler,
+  };
+
   /// \brief Get address space for OpenCL type.
-  virtual LangAS getOpenCLTypeAddrSpace(const Type *T) const;
+  virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const;
 
   /// \returns Target specific vtbl ptr address space.
   virtual unsigned getVtblPtrAddressSpace() const {
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -1826,7 +1826,8 @@
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
 case BuiltinType::Id:
 #include "clang/Basic/OpenCLImageTypes.def"
-  AS = getTargetAddressSpace(Target->getOpenCLTypeAddrSpace(T));
+  AS = getTargetAddressSpace(
+  Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T)));
   Width = Target->getPointerWidth(AS);
   Align = Target->getPointerAlign(AS);
   break;
@@ -5720,6 +5721,46 @@
   return getTagDeclType(BlockDescriptorExtendedType);
 }
 
+TargetInfo::OpenCLTypeKind ASTContext::getOpenCLTypeKind(const Type *T) const {
+  auto BT = dyn_cast(T);
+
+  if (!BT) {
+if (isa(T))
+  return TargetInfo::OCLTK_Pipe;
+
+return TargetInfo::OCLTK_Default;
+  }
+
+  switch (BT->getKind()) {
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   \
+  case BuiltinType::Id:\
+return TargetInfo::OCLTK_Image;
+#include "clang/Basic/OpenCLImageTypes.def"
+
+  case BuiltinType::OCLClkEvent:
+return TargetInfo::OCLTK_ClkEvent;
+
+  case BuiltinType::OCLEvent:
+return TargetInfo::OCLTK_Event;
+
+  case BuiltinType::OCLQueue:
+return TargetInfo::OCLTK_Queue;
+
+  case BuiltinType::OCLReserveID:
+return TargetInfo::OCLTK_ReserveID;
+
+  case BuiltinType::OCLSampler:
+return TargetInfo::OCLTK_Sampler;
+
+  default:
+return TargetInfo::OCLTK_Default;
+  }
+}
+
+LangAS ASTContext::getOpenCLTypeAddrSpace(const Type *T) const {
+  return Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T));
+}
+
 /// BlockRequiresCopying - Returns true if byref variable "D" of type "Ty"
 /// requires copy/dispose. Note that this must match the logic
 /// in buildByrefHelpers.
Index: lib/Basic/Targets/AMDGPU.h
===
--- lib/Basic/Targets/AMDGPU.h
+++ lib/Basic/Targets/AMDGPU.h
@@ -14,7 +14,6 @@
 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H
 #define LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H
 
-#include "clang/AST/Type.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/ADT/StringSet.h"
@@ -258,24 +257,18 @@
 }
   }
 
-  LangAS getOpenCLTypeAddrSpace(const Type *T) const override {
-auto BT = dyn_cast(T);
-
-if (!BT)
-  return TargetInfo::getOpenCLTypeAddrSpace(T);
-
-switch (BT->getKind()) {
-#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   \
-  case BuiltinType::Id:\
-return LangAS::opencl_constant;
-#include "clang/Basic/OpenCLImageTypes.def"
-case BuiltinType::OCLClkEvent:
-case BuiltinType::OCLQueue:
-case BuiltinType::OCLReserveID:
+  LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const override {
+switch (TK) {
+case OCLTK_Image:
+  return LangAS::opencl_constant;
+
+case OCLTK_ClkEvent:
+case OCLTK_Que

[PATCH] D37813: clang-format: better handle namespace macros

2017-12-06 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D37813#945125, @Typz wrote:

> I don't think this is really relevant for this tool: if someone changes the 
> implementation of the macro, then *they* must indeed if it should not be 
> formatted like a namespace (and keep the clang-format configuration 
> unchanged), or if it should now be formatted like a class (and thus make 
> changes to clang-format configuration). Here we are not defining what the 
> macro does, but how clang-format should indent it : in most case I don't 
> think the indentation format should actually depend on the way it is 
> implemented...


Ok, that's probably where our different opinions come from - I would want a 
macro to be formatted to reflect how it's implemented, because otherwise I'm 
going to be surprised when I look at the implementation, and I consider 
surprises to be something to avoid in programming in general, where possible.

That said, I'm also then a bit confused by your tests - they seem to currently 
format a mixture of namespace and class formatting, and combine the indentation 
of a class-scope with namespace end comments.


https://reviews.llvm.org/D37813



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


[PATCH] D40488: [clangd] Implemented tracing using Context

2017-12-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 125690.
ilya-biryukov added a comment.
Herald added a subscriber: klimek.

- Updated tracing to use the new Context implementation.
- Restored global tracer.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40488

Files:
  clangd/ClangdUnit.cpp
  clangd/JSONRPCDispatcher.cpp
  clangd/Trace.cpp
  clangd/Trace.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/TraceTests.cpp

Index: unittests/clangd/TraceTests.cpp
===
--- unittests/clangd/TraceTests.cpp
+++ unittests/clangd/TraceTests.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "Context.h"
 #include "Trace.h"
 
 #include "llvm/ADT/DenseMap.h"
@@ -74,10 +75,11 @@
   std::string JSON;
   {
 raw_string_ostream OS(JSON);
-auto Session = trace::Session::create(OS);
+auto JSONTracer = trace::createJSONTracer(OS);
+trace::TracingSession Session(*JSONTracer);
 {
-  trace::Span S("A");
-  trace::log("B");
+  trace::Span S(emptyCtx(), "A");
+  trace::log(emptyCtx(), "B");
 }
   }
 
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -115,19 +115,25 @@
<< EC.message();
 }
   }
+
+  // Setup tracing facilities.
   llvm::Optional TraceStream;
-  std::unique_ptr TraceSession;
+  std::unique_ptr Tracer;
   if (!TraceFile.empty()) {
 std::error_code EC;
 TraceStream.emplace(TraceFile, /*ref*/ EC, llvm::sys::fs::F_RW);
 if (EC) {
   TraceFile.reset();
   llvm::errs() << "Error while opening trace file: " << EC.message();
 } else {
-  TraceSession = trace::Session::create(*TraceStream, PrettyPrint);
+  Tracer = trace::createJSONTracer(*TraceStream, PrettyPrint);
 }
   }
 
+  llvm::Optional TracingSession;
+  if (Tracer)
+TracingSession.emplace(*Tracer);
+
   llvm::raw_ostream &Outs = llvm::outs();
   llvm::raw_ostream &Logs = llvm::errs();
   JSONOutput Out(Outs, Logs,
Index: clangd/Trace.h
===
--- clangd/Trace.h
+++ clangd/Trace.h
@@ -8,60 +8,74 @@
 //===--===//
 //
 // Supports writing performance traces describing clangd's behavior.
-// Traces are written in the Trace Event format supported by chrome's trace
-// viewer (chrome://tracing).
+// Traces are consumed by implementations of the EventTracer interface.
 //
-// The format is documented here:
-// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
 //
 // All APIs are no-ops unless a Session is active (created by ClangdMain).
 //
 //===--===//
 
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRACE_H_
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRACE_H_
 
+#include "Context.h"
 #include "JSONExpr.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 namespace clangd {
 namespace trace {
 
-// A session directs the output of trace events. Only one Session can exist.
-// It should be created before clangd threads are spawned, and destroyed after
-// they exit.
-// TODO: we may want to add pluggable support for other tracing backends.
-class Session {
+/// A consumer of trace events. The events are produced by Spans and trace::log.
+class EventTracer {
 public:
-  // Starts a sessions capturing trace events and writing Trace Event JSON.
-  static std::unique_ptr create(llvm::raw_ostream &OS,
- bool Pretty = false);
-  ~Session();
+  virtual ~EventTracer() = default;
+  /// Consume a trace event.
+  virtual void event(const ContextData &Ctx, llvm::StringRef Phase,
+ json::obj &&Contents) = 0;
+};
 
-private:
-  Session() = default;
+/// Sets up a global EventTracer that consumes events produced by Span and
+/// trace::log. Only one TracingSession can be active at a time and it should be
+/// set up before calling any clangd-specific functions.
+class TracingSession {
+public:
+  TracingSession(EventTracer &Tracer);
+  ~TracingSession();
 };
 
-// Records a single instant event, associated with the current thread.
-void log(const llvm::Twine &Name);
+/// Create an instance of EventTracer that produces an output in the Trace Event
+/// format supported by Chrome's trace viewer (chrome://tracing).
+///
+/// The format is documented here:
+/// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
+///
+/// The implementation supports concurrent calls and can be used as a global
+/// tracer (i.e., can be put into a global Context).
+std::unique_ptr createJSONTracer(llvm::raw_ostream &OS,
+  bool Pretty = false);
 
-// Records

[PATCH] D40489: [clangd] Changed tracing interfaces

2017-12-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 125696.
ilya-biryukov added a comment.
Herald added a subscriber: klimek.

- Update the patch to accomodate changes from tracing and Context patches.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40489

Files:
  clangd/Trace.cpp
  clangd/Trace.h

Index: clangd/Trace.h
===
--- clangd/Trace.h
+++ clangd/Trace.h
@@ -28,12 +28,21 @@
 namespace trace {
 
 /// A consumer of trace events. The events are produced by Spans and trace::log.
+/// Calls to begin_event and end_event with the same name are always properly
+/// nested by using a RAII object (Span).
+/// Implmentations of this interface must be thread-safe.
 class EventTracer {
 public:
   virtual ~EventTracer() = default;
-  /// Consume a trace event.
-  virtual void event(const ContextData &Ctx, llvm::StringRef Phase,
- json::obj &&Contents) = 0;
+
+  /// Called when event with \p Name starts.
+  virtual void begin_event(const ContextData &Ctx, llvm::StringRef Name) = 0;
+  /// Called when event with \p Name ends.
+  virtual void end_event(const ContextData &Ctx, llvm::StringRef Name,
+ json::obj &&Args) = 0;
+  /// Called for instant events.
+  virtual void instant_event(const ContextData &Ctx, llvm::StringRef Name,
+ json::obj &&Args) = 0;
 };
 
 /// Sets up a global EventTracer that consumes events produced by Span and
@@ -67,15 +76,16 @@
 /// SomeJSONExpr is evaluated and copied only if actually needed.
 class Span {
 public:
-  Span(Context &Ctx, std::string Name);
+  Span(Context &Ctx, llvm::StringRef Name);
   ~Span();
 
   /// Returns mutable span metadata if this span is interested.
   /// Prefer to use SPAN_ATTACH rather than accessing this directly.
   json::obj *args() { return Args.get(); }
 
 private:
   const ContextData &Ctx;
+  std::string Name;
   std::unique_ptr Args;
 };
 
Index: clangd/Trace.cpp
===
--- clangd/Trace.cpp
+++ clangd/Trace.cpp
@@ -44,10 +44,23 @@
 Out.flush();
   }
 
+  void begin_event(const ContextData &Ctx, llvm::StringRef Name) override {
+jsonEvent("B", json::obj{{"name", Name}});
+  }
+
+  void end_event(const ContextData &Ctx, llvm::StringRef Name,
+ json::obj &&Args) override {
+jsonEvent("E", json::obj{{"args", std::move(Args)}});
+  }
+
+  void instant_event(const ContextData &Ctx, llvm::StringRef Name,
+ json::obj &&Args) override {
+jsonEvent("i", json::obj{{"name", Name}, {"args", std::move(Args)}});
+  }
+
   // Record an event on the current thread. ph, pid, tid, ts are set.
   // Contents must be a list of the other JSON key/values.
-  void event(const ContextData &Ctx, StringRef Phase,
- json::obj &&Contents) override {
+  void jsonEvent(StringRef Phase, json::obj &&Contents) {
 uint64_t TID = get_threadid();
 std::lock_guard Lock(Mu);
 // If we haven't already, emit metadata describing this thread.
@@ -109,27 +122,21 @@
 void log(Context &Ctx, const Twine &Message) {
   if (!T)
 return;
-  T->event(*Ctx, "i",
-   json::obj{
-   {"name", "Log"},
-   {"args", json::obj{{"Message", Message.str()}}},
-   });
+  T->instant_event(*Ctx, "Log", json::obj{{"Message", Message.str()}});
 }
 
-Span::Span(Context &Ctx, std::string Name) : Ctx(*Ctx) {
+Span::Span(Context &Ctx, llvm::StringRef Name) : Ctx(*Ctx), Name(Name) {
   if (!T)
 return;
-  T->event(this->Ctx, "B", json::obj{{"name", std::move(Name)}});
+  T->begin_event(this->Ctx, this->Name);
   Args = llvm::make_unique();
 }
 
 Span::~Span() {
   if (!T)
 return;
-  if (!Args)
-Args = llvm::make_unique();
-  T->event(Ctx, "E",
-   Args ? json::obj{{"args", std::move(*Args)}} : json::obj{});
+  assert(Args && "Args can't be null at this point");
+  T->end_event(Ctx, Name, std::move(*Args));
 }
 
 } // namespace trace
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33467: Fix LLVM build errors if necent build of GCC 7 is used

2017-12-06 Thread Guilherme Amadio via Phabricator via cfe-commits
amadio added a comment.

The problems fixed here also happen when compiling with Clang-5.0 and C++17 
enabled. What happens is that the assignment to `ProfileFileName` needs a 
conversion of `PGOTestProfileFile` from the `opt` type to `std::string`, but 
the compiler is trying to use a deleted constructor of `opt` instead:

  include/llvm/Support/CommandLine.h:1296:3: note: declared here
 opt(const opt &) = delete;

An alternative way of fixing this, which I have used in ROOT is to write 
`ProfileFileName = StringRef(PGOTestProfileFile);` to help the compiler 
understand what is going on.


Repository:
  rL LLVM

https://reviews.llvm.org/D33467



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


[PATCH] D40888: [ARM] ACLE parallel arithmetic and DSP style multiplications

2017-12-06 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer created this revision.
Herald added subscribers: kristof.beyls, javed.absar, aemerson.

  This is a follow up of r302131, in which we forgot to add SemaChecking
  tests. Adding these tests revealed two problems which have been fixed:
  - added missing intrinsic __qdbl,
  - properly range checking ssat16 and usat16.


https://reviews.llvm.org/D40888

Files:
  include/clang/Basic/BuiltinsARM.def
  lib/Sema/SemaChecking.cpp
  test/Sema/builtins-arm.c

Index: test/Sema/builtins-arm.c
===
--- test/Sema/builtins-arm.c
+++ test/Sema/builtins-arm.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -triple armv7 -target-abi apcs-gnu \
 // RUN:   -fsyntax-only -verify %s
 
+#include 
+
 void f(void *a, void *b) {
   __clear_cache(); // expected-error {{too few arguments to function call, expected 2, have 0}} // expected-note {{'__clear_cache' is a builtin with type 'void (void *, void *)}}
   __clear_cache(a); // expected-error {{too few arguments to function call, expected 2, have 1}}
@@ -136,3 +138,185 @@
   __builtin_arm_mrrc2(15, a, 0); // expected-error {{argument to '__builtin_arm_mrrc2' must be a constant integer}}
   __builtin_arm_mrrc2(15, 0, a); // expected-error {{argument to '__builtin_arm_mrrc2' must be a constant integer}}
 }
+
+void test_9_3_multiplications(int a, int b) {
+  int r;
+  r = __builtin_arm_smulbb(a, b);
+  r = __builtin_arm_smulbb(1, -9);
+
+  r = __builtin_arm_smulbt(a, b);
+  r = __builtin_arm_smulbt(0, b);
+
+  r = __builtin_arm_smultb(a, b);
+  r = __builtin_arm_smultb(5, b);
+
+  r = __builtin_arm_smultt(a, b);
+  r = __builtin_arm_smultt(a, -1);
+
+  r = __builtin_arm_smulwb(a, b);
+  r = __builtin_arm_smulwb(1, 2);
+
+  r = __builtin_arm_smulwt(a, b);
+  r = __builtin_arm_smulwt(-1, -2);
+  r = __builtin_arm_smulwt(-1.0f, -2);
+}
+
+void test_9_4_1_width_specified_saturation(int a, int b) {
+  unsigned u;
+  int s;
+
+  s = __builtin_arm_ssat(8, 2);
+  s = __builtin_arm_ssat(a, 1);
+  s = __builtin_arm_ssat(a, 32);
+  s = __builtin_arm_ssat(a, 0);   // expected-error {{argument should be a value from 1 to 32}}
+  s = __builtin_arm_ssat(a, 33);  // expected-error {{argument should be a value from 1 to 32}}
+  s = __builtin_arm_ssat(a, b);   // expected-error {{argument to '__builtin_arm_ssat' must be a constant integer}}
+
+  u = __builtin_arm_usat(8, 2);
+  u = __builtin_arm_usat(a, 0);
+  u = __builtin_arm_usat(a, 31);
+  u = __builtin_arm_usat(a, 32);  // expected-error {{argument should be a value from 0 to 31}}
+  u = __builtin_arm_usat(a, b);   // expected-error {{argument to '__builtin_arm_usat' must be a constant integer}}
+}
+
+void test_9_4_2_saturating_addition_subtraction(int a, int b) {
+  int s;
+  s = __builtin_arm_qadd(a, b);
+  s = __builtin_arm_qadd(-1, 0);
+
+  s = __builtin_arm_qsub(a, b);
+  s = __builtin_arm_qsub(0, -1);
+
+  s = __builtin_arm_qdbl(a);
+}
+
+void test_9_4_3_accumulating_multiplications(int a, int b, int c) {
+  int s;
+
+  s = __builtin_arm_smlabb(a, b, c);
+  s = __builtin_arm_smlabb(1, b, c);
+  s = __builtin_arm_smlabb(a, 2, c);
+  s = __builtin_arm_smlabb(a, b, -3);
+
+  s = __builtin_arm_smlabt(a, b, c);
+  s = __builtin_arm_smlabt(1, b, c);
+  s = __builtin_arm_smlabt(a, 2, c);
+  s = __builtin_arm_smlabt(a, b, -3);
+
+  s = __builtin_arm_smlatb(a, b, c);
+  s = __builtin_arm_smlatt(1, b, c);
+  s = __builtin_arm_smlawb(a, 2, c);
+  s = __builtin_arm_smlawt(a, b, -3);
+}
+
+void test_9_5_4_parallel_16bit_saturation(int16x2_t a) {
+  unsigned u;
+  int s;
+
+  s = __builtin_arm_ssat16(a, 1);
+  s = __builtin_arm_ssat16(a, 16);
+  s = __builtin_arm_ssat16(a, 0);  // expected-error {{argument should be a value from 1 to 16}}
+  s = __builtin_arm_ssat16(a, 17); // expected-error {{argument should be a value from 1 to 16}}
+
+  u = __builtin_arm_usat16(a, 0);
+  u = __builtin_arm_usat16(a, 15);
+  u = __builtin_arm_usat16(a, 16); // expected-error {{argument should be a value from 0 to 15}}
+}
+
+void test_9_5_5_packing_and_unpacking(int16x2_t a, int8x4_t b, uint16x2_t c, uint8x4_t d) {
+  int16x2_t x;
+  uint16x2_t y;
+
+  x = __builtin_arm_sxtab16(a, b);
+  x = __builtin_arm_sxtab16(1, -1);
+  x = __builtin_arm_sxtb16(b);
+  x = __builtin_arm_sxtb16(-b);
+
+  y = __builtin_arm_uxtab16(c, d);
+  y = __builtin_arm_uxtab16(-1, -2);
+  y = __builtin_arm_uxtb16(d);
+  y = __builtin_arm_uxtb16(-1);
+}
+
+uint8x4_t
+test_9_5_6_parallel_selection(uint8x4_t a, uint8x4_t b) {
+  return __builtin_arm_sel(a, b);
+}
+
+void test_9_5_7_parallel_8bit_addition_substraction(int8x4_t a, int8x4_t b,
+uint8x4_t c, uint8x4_t d) {
+  int8x4_t s;
+  uint8x4_t u;
+
+  s = __builtin_arm_qadd8(a, b);
+  s = __builtin_arm_qsub8(a, b);
+  s = __builtin_arm_sadd8(a, b);
+  s = __builtin_arm_shadd8(a, b);
+  s = __builtin_arm_shsub8(a, b);
+  s = __builtin_arm_ssub8(a, b);
+
+  u = __builtin_arm_uadd8(c, d);
+  u = __builtin_arm_uhadd8(c, d);
+  u = __built

[PATCH] D40485: [clangd] Introduced a Context that stores implicit data

2017-12-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 125712.
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.

- Removed unused helpers from Context.h
- Use assert instead of llvm_unreachable in getExisiting(Key<>)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40485

Files:
  clangd/CMakeLists.txt
  clangd/Context.cpp
  clangd/Context.h
  clangd/TypedValueMap.h
  unittests/clangd/CMakeLists.txt
  unittests/clangd/ContextTests.cpp

Index: unittests/clangd/ContextTests.cpp
===
--- /dev/null
+++ unittests/clangd/ContextTests.cpp
@@ -0,0 +1,71 @@
+//===-- ContextTests.cpp - Context tests *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "Context.h"
+
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+
+TEST(TypedValueMapTests, Simple) {
+  Key IntParam;
+  Key ExtraIntParam;
+
+  clangd::TypedValueMap Ctx;
+
+  ASSERT_TRUE(Ctx.emplace(IntParam, 10));
+  ASSERT_TRUE(Ctx.emplace(ExtraIntParam, 20));
+
+  EXPECT_EQ(*Ctx.get(IntParam), 10);
+  EXPECT_EQ(*Ctx.get(ExtraIntParam), 20);
+
+  ASSERT_FALSE(Ctx.emplace(IntParam, 30));
+
+  ASSERT_TRUE(Ctx.remove(IntParam));
+  EXPECT_EQ(Ctx.get(IntParam), nullptr);
+  EXPECT_EQ(*Ctx.get(ExtraIntParam), 20);
+
+  ASSERT_TRUE(Ctx.emplace(IntParam, 30));
+  EXPECT_EQ(*Ctx.get(IntParam), 30);
+  EXPECT_EQ(*Ctx.get(ExtraIntParam), 20);
+}
+
+TEST(TypedValueMapTests, MoveOps) {
+  Key> Param;
+
+  clangd::TypedValueMap Ctx;
+  Ctx.emplace(Param, llvm::make_unique(10));
+  EXPECT_EQ(**Ctx.get(Param), 10);
+
+  clangd::TypedValueMap NewCtx = std::move(Ctx);
+  EXPECT_EQ(**NewCtx.get(Param), 10);
+}
+
+TEST(ContextTests, Builders) {
+  Key ParentParam;
+  Key ParentAndChildParam;
+  Key ChildParam;
+
+  Context ParentCtx =
+  buildCtx().add(ParentParam, 10).add(ParentAndChildParam, 20);
+  Context ChildCtx =
+  ParentCtx.derive().add(ParentAndChildParam, 30).add(ChildParam, 40);
+
+  EXPECT_EQ(*ParentCtx->get(ParentParam), 10);
+  EXPECT_EQ(*ParentCtx->get(ParentAndChildParam), 20);
+  EXPECT_EQ(ParentCtx->get(ChildParam), nullptr);
+
+  EXPECT_EQ(*ChildCtx->get(ParentParam), 10);
+  EXPECT_EQ(*ChildCtx->get(ParentAndChildParam), 30);
+  EXPECT_EQ(*ChildCtx->get(ChildParam), 40);
+}
+
+} // namespace clangd
+} // namespace clang
Index: unittests/clangd/CMakeLists.txt
===
--- unittests/clangd/CMakeLists.txt
+++ unittests/clangd/CMakeLists.txt
@@ -11,6 +11,7 @@
 add_extra_unittest(ClangdTests
   ClangdTests.cpp
   CodeCompleteTests.cpp
+  ContextTests.cpp
   FuzzyMatchTests.cpp
   JSONExprTests.cpp
   TestFS.cpp
Index: clangd/TypedValueMap.h
===
--- /dev/null
+++ clangd/TypedValueMap.h
@@ -0,0 +1,95 @@
+//===--- TypedValueMap.h - Type-safe heterogenous key-value map -*- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Type-safe heterogenous map.
+//
+//===--===//
+
+#include "llvm/ADT/DenseMap.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+/// Used as identity for map values. Non-movable and non-copyable. Address of
+/// this object is used internally to as keys in a map.
+template  class Key {
+public:
+  static_assert(!std::is_reference::value,
+"Reference arguments to Key<> are not allowed");
+
+  Key() = default;
+
+  Key(Key const &) = delete;
+  Key &operator=(Key const &) = delete;
+  Key(Key &&) = delete;
+  Key &operator=(Key &&) = delete;
+};
+
+/// A type-safe map from Key to T.
+class TypedValueMap {
+public:
+  TypedValueMap() = default;
+  TypedValueMap(const TypedValueMap &) = delete;
+  TypedValueMap(TypedValueMap &&) = default;
+
+  template  Type *get(Key &Key) const {
+auto It = Map.find(&Key);
+if (It == Map.end())
+  return nullptr;
+return static_cast(It->second->getValuePtr());
+  }
+
+  template 
+  bool emplace(Key &Key, Args &&... As) {
+bool Added =
+Map.try_emplace(&Key,
+llvm::make_unique<
+TypedAnyStorage::type>>(
+std::forward(As)...))
+.second;
+return Added;
+  }
+
+  template  bool remove(Key &Key) {
+auto It = Map.find(&Key);
+if (It == Map.end())
+  return false;
+
+Map.erase(It);
+return true;
+  }
+
+private:
+  class AnyStorage {
+  public:
+virtual ~AnyS

[PATCH] D20124: [PCH] Serialize skipped preprocessor ranges

2017-12-06 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik added a comment.

In https://reviews.llvm.org/D20124#943592, @cameron314 wrote:

> Here's the final patch that fixes `clang_getSkippedRegions` with regions in 
> the preamble (as well as serializing the skipped regions in the PCH file).


Works fine for me, thanks! Test from the bug report is fixed by this one.

You should probably add "Fixes PR34971." to the summary.

@erikjv @ilya-biryukov - please review as you know the details here :)


https://reviews.llvm.org/D20124



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


[PATCH] D40488: [clangd] Implemented tracing using Context

2017-12-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 125713.
ilya-biryukov added a comment.

- Use getExistingKey instead of getPtr in JSONRPCDispatcher.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40488

Files:
  clangd/ClangdUnit.cpp
  clangd/JSONRPCDispatcher.cpp
  clangd/Trace.cpp
  clangd/Trace.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/TraceTests.cpp

Index: unittests/clangd/TraceTests.cpp
===
--- unittests/clangd/TraceTests.cpp
+++ unittests/clangd/TraceTests.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "Context.h"
 #include "Trace.h"
 
 #include "llvm/ADT/DenseMap.h"
@@ -74,10 +75,11 @@
   std::string JSON;
   {
 raw_string_ostream OS(JSON);
-auto Session = trace::Session::create(OS);
+auto JSONTracer = trace::createJSONTracer(OS);
+trace::TracingSession Session(*JSONTracer);
 {
-  trace::Span S("A");
-  trace::log("B");
+  trace::Span S(emptyCtx(), "A");
+  trace::log(emptyCtx(), "B");
 }
   }
 
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -115,19 +115,25 @@
<< EC.message();
 }
   }
+
+  // Setup tracing facilities.
   llvm::Optional TraceStream;
-  std::unique_ptr TraceSession;
+  std::unique_ptr Tracer;
   if (!TraceFile.empty()) {
 std::error_code EC;
 TraceStream.emplace(TraceFile, /*ref*/ EC, llvm::sys::fs::F_RW);
 if (EC) {
   TraceFile.reset();
   llvm::errs() << "Error while opening trace file: " << EC.message();
 } else {
-  TraceSession = trace::Session::create(*TraceStream, PrettyPrint);
+  Tracer = trace::createJSONTracer(*TraceStream, PrettyPrint);
 }
   }
 
+  llvm::Optional TracingSession;
+  if (Tracer)
+TracingSession.emplace(*Tracer);
+
   llvm::raw_ostream &Outs = llvm::outs();
   llvm::raw_ostream &Logs = llvm::errs();
   JSONOutput Out(Outs, Logs,
Index: clangd/Trace.h
===
--- clangd/Trace.h
+++ clangd/Trace.h
@@ -8,60 +8,74 @@
 //===--===//
 //
 // Supports writing performance traces describing clangd's behavior.
-// Traces are written in the Trace Event format supported by chrome's trace
-// viewer (chrome://tracing).
+// Traces are consumed by implementations of the EventTracer interface.
 //
-// The format is documented here:
-// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
 //
 // All APIs are no-ops unless a Session is active (created by ClangdMain).
 //
 //===--===//
 
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRACE_H_
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRACE_H_
 
+#include "Context.h"
 #include "JSONExpr.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 namespace clangd {
 namespace trace {
 
-// A session directs the output of trace events. Only one Session can exist.
-// It should be created before clangd threads are spawned, and destroyed after
-// they exit.
-// TODO: we may want to add pluggable support for other tracing backends.
-class Session {
+/// A consumer of trace events. The events are produced by Spans and trace::log.
+class EventTracer {
 public:
-  // Starts a sessions capturing trace events and writing Trace Event JSON.
-  static std::unique_ptr create(llvm::raw_ostream &OS,
- bool Pretty = false);
-  ~Session();
+  virtual ~EventTracer() = default;
+  /// Consume a trace event.
+  virtual void event(const ContextData &Ctx, llvm::StringRef Phase,
+ json::obj &&Contents) = 0;
+};
 
-private:
-  Session() = default;
+/// Sets up a global EventTracer that consumes events produced by Span and
+/// trace::log. Only one TracingSession can be active at a time and it should be
+/// set up before calling any clangd-specific functions.
+class TracingSession {
+public:
+  TracingSession(EventTracer &Tracer);
+  ~TracingSession();
 };
 
-// Records a single instant event, associated with the current thread.
-void log(const llvm::Twine &Name);
+/// Create an instance of EventTracer that produces an output in the Trace Event
+/// format supported by Chrome's trace viewer (chrome://tracing).
+///
+/// The format is documented here:
+/// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
+///
+/// The implementation supports concurrent calls and can be used as a global
+/// tracer (i.e., can be put into a global Context).
+std::unique_ptr createJSONTracer(llvm::raw_ostream &OS,
+  bool Pretty = false);
 
-// Records an event whose duration is the lifetime of the Span obje

[PATCH] D40888: [ARM] ACLE parallel arithmetic and DSP style multiplications

2017-12-06 Thread Sam Parker via Phabricator via cfe-commits
samparker added a comment.

Thanks for looking into this!




Comment at: include/clang/Basic/BuiltinsARM.def:39
 BUILTIN(__builtin_arm_qsub, "iii", "nc")
+BUILTIN(__builtin_arm_qdbl, "ii", "nc")
 BUILTIN(__builtin_arm_ssat, "iiUi", "nc")

Do we now need a codegen tests for this one?



Comment at: test/Sema/builtins-arm.c:161
+  r = __builtin_arm_smulwt(-1, -2);
+  r = __builtin_arm_smulwt(-1.0f, -2);
+}

Interesting that this doesn't give an error?



Comment at: test/Sema/builtins-arm.c:236
+  y = __builtin_arm_uxtab16(c, d);
+  y = __builtin_arm_uxtab16(-1, -2);
+  y = __builtin_arm_uxtb16(d);

Can / should we warn the user when using signed arguments? Looks like I missed 
the unsigned qualifiers in the original patch.


https://reviews.llvm.org/D40888



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


[PATCH] D40895: Ignore pointers to incomplete types when diagnosing misaligned addresses

2017-12-06 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 created this revision.

This is a fix for PR35509 in which we crash because we attempt to compute the 
alignment of an incomplete type.


https://reviews.llvm.org/D40895

Files:
  lib/Sema/SemaChecking.cpp
  test/SemaCXX/address-packed.cpp


Index: test/SemaCXX/address-packed.cpp
===
--- test/SemaCXX/address-packed.cpp
+++ test/SemaCXX/address-packed.cpp
@@ -112,3 +112,12 @@
   S s3;
   s3.get(); // expected-note {{in instantiation of member function 
'S::get'}}
 }
+
+// PR35509
+typedef long L1;
+struct Incomplete;
+struct S2 {
+  L1 d;
+  Incomplete *e() const;
+} __attribute__((packed));
+Incomplete *S2::e() const { return (Incomplete *)&d; } // no-warning
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -12453,8 +12453,9 @@
   MisalignedMember(Op));
   if (MA != MisalignedMembers.end() &&
   (T->isIntegerType() ||
-   (T->isPointerType() &&
-Context.getTypeAlignInChars(T->getPointeeType()) <= 
MA->Alignment)))
+   (T->isPointerType() && (T->getPointeeType()->isIncompleteType() ||
+   Context.getTypeAlignInChars(
+   T->getPointeeType()) <= 
MA->Alignment
 MisalignedMembers.erase(MA);
 }
   }


Index: test/SemaCXX/address-packed.cpp
===
--- test/SemaCXX/address-packed.cpp
+++ test/SemaCXX/address-packed.cpp
@@ -112,3 +112,12 @@
   S s3;
   s3.get(); // expected-note {{in instantiation of member function 'S::get'}}
 }
+
+// PR35509
+typedef long L1;
+struct Incomplete;
+struct S2 {
+  L1 d;
+  Incomplete *e() const;
+} __attribute__((packed));
+Incomplete *S2::e() const { return (Incomplete *)&d; } // no-warning
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -12453,8 +12453,9 @@
   MisalignedMember(Op));
   if (MA != MisalignedMembers.end() &&
   (T->isIntegerType() ||
-   (T->isPointerType() &&
-Context.getTypeAlignInChars(T->getPointeeType()) <= MA->Alignment)))
+   (T->isPointerType() && (T->getPointeeType()->isIncompleteType() ||
+   Context.getTypeAlignInChars(
+   T->getPointeeType()) <= MA->Alignment
 MisalignedMembers.erase(MA);
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40888: [ARM] ACLE parallel arithmetic and DSP style multiplications

2017-12-06 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added inline comments.



Comment at: include/clang/Basic/BuiltinsARM.def:39
 BUILTIN(__builtin_arm_qsub, "iii", "nc")
+BUILTIN(__builtin_arm_qdbl, "ii", "nc")
 BUILTIN(__builtin_arm_ssat, "iiUi", "nc")

samparker wrote:
> Do we now need a codegen tests for this one?
It's there already. 



Comment at: test/Sema/builtins-arm.c:161
+  r = __builtin_arm_smulwt(-1, -2);
+  r = __builtin_arm_smulwt(-1.0f, -2);
+}

samparker wrote:
> Interesting that this doesn't give an error?
No, was just playing a little bit with "6.3.1.4  Real floating and integer" 
conversions here: "When a finite value of real floating type is converted to an 
integer type other than_Bool, the fractional part is discarded ... "



Comment at: test/Sema/builtins-arm.c:236
+  y = __builtin_arm_uxtab16(c, d);
+  y = __builtin_arm_uxtab16(-1, -2);
+  y = __builtin_arm_uxtb16(d);

samparker wrote:
> Can / should we warn the user when using signed arguments? Looks like I 
> missed the unsigned qualifiers in the original patch.
Similarly, was playing a little bit with implicit conversions here: -1 is 
converted to unsigned. So, it's ok.


https://reviews.llvm.org/D40888



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


r319896 - [OPENMP] Initial codegen for `teams distribute simd` directive.

2017-12-06 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Dec  6 06:31:09 2017
New Revision: 319896

URL: http://llvm.org/viewvc/llvm-project?rev=319896&view=rev
Log:
[OPENMP] Initial codegen for `teams distribute simd` directive.

Host + default devices codegen for `teams distribute simd` directive.

Added:
cfe/trunk/test/OpenMP/teams_distribute_simd_codegen.cpp
cfe/trunk/test/OpenMP/teams_distribute_simd_collapse_codegen.cpp
cfe/trunk/test/OpenMP/teams_distribute_simd_dist_schedule_codegen.cpp
cfe/trunk/test/OpenMP/teams_distribute_simd_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/teams_distribute_simd_lastprivate_codegen.cpp
cfe/trunk/test/OpenMP/teams_distribute_simd_private_codegen.cpp
cfe/trunk/test/OpenMP/teams_distribute_simd_reduction_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=319896&r1=319895&r2=319896&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Wed Dec  6 06:31:09 2017
@@ -2091,18 +2091,6 @@ void CodeGenFunction::EmitOMPTargetSimdD
   emitCommonOMPTargetDirective(*this, S, CodeGen);
 }
 
-void CodeGenFunction::EmitOMPTeamsDistributeSimdDirective(
-const OMPTeamsDistributeSimdDirective &S) {
-  OMPLexicalScope Scope(*this, S, /*AsInlined=*/true);
-  CGM.getOpenMPRuntime().emitInlinedDirective(
-  *this, OMPD_teams_distribute_simd,
-  [&S](CodeGenFunction &CGF, PrePostActionTy &) {
-OMPLoopScope PreInitScope(CGF, S);
-CGF.EmitStmt(
-cast(S.getAssociatedStmt())->getCapturedStmt());
-  });
-}
-
 void CodeGenFunction::EmitOMPTargetTeamsDistributeDirective(
 const OMPTargetTeamsDistributeDirective &S) {
   OMPLexicalScope Scope(*this, S, /*AsInlined=*/true);
@@ -3099,7 +3087,8 @@ void CodeGenFunction::EmitOMPDistributeL
   }
   EmitOMPPrivateClause(S, LoopScope);
   if (isOpenMPSimdDirective(S.getDirectiveKind()) &&
-  !isOpenMPParallelDirective(S.getDirectiveKind()))
+  !isOpenMPParallelDirective(S.getDirectiveKind()) &&
+  !isOpenMPTeamsDirective(S.getDirectiveKind()))
 EmitOMPReductionClauseInit(S, LoopScope);
   HasLastprivateClause = EmitOMPLastprivateClauseInit(S, LoopScope);
   EmitOMPPrivateLoopCounters(S, LoopScope);
@@ -3921,6 +3910,27 @@ void CodeGenFunction::EmitOMPTeamsDistri
   emitPostUpdateForReductionClause(*this, S,
[](CodeGenFunction &) { return nullptr; });
 }
+
+void CodeGenFunction::EmitOMPTeamsDistributeSimdDirective(
+const OMPTeamsDistributeSimdDirective &S) {
+  auto &&CodeGenDistribute = [&S](CodeGenFunction &CGF, PrePostActionTy &) {
+CGF.EmitOMPDistributeLoop(S, emitOMPLoopBodyWithStopPoint, S.getInc());
+  };
+
+  // Emit teams region as a standalone region.
+  auto &&CodeGen = [&S, &CodeGenDistribute](CodeGenFunction &CGF,
+PrePostActionTy &) {
+OMPPrivateScope PrivateScope(CGF);
+CGF.EmitOMPReductionClauseInit(S, PrivateScope);
+(void)PrivateScope.Privatize();
+CGF.CGM.getOpenMPRuntime().emitInlinedDirective(CGF, OMPD_simd,
+CodeGenDistribute);
+CGF.EmitOMPReductionClauseFinal(S, /*ReductionKind=*/OMPD_teams);
+  };
+  emitCommonOMPTeamsDirective(*this, S, OMPD_distribute_simd, CodeGen);
+  emitPostUpdateForReductionClause(*this, S,
+   [](CodeGenFunction &) { return nullptr; });
+}
 
 void CodeGenFunction::EmitOMPTeamsDistributeParallelForDirective(
 const OMPTeamsDistributeParallelForDirective &S) {

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=319896&r1=319895&r2=319896&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Wed Dec  6 06:31:09 2017
@@ -2075,7 +2075,8 @@ void Sema::ActOnOpenMPRegionStart(OpenMP
   case OMPD_parallel_for_simd:
   case OMPD_parallel_sections:
   case OMPD_teams:
-  case OMPD_teams_distribute: {
+  case OMPD_teams_distribute:
+  case OMPD_teams_distribute_simd: {
 QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1);
 QualType KmpInt32PtrTy =
 Context.getPointerType(KmpInt32Ty).withConst().withRestrict();
@@ -2198,7 +2199,6 @@ void Sema::ActOnOpenMPRegionStart(OpenMP
   }
   case OMPD_distribute_parallel_for_simd:
   case OMPD_distribute_parallel_for:
-  case OMPD_teams_distribute_simd:
   case OMPD_target_teams_distribute:
   case OMPD_target_teams_distribute_parallel_for:
   case OMPD_target_teams_distribute_parallel_for_simd:
@@ -7101,13 +7101,25 @@ StmtResult Sema::ActOnOpenMPTeamsDistrib
   // Th

[PATCH] D40884: [Index] Add setPreprocessor member to IndexDataConsumer.

2017-12-06 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

You can get the preprocessor from the ASTContext, no?


Repository:
  rC Clang

https://reviews.llvm.org/D40884



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


[PATCH] D39457: [OPENMP] Current status of OpenMP support.

2017-12-06 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 125722.
ABataev added a comment.

Update


Repository:
  rC Clang

https://reviews.llvm.org/D39457

Files:
  docs/OpenMPSupport.rst
  docs/index.rst


Index: docs/index.rst
===
--- docs/index.rst
+++ docs/index.rst
@@ -39,6 +39,7 @@
SourceBasedCodeCoverage
Modules
MSVCCompatibility
+   OpenMPSupport
ThinLTO
CommandGuide/index
FAQ
Index: docs/OpenMPSupport.rst
===
--- /dev/null
+++ docs/OpenMPSupport.rst
@@ -0,0 +1,74 @@
+.. raw:: html
+
+  
+.none { background-color: #FF }
+.partial { background-color: #99 }
+.good { background-color: #CCFF99 }
+  
+
+.. role:: none
+.. role:: partial
+.. role:: good
+
+==
+OpenMP Support
+==
+
+Clang fully supports OpenMP 3.1 + some elements of OpenMP 4.5. Clang supports 
offloading to X86_64, AArch64, PPC64[LE] and Cuda devices.
+The status of major OpenMP 4.5 features support in Clang.
+
+Standalone directives
+=
+
+* #pragma omp [for] simd: :good:`Complete`.
+
+* #pragma omp declare simd: :partial:`Partial`.  We support parsing/semantic
+  analysis + generation of special attributes for X86 target, but still
+  missing the LLVM pass for vectorization.
+
+* #pragma omp taskloop [simd]: :good:`Complete`.
+
+* #pragma omp target [enter|exit] data: :good:`Mostly complete`.  Some rework 
is
+  required for better stability.
+
+* #pragma omp target update: :good:`Mostly complete`.  Some rework is
+  required for better stability.
+
+* #pragma omp target: :partial:`Partial`.  No support for the `reduction`,
+  `nowait` and `depend` clauses.
+
+* #pragma omp declare target: :partial:`Partial`.  No full codegen support.
+
+* #pragma omp teams: :good:`Complete`.
+
+* #pragma omp distribute [simd]: :good:`Complete`.
+
+* #pragma omp distribute parallel for [simd]: :good:`Complete`.
+
+Combined directives
+===
+
+* #pragma omp parallel for simd: :good:`Complete`.
+
+* #pragma omp target parallel: :partial:`Partial`.  No support for the 
`reduction`,
+  `nowait` and `depend` clauses.
+
+* #pragma omp target parallel for [simd]: :partial:`Partial`.  No support for 
the `reduction`,
+  `nowait` and `depend` clauses.
+
+* #pragma omp target simd: :partial:`Partial`.  No support for the `reduction`,
+  `nowait` and `depend` clauses.
+
+* #pragma omp target teams: :partial:`Partial`.  No support for the 
`reduction`,
+  `nowait` and `depend` clauses.
+
+* #pragma omp teams distribute [simd]: :good:`Complete`.
+
+* #pragma omp target teams distribute [simd]: :partial:`Partial`.  No full 
codegen support.
+
+* #pragma omp teams distribute parallel for [simd]: :good:`Complete`.
+
+* #pragma omp target teams distribute parallel for [simd]: :partial:`Partial`. 
 No full codegen support.
+
+Clang does not support any constructs/updates from upcoming OpenMP 5.0 except 
for `reduction`-based clauses in the `task`-based directives.
+


Index: docs/index.rst
===
--- docs/index.rst
+++ docs/index.rst
@@ -39,6 +39,7 @@
SourceBasedCodeCoverage
Modules
MSVCCompatibility
+   OpenMPSupport
ThinLTO
CommandGuide/index
FAQ
Index: docs/OpenMPSupport.rst
===
--- /dev/null
+++ docs/OpenMPSupport.rst
@@ -0,0 +1,74 @@
+.. raw:: html
+
+  
+.none { background-color: #FF }
+.partial { background-color: #99 }
+.good { background-color: #CCFF99 }
+  
+
+.. role:: none
+.. role:: partial
+.. role:: good
+
+==
+OpenMP Support
+==
+
+Clang fully supports OpenMP 3.1 + some elements of OpenMP 4.5. Clang supports offloading to X86_64, AArch64, PPC64[LE] and Cuda devices.
+The status of major OpenMP 4.5 features support in Clang.
+
+Standalone directives
+=
+
+* #pragma omp [for] simd: :good:`Complete`.
+
+* #pragma omp declare simd: :partial:`Partial`.  We support parsing/semantic
+  analysis + generation of special attributes for X86 target, but still
+  missing the LLVM pass for vectorization.
+
+* #pragma omp taskloop [simd]: :good:`Complete`.
+
+* #pragma omp target [enter|exit] data: :good:`Mostly complete`.  Some rework is
+  required for better stability.
+
+* #pragma omp target update: :good:`Mostly complete`.  Some rework is
+  required for better stability.
+
+* #pragma omp target: :partial:`Partial`.  No support for the `reduction`,
+  `nowait` and `depend` clauses.
+
+* #pragma omp declare target: :partial:`Partial`.  No full codegen support.
+
+* #pragma omp teams: :good:`Complete`.
+
+* #pragma omp distribute [simd]: :good:`Complete`.
+
+* #pragma omp distribute parallel for [simd]: :good:`Complete`.
+
+Combined directives
+===
+
+* #pragma omp parallel for simd: :good:`Complete`.
+
+* #pragma omp 

[PATCH] D40864: [Darwin] Add a new -mstack-probe option and enable by default

2017-12-06 Thread Amara Emerson via Phabricator via cfe-commits
aemerson added inline comments.



Comment at: lib/CodeGen/BackendUtil.cpp:442
   Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
+  Options.EnableStackProbe = CodeGenOpts.StackProbe;
 

ahatanak wrote:
> Is there a reason you can't use function attributes 
> "probe-stack"="___chkstk_darwin" and "stack-probe-size"=4096 instead of 
> setting a TargetOptions flag here? If you intend to use stack probing with 
> LTO, I think you need function attributes. Also, it looks like that would 
> simplify the changes made to X86 backend.
I don't think there's any reason not to. Is it worth specifying the probe size 
itself given that it'll be a known fixed value? It could be misleading to give 
a probe size which only has a single valid value for Darwin.



Comment at: lib/Driver/ToolChains/Clang.cpp:3955
+CmdArgs.push_back("-mstack-probe");
+
   if (Args.hasArg(options::OPT_mstack_probe_size)) {

ahatanak wrote:
> Just to confirm, is stack probing going to be enabled unconditionally on 
> Darwin unless the user disables it with mno-stack-probe?
Yes that's the intention. However on D40863 there's discussion that it might be 
better to restrict to newer Darwin targets.


Repository:
  rC Clang

https://reviews.llvm.org/D40864



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


[PATCH] D36672: [clang-tidy] readability-non-const-parameter: fixit on all function declarations

2017-12-06 Thread Anders Rönnholm via Phabricator via cfe-commits
AndersRonnholm abandoned this revision.
AndersRonnholm added a comment.

Fixed by https://reviews.llvm.org/rL319021. At least for c/c++ not sure if it 
handles objective-c.


Repository:
  rL LLVM

https://reviews.llvm.org/D36672



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


r319897 - [OPENMP] Improve error message for mapping union members.

2017-12-06 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Dec  6 07:04:36 2017
New Revision: 319897

URL: http://llvm.org/viewvc/llvm-project?rev=319897&view=rev
Log:
[OPENMP] Improve error message for mapping union members.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/test/OpenMP/target_map_messages.cpp
cfe/trunk/test/OpenMP/target_teams_map_messages.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=319897&r1=319896&r2=319897&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Dec  6 07:04:36 
2017
@@ -8617,7 +8617,7 @@ def err_omp_bit_fields_forbidden_in_clau
 def err_array_section_does_not_specify_contiguous_storage : Error<
   "array section does not specify contiguous storage">;
 def err_omp_union_type_not_allowed : Error<
-  "mapped storage cannot be derived from a union">;
+  "mapping of union members is not allowed">;
 def err_omp_expected_access_to_data_field : Error<
   "expected access to data field">;
 def err_omp_multiple_array_items_in_map_clause : Error<

Modified: cfe/trunk/test/OpenMP/target_map_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_map_messages.cpp?rev=319897&r1=319896&r2=319897&view=diff
==
--- cfe/trunk/test/OpenMP/target_map_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/target_map_messages.cpp Wed Dec  6 07:04:36 2017
@@ -274,7 +274,7 @@ void SAclient(int arg) {
   {}
   #pragma omp target map((p+1)->A)  // expected-error {{expected expression 
containing only member accesses and/or array sections based on named variables}}
   {}
-  #pragma omp target map(u.B)  // expected-error {{mapped storage cannot be 
derived from a union}}
+  #pragma omp target map(u.B)  // expected-error {{mapping of union members is 
not allowed}}
   {}
   #pragma omp target
   {

Modified: cfe/trunk/test/OpenMP/target_teams_map_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_teams_map_messages.cpp?rev=319897&r1=319896&r2=319897&view=diff
==
--- cfe/trunk/test/OpenMP/target_teams_map_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/target_teams_map_messages.cpp Wed Dec  6 07:04:36 2017
@@ -265,7 +265,7 @@ void SAclient(int arg) {
   {}
   #pragma omp target teams map((p+1)->A)  // expected-error {{expected 
expression containing only member accesses and/or array sections based on named 
variables}}
   {}
-  #pragma omp target teams map(u.B)  // expected-error {{mapped storage cannot 
be derived from a union}}
+  #pragma omp target teams map(u.B)  // expected-error {{mapping of union 
members is not allowed}}
   {}
 
   #pragma omp target data map(to: r.C) //expected-note {{used here}}


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


[PATCH] D40485: [clangd] Introduced a Context that stores implicit data

2017-12-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

There's a couple of points where we might be a bit stuck on complexity vs X 
tradeoffs (map + contextbuilder, and some of the convenience APIs).

Just want to mention: if I find these things complex, it doesn't mean I think 
they're bad code, or even that you should agree they're complex! Happy to pull 
in a third opinion if you think we can't or shouldn't live without them.




Comment at: clangd/Context.h:11
+// Context for storing and retrieving implicit data. Useful for passing 
implicit
+// parameters on a per-request basis.
+//

This could use a bit more I think, e.g.

A context is an immutable container for per-request data that must be 
propagated through layers that don't care about it.
An example is a request ID that we may want to use when logging.

Conceptually, a context is a heterogeneous map, T>. Each key has 
an associated value type, which allows the map to be typesafe.

You can't add data to an existing context, instead you create a new 
immutable context derived from it with extra data added. When you retrieve 
data, the context will walk up the parent chain until the key is found.

Contexts should be:
 - passed by reference when calling synchronous functions
 - passed by value (move) when calling asynchronous functions. The callback 
will receive the context again.
 - copied only when 'forking' an asynchronous computation that we don't 
wait for

Some of this is on the class comment - this seems fine but the Context class 
should then be the first thing in the file.



Comment at: clangd/Context.h:25
+
+class ContextData {
+public:

IIUC, the only reason we expose separate `Context` and `ContextData` types is 
to give things like Span a stable reference to hold onto (`ContextData*`).

Could we use `Context` instead (a copy)? Then we incur `shared_ptr` overhead 
for span creation, but greatly simplify the interface.
If we want to avoid the overhead, the Span could maybe grab whatever it needs 
out of the context at construction time, for use in the destructor.

Either way, we should make sure `Context` is front-and-center in this header, 
and I hope we can hide ContextData entirely.



Comment at: clangd/Context.h:32
+  /// specified for \p Key, return null.
+  template  Type *get(Key &Key) const {
+if (auto Val = Data.get(Key))

nit: const Key&, and below



Comment at: clangd/Context.h:32
+  /// specified for \p Key, return null.
+  template  Type *get(Key &Key) const {
+if (auto Val = Data.get(Key))

sammccall wrote:
> nit: const Key&, and below
this isn't usually how we define const-correctness for containers.
A const method shouldn't return a mutable reference to the contained object.



Comment at: clangd/Context.h:42
+  /// Must not be called for keys that are not in the map.
+  template  Type &getExisting(Key &Key) const {
+auto Val = get(Key);

I'd prefer the standard name `at` for this function (assert vs throw being 
pretty minor I think), but YMMV



Comment at: clangd/Context.h:49
+
+  /// A helper to get a string value as StringRef. Returns empty StringRef if 
\p
+  /// StrKey does not exist in a map.

This is unused - remove until we need it?



Comment at: clangd/Context.h:61
+  /// exist in a map.
+  template  Type *getPtr(Key &Key) const {
+if (auto Val = get(Key))

This is only used where getExisting() would be better - remove until we need it?



Comment at: clangd/Context.h:68
+private:
+  // We need to make sure Parent is destroyed after Data. The order of members
+  // is important.

Nit: is destroyed after --> outlives?

If you're going to repeat that this is important, then say why :-)



Comment at: clangd/Context.h:82
+/// used as parents for some other Contexts.
+class Context {
+public:

If we're going to define this as a real class (rather than use/inherit 
`shared_ptr`), we should really be able to put the API on it directly (rather 
than require the user to `->`) 



Comment at: clangd/Context.h:96
+
+  ContextBuilder derive();
+

If we discourage copies, you probably want a moving `ContextBuilder derive() 
&&` overload



Comment at: clangd/Context.h:96
+
+  ContextBuilder derive();
+

sammccall wrote:
> If we discourage copies, you probably want a moving `ContextBuilder derive() 
> &&` overload
nit: const



Comment at: clangd/Context.h:139
+/// that require a Context when no explicit Context is not available.
+Context &emptyCtx();
+

nit: how do you feel about Context::empty()? it ties the name to the type more 
clearly, I think.



Comment at: clangd/Context.h:139
+/// that require

[PATCH] D39027: [docs][refactor] Add a new tutorial that talks about how one can implement refactoring actions

2017-12-06 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: docs/RefactoringActionTutorial.rst:7
+
+  This tutorial talks about a work-in-progress library in Clang.
+  Some of the described features might not be available yet in trunk, but 
should

hokein wrote:
> I'm a bit concerned about this. If we check in this doc before all features 
> are implemented, it probably confuses users.
> 
I'm not too concerned about this. The code is already there, so I believe more 
docs are better :)



Comment at: docs/RefactoringActionTutorial.rst:41-42
+  int computeArrayOffset(int x, int y) {
+if (x >= 0) {
+  if (y >= 0) {
+return x * 4 + y;

This looks like an example that's a better fit for clang-tidy?
Perhaps a good example would be replacing all int x, int y parameters to an 
const Point& parameter or something like that?


Repository:
  rL LLVM

https://reviews.llvm.org/D39027



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


[PATCH] D40485: [clangd] Introduced a Context that stores implicit data

2017-12-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Oops, forgot one important question!

BTW, phabricator seems to have misaligned all my previous comments (you updated 
the diff before I submitted them I guess). Let me know if any of them don't 
make sense now!




Comment at: clangd/Context.h:63
+/// used as parents for some other Contexts.
+class Context {
+public:

I think we should strongly consider calling the class Ctx over Context. It's 
going to appear in many function signatures, and I'm not sure the extra 
characters buy us anything considering the abbreviation is pretty unambiguous, 
and the full version isn't very explicit.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40485



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


[PATCH] D37813: clang-format: better handle namespace macros

2017-12-06 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

> Ok, that's probably where our different opinions come from - I would want a 
> macro to be formatted to reflect how it's implemented, because otherwise I'm 
> going to be surprised when I look at the implementation, and I consider 
> surprises to be something to avoid in programming in general, where possible.

As "author of the coding rules" (and thus writer of clang-format config), I 
would agree with you.
But I think the tool itself should not decide to enforce this : maybe there are 
cases where the macro is "conceptually" a namespace, but should be indented as 
a class ; in this case I think the tool should quite dumb, and simply do what 
was asked: if asked to format the macro as a namespace, it should do it, 
whatever the implementation is.

That said, on top of this "user choice" the tool could be smart, and 
automatically handle all macros based on their actual implementation: if the 
macro is actually implemented with a namespace (and there is no "explicit" 
definition of how it should be handled), then indeed the tool could format the 
whole block as a namespace, and so on... But unfortunately that would imply 
parsing numerous #include to get the definitions, and is definitely not the 
goal of this patch: this patch is really about letting the "user" decide how to 
handle the macro.

> That said, I'm also then a bit confused by your tests - they seem to 
> currently format a mixture of namespace and class formatting, and combine the 
> indentation of a class-scope with namespace end comments.

This should not be the case: the goal here is that the macro is handled exactly 
like a namespace.
The NamespaceEndCommentFixer tests indeed contain some indentation, but it is 
not significant and is there only because I copied existing test cases and 
followed the same "style": but these tests do not actually perform any 
indentation, they simply handle the "end comment".
Do you have any specific test which confuses you?


https://reviews.llvm.org/D37813



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


[PATCH] D40897: [clangd] Introduce a "Symbol" class.

2017-12-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
Herald added subscribers: mgorny, klimek.

- The "Symbol" class represents a C++ symbol in the codebase, containing all 
the information of a C++ symbol needed by clangd. clangd will use it in 
clangd's AST/dynamic index and global/static index (code completion and code 
navigation).
- The SymbolCollector (another IndexAction) will be used to recollect the 
symbols when the source file is changed (for ASTIndex), or to generate all C++ 
symbols for the whole project.

In the long term (when index-while-building is ready), clangd should share a
same "Symbol" structure and IndexAction with index-while-building, but
for now we want to have some stuff working in clangd.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40897

Files:
  clangd/CMakeLists.txt
  clangd/Symbol.cpp
  clangd/Symbol.h
  unittests/clangd/CMakeLists.txt
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- /dev/null
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -0,0 +1,110 @@
+//===-- SymbolCollectorTests.cpp  ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "Symbol.h"
+#include "clang/Index/IndexingAction.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
+#include "clang/Basic/VirtualFileSystem.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+
+#include 
+#include 
+
+using testing::ElementsAre;
+using testing::Eq;
+using testing::Field;
+
+namespace clang {
+namespace clangd {
+
+namespace {
+class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
+ public:
+  SymbolIndexActionFactory() = default;
+
+  clang::ASTFrontendAction *create() override {
+index::IndexingOptions IndexOpts;
+IndexOpts.SystemSymbolFilter =
+index::IndexingOptions::SystemSymbolFilterKind::All;
+IndexOpts.IndexFunctionLocals = false;
+Collector = std::make_shared();
+FrontendAction *Action =
+index::createIndexingAction(Collector, IndexOpts, nullptr).release();
+return llvm::cast(Action);
+  }
+
+  std::shared_ptr Collector;
+};
+
+class SymbolCollectorTest : public ::testing::Test {
+public:
+  bool runSymbolCollector(StringRef HeaderCode, StringRef MainCode) {
+llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+new vfs::InMemoryFileSystem);
+llvm::IntrusiveRefCntPtr Files(
+new FileManager(FileSystemOptions(), InMemoryFileSystem));
+
+const std::string FileName = "symbol.cc";
+const std::string HeaderName = "symbols.h";
+auto Factory = llvm::make_unique();
+
+tooling::ToolInvocation Invocation(
+{"symbol_collector", "-fsyntax-only", "-std=c++11", FileName},
+Factory->create(), Files.get(),
+std::make_shared());
+
+InMemoryFileSystem->addFile(HeaderName, 0,
+llvm::MemoryBuffer::getMemBuffer(HeaderCode));
+
+std::string Content = "#include\"" + std::string(HeaderName) + "\"";
+Content += "\n" + MainCode.str();
+InMemoryFileSystem->addFile(FileName, 0,
+llvm::MemoryBuffer::getMemBuffer(Content));
+Invocation.run();
+Symbols = Factory->Collector->getSymbols();
+return true;
+  }
+
+protected:
+  std::set Symbols;
+};
+
+TEST_F(SymbolCollectorTest, CollectSymbol) {
+  const std::string Header = R"(
+class Foo {
+ void f();
+};
+void f1();
+inline void f2() {}
+  )";
+  const std::string Main = R"(
+namespace {
+void ff() {} // ignore
+}
+void f1() {}
+  )";
+  runSymbolCollector(Header, Main);
+  EXPECT_THAT(Symbols,
+  UnorderedElementsAre(Field(&Symbol::QualifiedName, Eq("Foo")),
+   Field(&Symbol::QualifiedName, Eq("Foo::f")),
+   Field(&Symbol::QualifiedName, Eq("f1")),
+   Field(&Symbol::QualifiedName, Eq("f2";
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: unittests/clangd/CMakeLists.txt
===
--- unittests/clangd/CMakeLists.txt
+++ unittests/clangd/CMakeLists.txt
@@ -15,6 +15,7 @@
   JSONExprTests.cpp
   TestFS.cpp
   TraceTests.cpp
+  SymbolCollectorTests.cpp
   )
 
 target_link_libraries(ClangdTests
Index: clangd/Symbol.h
===
--- /dev/null
+++ clangd/Symbol.h
@@ -

[PATCH] D40485: [clangd] Introduced a Context that stores implicit data

2017-12-06 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/Context.h:63
+/// used as parents for some other Contexts.
+class Context {
+public:

sammccall wrote:
> I think we should strongly consider calling the class Ctx over Context. It's 
> going to appear in many function signatures, and I'm not sure the extra 
> characters buy us anything considering the abbreviation is pretty 
> unambiguous, and the full version isn't very explicit.
I have no opinion on the names... Just wondering: if the class is called `Ctx`, 
what name do you suggest to use for variables? With `Context`, you can probably 
use `Ctx`.  But... LLVM variable naming is sad... :(


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40485



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


[PATCH] D30691: [analyzer] Support for naive cross translational unit analysis

2017-12-06 Thread Zoltán Gera via Phabricator via cfe-commits
gerazo added a comment.

The code modifications are coming soon (after doing some extensive testing) for 
the scan-build part.




Comment at: tools/scan-build-py/libscanbuild/analyze.py:223
+ctu_config = get_ctu_config(args)
+if ctu_config.collect:
+shutil.rmtree(ctu_config.dir, ignore_errors=True)

danielmarjamaki wrote:
> danielmarjamaki wrote:
> > not a big deal but I would use early exits in this function
> with "not a big deal" I mean; feel free to ignore my comment if you want to 
> have it this way.
I've checked it through. The only place for an early exit now would be before 
the else. The 1st and 2nd ifs are in fact non-orthogonal.



Comment at: tools/scan-build-py/libscanbuild/analyze.py:145
+mangled_ast_pairs.append((mangled_name, ast_files.pop()))
+
+return mangled_ast_pairs

george.karpenkov wrote:
> Overall, instead of creating a dictionary with multiple elements, and then 
> converting to a list, it's much simper to only add an element to 
> `mangled_to_asts` when it is not already mapped to something (probably 
> logging a message otherwise), and then just return `mangled_to_asts.items()`
The reason for the previous is that we need to count the occurence number 
ofdifferent mappings only let those pass through which don't have multiple 
variations.



Comment at: tools/scan-build-py/libscanbuild/analyze.py:189
+# Remove all temporary files
+shutil.rmtree(fnmap_dir, ignore_errors=True)
+

gerazo wrote:
> george.karpenkov wrote:
> > Having an analysis tool remove files is scary, what if (maybe not in this 
> > revision, but in a future iteration) a bug is introduced, and the tool 
> > removes user code instead?
> > Why not just create a temporary directory with `tempfile.mkdtemp`, put all 
> > temporary files there, and then simply iterate through them?
> > Then you would be able to get rid of the constant `CPU_TEMP_FNMAP_FOLDER` 
> > entirely, and OS would be responsible for cleanup.
> Yes, you are right. We are essentially using a temp dir. Because of the size 
> we first had to put it next to the project (not on tmp drive for instance) 
> and for debugging purposes we gave a name to it. Still it can be done with 
> mkdtemp as well.
Finally, I came to the conclusion that mkdtemp would not be better than the 
current solution. In order to find our created dir by other threads, we need a 
designated name. Suffixing it by generated name would further complicate things 
as we need not to allow multiple concurrent runs here. The current solution is 
more robust from this point of view.



Comment at: tools/scan-build-py/libscanbuild/analyze.py:241
+run_analyzer_parallel(args)
+shutil.rmtree(ctu_config.dir, ignore_errors=True)
+else:

george.karpenkov wrote:
> Same as the comment above about removing folders. Also it seems like there 
> should be a way to remove redundancy in `if collect / remove tree` block 
> repeated twice.
Th previous call for data removal happens because the user asked for a collect 
run, so we clean data to do a recollection. This second one happens because the 
user asked for a full recollection and anaylsis run all in one. So here we 
destroy the temp data for user's convenience. This happens after, not before 
like previously. The default behavior is to do this when the user uses the tool 
the easy way (collect and analyze all in one) and we intentionally keep 
collection data if the user only asks for a collect or an analyze run. So with 
this, the user can use a collect run's results for multiple analyze runs. This 
is written in the command line help. I will definitely put comments here to 
explain.



Comment at: tools/scan-build-py/libscanbuild/analyze.py:296
+'command': [execution.cmd[0], '-c'] + compilation.flags,
+'ctu': json.loads(os.getenv('ANALYZE_BUILD_CTU'))
 }

george.karpenkov wrote:
> Again, is it possible to avoid JSON-over-environment-variables?
There is an other thing against changing this. Currently the interface here 
using env variables is used by intercept-build, analyze-build and scan-build 
tool as well. In order to drop json, we need to change those tools too. It 
would be a separate patch definitely.



Comment at: tools/scan-build-py/libscanbuild/analyze.py:561
+except OSError:
+pass
+ast_command = [opts['clang'], '-emit-ast']

gerazo wrote:
> george.karpenkov wrote:
> > `try/except/pass` is almost always bad.
> > When can the error occur? Why are we ignoring it?
> I think this code is redundant with the if above.
Here the folders are created on demand. Because these are created parallel by 
multiple processes, there is small chance that an other process already created 
the folder between the isdir check and the makedirs c

[PATCH] D40884: [Index] Add setPreprocessor member to IndexDataConsumer.

2017-12-06 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

In https://reviews.llvm.org/D40884#946506, @malaperle wrote:

> You can get the preprocessor from the ASTContext, no?


I don't think `ASTContext` contains preprocessor information.


Repository:
  rC Clang

https://reviews.llvm.org/D40884



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


[PATCH] D40884: [Index] Add setPreprocessor member to IndexDataConsumer.

2017-12-06 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

In https://reviews.llvm.org/D40884#946630, @ioeric wrote:

> In https://reviews.llvm.org/D40884#946506, @malaperle wrote:
>
> > You can get the preprocessor from the ASTContext, no?
>
>
> I don't think `ASTContext` contains preprocessor information.


My bad, it was the SourceManager I had in mind. Ignore me!


Repository:
  rC Clang

https://reviews.llvm.org/D40884



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


[PATCH] D40888: [ARM] ACLE parallel arithmetic and DSP style multiplications

2017-12-06 Thread Sam Parker via Phabricator via cfe-commits
samparker accepted this revision.
samparker added a comment.
This revision is now accepted and ready to land.

Great, LGTM, many thanks for doing this!


https://reviews.llvm.org/D40888



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


[PATCH] D40901: Refactor lazy loading of template specializations. NFC

2017-12-06 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.

Unify the loading of lazy template specializations across class, function

  and variable templates.


Repository:
  rL LLVM

https://reviews.llvm.org/D40901

Files:
  include/clang/AST/DeclTemplate.h
  lib/AST/DeclTemplate.cpp

Index: lib/AST/DeclTemplate.cpp
===
--- lib/AST/DeclTemplate.cpp
+++ lib/AST/DeclTemplate.cpp
@@ -182,15 +182,30 @@
   return Common;
 }
 
+void RedeclarableTemplateDecl::loadLazySpecializationsImpl() const {
+  // Grab the most recent declaration to ensure we've loaded any lazy
+  // redeclarations of this template.
+  //
+  // FIXME: Avoid walking the entire redeclaration chain here.
+  CommonBase *CommonBasePtr = getMostRecentDecl()->getCommonPtr();
+  if (CommonBasePtr->LazySpecializations) {
+ASTContext &Context = getASTContext();
+uint32_t *Specs = CommonBasePtr->LazySpecializations;
+CommonBasePtr->LazySpecializations = nullptr;
+for (uint32_t I = 0, N = *Specs++; I != N; ++I)
+  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
+  }
+}
+
 template
 typename RedeclarableTemplateDecl::SpecEntryTraits::DeclType *
 RedeclarableTemplateDecl::findSpecializationImpl(
 llvm::FoldingSetVector &Specs, ArrayRef Args,
 void *&InsertPos) {
   using SETraits = SpecEntryTraits;
 
   llvm::FoldingSetNodeID ID;
-  EntryType::Profile(ID,Args, getASTContext());
+  EntryType::Profile(ID, Args, getASTContext());
   EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
   return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
 }
@@ -251,18 +266,7 @@
 }
 
 void FunctionTemplateDecl::LoadLazySpecializations() const {
-  // Grab the most recent declaration to ensure we've loaded any lazy
-  // redeclarations of this template.
-  //
-  // FIXME: Avoid walking the entire redeclaration chain here.
-  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
-  if (CommonPtr->LazySpecializations) {
-ASTContext &Context = getASTContext();
-uint32_t *Specs = CommonPtr->LazySpecializations;
-CommonPtr->LazySpecializations = nullptr;
-for (uint32_t I = 0, N = *Specs++; I != N; ++I)
-  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
-  }
+  loadLazySpecializationsImpl();
 }
 
 llvm::FoldingSetVector &
@@ -330,18 +334,7 @@
 }
 
 void ClassTemplateDecl::LoadLazySpecializations() const {
-  // Grab the most recent declaration to ensure we've loaded any lazy
-  // redeclarations of this template.
-  //
-  // FIXME: Avoid walking the entire redeclaration chain here.
-  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
-  if (CommonPtr->LazySpecializations) {
-ASTContext &Context = getASTContext();
-uint32_t *Specs = CommonPtr->LazySpecializations;
-CommonPtr->LazySpecializations = nullptr;
-for (uint32_t I = 0, N = *Specs++; I != N; ++I)
-  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
-  }
+  loadLazySpecializationsImpl();
 }
 
 llvm::FoldingSetVector &
@@ -941,21 +934,8 @@
  DeclarationName(), nullptr, nullptr);
 }
 
-// TODO: Unify across class, function and variable templates?
-//   May require moving this and Common to RedeclarableTemplateDecl.
 void VarTemplateDecl::LoadLazySpecializations() const {
-  // Grab the most recent declaration to ensure we've loaded any lazy
-  // redeclarations of this template.
-  //
-  // FIXME: Avoid walking the entire redeclaration chain here.
-  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
-  if (CommonPtr->LazySpecializations) {
-ASTContext &Context = getASTContext();
-uint32_t *Specs = CommonPtr->LazySpecializations;
-CommonPtr->LazySpecializations = nullptr;
-for (uint32_t I = 0, N = *Specs++; I != N; ++I)
-  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
-  }
+  loadLazySpecializationsImpl();
 }
 
 llvm::FoldingSetVector &
Index: include/clang/AST/DeclTemplate.h
===
--- include/clang/AST/DeclTemplate.h
+++ include/clang/AST/DeclTemplate.h
@@ -800,6 +800,8 @@
 return SpecIterator(isEnd ? Specs.end() : Specs.begin());
   }
 
+  void loadLazySpecializationsImpl() const;
+
   template  typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector &Specs,
  ArrayRef Args, void *&InsertPos);
@@ -818,6 +820,13 @@
 /// was explicitly specialized.
 llvm::PointerIntPair
   InstantiatedFromMember;
+
+/// \brief If non-null, points to an array of specializations (including
+/// partial specializations) known only by their external declaration IDs.
+///
+/// The first value in the array is the number of of specializations/
+/// partial specializations that follow.
+uint32_t *LazySpecializations = nullptr;
   };
 
   /// \brief Pointer to the common data shared by all declarations of this
@@ -985,13 +994,6 @@
   

[PATCH] D40903: [Sanitizers] Basic Solaris sanitizer support (PR 33274)

2017-12-06 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a project: Sanitizers.
Herald added subscribers: fedor.sergeev, jyknight.

This patch (on top of https://reviews.llvm.org/D35755) provides the clang side 
necessary
to enable the Solaris port of the sanitizers implemented by 
https://reviews.llvm.org/D40898,
https://reviews.llvm.org/D40899, and https://reviews.llvm.org/D40900).

A few features of note:

- While compiler-rt cmake/base-config-ix.cmake (COMPILER_RT_OS_DIR) places the 
runtime libs in a tolower(CMAKE_SYSTEM_NAME) directory, clang defaults to the 
OS part of the target triplet (solaris2.11 in the case at hand).  The patch 
makes them agree on compiler-rt's idea.

- While Solaris ld accepts a considerable number of GNU ld options for 
compatibility, it only does so for the double-dash forms.  clang unfortunately 
is inconsistent here and sometimes uses the double-dash form, sometimes the 
single-dash one that confuses the hell out of Solaris ld.  I've changed the 
affected places to use the double-dash form that should always work.

- As described in https://reviews.llvm.org/D40899, Solaris ld doesn't create 
the __start___sancov_guards/__stop___sancov_guards labels gld/gold/lld do, so 
I'm including additional runtime libs into the link that provide them.

- One test uses -fstack-protector, but unlike other systems libssp hasn't been 
folded into Solaris libc, but needs to be linked with separately.

- For now, only 32-bit x86 asan is enabled on Solaris.  64-bit x86 should 
follow, but sparc (which requires additional compiler-rt changes not yet 
submitted) fails miserably due to a llvmsparc backend limitation:

fatal error: error in backend: Function 
"_ZN7testing8internal16BoolFromGTestEnvEPKcb": over-aligned dynamic alloca not 
supported.

  However, inside the gcc tree, Solaris/sparc asan works almost as well as x86.


Repository:
  rC Clang

https://reviews.llvm.org/D40903

Files:
  include/clang/Driver/ToolChain.h
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains/CommonArgs.cpp
  lib/Driver/ToolChains/Solaris.cpp
  lib/Driver/ToolChains/Solaris.h

Index: lib/Driver/ToolChains/Solaris.h
===
--- lib/Driver/ToolChains/Solaris.h
+++ lib/Driver/ToolChains/Solaris.h
@@ -65,6 +65,7 @@
   addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
 
+  SanitizerMask getSupportedSanitizers() const override;
   unsigned GetDefaultDwarfVersion() const override { return 2; }
 
 protected:
Index: lib/Driver/ToolChains/Solaris.cpp
===
--- lib/Driver/ToolChains/Solaris.cpp
+++ lib/Driver/ToolChains/Solaris.cpp
@@ -92,24 +92,48 @@
 Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
   }
 
+  // Provide __start___sancov_guards.  Solaris ld doesn't automatically create
+  // __start_SECNAME labels.
+  CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back(
+  getToolChain().getCompilerRTArgString(Args, "sancov_begin", false));
+  CmdArgs.push_back("--no-whole-archive");
+
   getToolChain().AddFilePathLibArgs(Args, CmdArgs);
 
   Args.AddAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_e, options::OPT_r});
 
+  bool NeedsSanitizerDeps = addSanitizerRuntimes(getToolChain(), Args, CmdArgs);
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
 if (getToolChain().ShouldLinkCXXStdlib(Args))
   getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
+if (Args.hasArg(options::OPT_fstack_protector) ||
+Args.hasArg(options::OPT_fstack_protector_strong) ||
+Args.hasArg(options::OPT_fstack_protector_all)) {
+  // Explicitly link ssp libraries, not folded into Solaris libc.
+  CmdArgs.push_back("-lssp_nonshared");
+  CmdArgs.push_back("-lssp");
+}
 CmdArgs.push_back("-lgcc_s");
 CmdArgs.push_back("-lc");
 if (!Args.hasArg(options::OPT_shared)) {
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
+if (NeedsSanitizerDeps)
+  linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
   }
 
+  // Provide __stop___sancov_guards.  Solaris ld doesn't automatically create
+  // __stop_SECNAME labels.
+  CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back(
+  getToolChain().getCompilerRTArgString(Args, "sancov_end", false));
+  CmdArgs.push_back("--no-whole-archive");
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
 CmdArgs.push_back(
 Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
@@ -165,6 +189,17 @@
   addPathIfExists(D, D.SysRoot + "/usr/lib" + LibSuffix, Paths);
 }
 
+SanitizerMask Solaris::getSupportedSanitizers() const {
+  const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
+  SanitizerMask Res = ToolChain::getSupported

[PATCH] D40813: [clang-tidy] Adding Fuchsia checker for virtual inheritance

2017-12-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: test/clang-tidy/fuchsia-virtual-inheritance.cpp:30
+class D : public B, public C {
+  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: virtual inheritance is disallowed 
[fuchsia-virtual-inheritance]
+  // CHECK-NEXT: class C : public B, public C {

I don't think that this should be diagnosed -- it will be confusing to the user 
to see this claimed as virtual inheritance when there's no virtual inheritance 
at this level.



Comment at: test/clang-tidy/fuchsia-virtual-inheritance.cpp:34-36
+  // CHECK-MESSAGES: [[@LINE-1]]:28: warning: constructing a class that 
inherits a virtual base class is disallowed [fuchsia-virtual-inheritance]
+  // CHECK-NEXT:  D(int value) : A(value), B(), C() {}
+  // CHECK-MESSAGES: [[@LINE-3]]:33: warning: constructing a class that 
inherits a virtual base class is disallowed [fuchsia-virtual-inheritance]

I'm also not certain this should be diagnosed either. It's technically correct 
because it's calling the base class constructors here, but at the same time, it 
seems very low-value and likely to cause the user to do something really bad, 
like silence the warning by not calling the base class constructors.


https://reviews.llvm.org/D40813



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


[PATCH] D40806: CodeGen: Fix invalid bitcasts for memcpy

2017-12-06 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm accepted this revision.
arsenm added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D40806



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


[PATCH] D40486: [clangd] Implemented logging using Context

2017-12-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Mostly nits - throughout there's going to be lots of judgement calls about 
where to propagate context and where not.
No need to get all those "exactly right", but trying to get a feel for what 
these answers are likely to be.

Most of the interesting stuff is around the logger itself of course :-)




Comment at: clangd/ClangdServer.cpp:31
 
-class FulfillPromiseGuard {
+class FulfillContextPromiseGuard {
 public:

Up to you, but I like the old name better - this class is local so it's OK to 
be a bit opinionated.



Comment at: clangd/ClangdServer.cpp:36
 
-  ~FulfillPromiseGuard() { Promise.set_value(); }
+  ~FulfillContextPromiseGuard() { Promise.set_value(std::move(Ctx)); }
 

Yikes, I can see how we got here, but we really don't get to move out of 
something we received an lvalue-reference to...

I think a safer idiom here is turning a whole lambda into a destructor:

   auto Fulfil = MakeDestructor([&]{
  DonePromise.set_value(std::move(Ctx));
   });

I'm not sure if LLVM has a shared utility for this, I've seen it in other 
codebases. Either way we could just define it here.

(Or we could copy the context to avoid the awkwardness)



Comment at: clangd/ClangdServer.cpp:220
 
-  // Note that std::future from this cleanup action is ignored.
-  scheduleCancelRebuild(std::move(Recreated.RemovedFile));
+  // Note that std::future from this cleanup action.
+  // FIXME(ibiryukov): We use a global context here, should not fork the action

You dropped the end of this comment



Comment at: clangd/ClangdServer.cpp:221
+  // Note that std::future from this cleanup action.
+  // FIXME(ibiryukov): We use a global context here, should not fork the action
+  // instead.

I don't quite understand what this is saying should be better. Is it saying we 
do these two things together instead of running them in parallel?

And why not clone the context instead?



Comment at: clangd/ClangdUnit.cpp:436
+  RebuildInProgress(false), PCHs(std::move(PCHs)) {
+  log(emptyCtx(), "Opened file " + FileName + " with command [" +
+  this->Command.Directory + "] " +

why are we dropping the context here?
It's important that in general we don't store the ctx in the object and blindly 
reuse it, but passing it into the constructor for use *in* the constructor 
seems fine.

Reading on... OK, it saves a *lot* of plumbing to avoid attributing this one 
API call. I still don't totally understand how the CppFile API/lifetime works, 
so up to you.



Comment at: clangd/ClangdUnit.cpp:533
+That](std::string NewContents,
+  Context &Ctx) mutable // 'mutable' to
+// allow changing

nit: this wrapping has become *really* weird over time - can we change the 
comment to `/* allow changing OldPreamble */` to try to fix it?



Comment at: clangd/ClangdUnit.h:257
 
+/// Get signature help at a specified \p Pos in \p FileName.
+SignatureHelp

I think this is a bad merge - signatureHelp has moved to CodeComplete.h



Comment at: clangd/GlobalCompilationDatabase.h:37
   virtual llvm::Optional
   getCompileCommand(PathRef File) const = 0;
 

Do we want Ctx in this interface?
It's an extension point, and the ability for embedders to track calls flowing 
between their API calls and their extension points is one of the reasons we 
have ctx...



Comment at: clangd/JSONRPCDispatcher.cpp:22
 
+namespace {
+static Key> TracerKey;

Maybe we don't need the Key suffix, as it's in the type... we should spend our 
verbosity elsewhere



Comment at: clangd/JSONRPCDispatcher.cpp:23
+namespace {
+static Key> TracerKey;
+static Key IDKey;

RequestTracer?



Comment at: clangd/JSONRPCDispatcher.cpp:24
+static Key> TracerKey;
+static Key IDKey;
+static Key OutKey;

RequestID



Comment at: clangd/JSONRPCDispatcher.cpp:48
+void JSONOutput::logImpl(Context &Ctx, const Twine &Message) {
+  // FIXME(ibiryukov): get rid of trace::log here.
   trace::log(Message);

why?



Comment at: clangd/JSONRPCDispatcher.h:29
 /// them.
 class JSONOutput : public Logger {
 public:

does this class need to be public? Is it staying around for the long haul?



Comment at: clangd/JSONRPCDispatcher.h:39
   /// Write a line to the logging stream.
-  void log(const Twine &Message) override;
+  void logImpl(Context &Ctx, const Twine &Message) override;
 

Is this temporary?



Comment at: clangd/Logger.cpp:16
+namespace {
+class EmptyLogger : public Logger {
+public:
---

[PATCH] D40897: [clangd] Introduce a "Symbol" class.

2017-12-06 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

Hi! Have you looked into https://reviews.llvm.org/D40548 ? Maybe we need to 
coordinate the two a bit.




Comment at: clangd/Symbol.h:37
+// The class presents a C++ symbol, e.g. class, function.
+struct Symbol {
+  // The symbol identifier, using USR.

I think it would be nice to have methods as an interface to get this data 
instead of storing them directly. So that an index-on-disk could go fetch the 
data. Especially the occurrences which can take a lot of memory (I'm working on 
a branch that does that). But perhaps defining that interface is not within the 
scope of this patch and could be better discussed in D40548 ?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40897



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


[PATCH] D40901: Refactor lazy loading of template specializations. NFC

2017-12-06 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 125738.
v.g.vassilev added a comment.

Fix preexisting comment typo.


https://reviews.llvm.org/D40901

Files:
  include/clang/AST/DeclTemplate.h
  lib/AST/DeclTemplate.cpp

Index: lib/AST/DeclTemplate.cpp
===
--- lib/AST/DeclTemplate.cpp
+++ lib/AST/DeclTemplate.cpp
@@ -182,15 +182,30 @@
   return Common;
 }
 
+void RedeclarableTemplateDecl::loadLazySpecializationsImpl() const {
+  // Grab the most recent declaration to ensure we've loaded any lazy
+  // redeclarations of this template.
+  //
+  // FIXME: Avoid walking the entire redeclaration chain here.
+  CommonBase *CommonBasePtr = getMostRecentDecl()->getCommonPtr();
+  if (CommonBasePtr->LazySpecializations) {
+ASTContext &Context = getASTContext();
+uint32_t *Specs = CommonBasePtr->LazySpecializations;
+CommonBasePtr->LazySpecializations = nullptr;
+for (uint32_t I = 0, N = *Specs++; I != N; ++I)
+  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
+  }
+}
+
 template
 typename RedeclarableTemplateDecl::SpecEntryTraits::DeclType *
 RedeclarableTemplateDecl::findSpecializationImpl(
 llvm::FoldingSetVector &Specs, ArrayRef Args,
 void *&InsertPos) {
   using SETraits = SpecEntryTraits;
 
   llvm::FoldingSetNodeID ID;
-  EntryType::Profile(ID,Args, getASTContext());
+  EntryType::Profile(ID, Args, getASTContext());
   EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
   return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
 }
@@ -251,18 +266,7 @@
 }
 
 void FunctionTemplateDecl::LoadLazySpecializations() const {
-  // Grab the most recent declaration to ensure we've loaded any lazy
-  // redeclarations of this template.
-  //
-  // FIXME: Avoid walking the entire redeclaration chain here.
-  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
-  if (CommonPtr->LazySpecializations) {
-ASTContext &Context = getASTContext();
-uint32_t *Specs = CommonPtr->LazySpecializations;
-CommonPtr->LazySpecializations = nullptr;
-for (uint32_t I = 0, N = *Specs++; I != N; ++I)
-  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
-  }
+  loadLazySpecializationsImpl();
 }
 
 llvm::FoldingSetVector &
@@ -330,18 +334,7 @@
 }
 
 void ClassTemplateDecl::LoadLazySpecializations() const {
-  // Grab the most recent declaration to ensure we've loaded any lazy
-  // redeclarations of this template.
-  //
-  // FIXME: Avoid walking the entire redeclaration chain here.
-  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
-  if (CommonPtr->LazySpecializations) {
-ASTContext &Context = getASTContext();
-uint32_t *Specs = CommonPtr->LazySpecializations;
-CommonPtr->LazySpecializations = nullptr;
-for (uint32_t I = 0, N = *Specs++; I != N; ++I)
-  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
-  }
+  loadLazySpecializationsImpl();
 }
 
 llvm::FoldingSetVector &
@@ -941,21 +934,8 @@
  DeclarationName(), nullptr, nullptr);
 }
 
-// TODO: Unify across class, function and variable templates?
-//   May require moving this and Common to RedeclarableTemplateDecl.
 void VarTemplateDecl::LoadLazySpecializations() const {
-  // Grab the most recent declaration to ensure we've loaded any lazy
-  // redeclarations of this template.
-  //
-  // FIXME: Avoid walking the entire redeclaration chain here.
-  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
-  if (CommonPtr->LazySpecializations) {
-ASTContext &Context = getASTContext();
-uint32_t *Specs = CommonPtr->LazySpecializations;
-CommonPtr->LazySpecializations = nullptr;
-for (uint32_t I = 0, N = *Specs++; I != N; ++I)
-  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
-  }
+  loadLazySpecializationsImpl();
 }
 
 llvm::FoldingSetVector &
Index: include/clang/AST/DeclTemplate.h
===
--- include/clang/AST/DeclTemplate.h
+++ include/clang/AST/DeclTemplate.h
@@ -800,6 +800,8 @@
 return SpecIterator(isEnd ? Specs.end() : Specs.begin());
   }
 
+  void loadLazySpecializationsImpl() const;
+
   template  typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector &Specs,
  ArrayRef Args, void *&InsertPos);
@@ -818,6 +820,13 @@
 /// was explicitly specialized.
 llvm::PointerIntPair
   InstantiatedFromMember;
+
+/// \brief If non-null, points to an array of specializations (including
+/// partial specializations) known only by their external declaration IDs.
+///
+/// The first value in the array is the number of specializations/partial
+/// specializations that follow.
+uint32_t *LazySpecializations = nullptr;
   };
 
   /// \brief Pointer to the common data shared by all declarations of this
@@ -985,13 +994,6 @@
 /// require the use of this information.
 Templ

[PATCH] D40895: Ignore pointers to incomplete types when diagnosing misaligned addresses

2017-12-06 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!


https://reviews.llvm.org/D40895



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


[PATCH] D39812: [Driver, CodeGen] pass through and apply -fassociative-math

2017-12-06 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

Ping * 3.


https://reviews.llvm.org/D39812



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


r319904 - Stringizing raw string literals containing newline

2017-12-06 Thread Taewook Oh via cfe-commits
Author: twoh
Date: Wed Dec  6 09:00:53 2017
New Revision: 319904

URL: http://llvm.org/viewvc/llvm-project?rev=319904&view=rev
Log:
Stringizing raw string literals containing newline

Summary: This patch implements 4.3 of 
http://open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4220.pdf. If a raw string 
contains a newline character, replace each newline character with the \n escape 
code. Without this patch, included test case (macro_raw_string.cpp) results 
compilation failure.

Reviewers: rsmith, doug.gregor, jkorous-apple

Reviewed By: jkorous-apple

Subscribers: jkorous-apple, vsapsai, cfe-commits

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

Added:
cfe/trunk/test/Preprocessor/macro_raw_string.cpp
Modified:
cfe/trunk/include/clang/Lex/Lexer.h
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/unittests/Lex/LexerTest.cpp

Modified: cfe/trunk/include/clang/Lex/Lexer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=319904&r1=319903&r2=319904&view=diff
==
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Wed Dec  6 09:00:53 2017
@@ -70,7 +70,7 @@ class Lexer : public PreprocessorLexer {
   SourceLocation FileLoc;// Location for start of file.
   LangOptions LangOpts;  // LangOpts enabled by this language (cache).
   bool Is_PragmaLexer;   // True if lexer for _Pragma handling.
-  
+
   
//======//
   // Context-specific lexing flags set by the preprocessor.
   //
@@ -241,17 +241,16 @@ public:
 
   /// \brief Return the current location in the buffer.
   const char *getBufferLocation() const { return BufferPtr; }
-  
-  /// Stringify - Convert the specified string into a C string by escaping '\'
-  /// and " characters.  This does not add surrounding ""'s to the string.
+
+  /// Stringify - Convert the specified string into a C string by i) escaping
+  /// '\\' and " characters and ii) replacing newline character(s) with "\\n".
   /// If Charify is true, this escapes the ' character instead of ".
   static std::string Stringify(StringRef Str, bool Charify = false);
 
-  /// Stringify - Convert the specified string into a C string by escaping '\'
-  /// and " characters.  This does not add surrounding ""'s to the string.
+  /// Stringify - Convert the specified string into a C string by i) escaping
+  /// '\\' and " characters and ii) replacing newline character(s) with "\\n".
   static void Stringify(SmallVectorImpl &Str);
 
-  
   /// getSpelling - This method is used to get the spelling of a token into a
   /// preallocated buffer, instead of as an std::string.  The caller is 
required
   /// to allocate enough space for the token, which is guaranteed to be at 
least
@@ -262,11 +261,11 @@ public:
   /// to point to a constant buffer with the data already in it (avoiding a
   /// copy).  The caller is not allowed to modify the returned buffer pointer
   /// if an internal buffer is returned.
-  static unsigned getSpelling(const Token &Tok, const char *&Buffer, 
+  static unsigned getSpelling(const Token &Tok, const char *&Buffer,
   const SourceManager &SourceMgr,
   const LangOptions &LangOpts,
   bool *Invalid = nullptr);
-  
+
   /// getSpelling() - Return the 'spelling' of the Tok token.  The spelling of 
a
   /// token is the characters used to represent the token in the source file
   /// after trigraph expansion and escaped-newline folding.  In particular, 
this
@@ -274,7 +273,7 @@ public:
   /// UCNs, etc.
   static std::string getSpelling(const Token &Tok,
  const SourceManager &SourceMgr,
- const LangOptions &LangOpts, 
+ const LangOptions &LangOpts,
  bool *Invalid = nullptr);
 
   /// getSpelling - This method is used to get the spelling of the
@@ -290,7 +289,7 @@ public:
const SourceManager &SourceMgr,
const LangOptions &LangOpts,
bool *invalid = nullptr);
-  
+
   /// MeasureTokenLength - Relex the token at the specified location and return
   /// its length in bytes in the input file.  If the token needs cleaning (e.g.
   /// includes a trigraph or an escaped newline) then this count includes bytes
@@ -312,7 +311,7 @@ public:
   static SourceLocation GetBeginningOfToken(SourceLocation Loc,
 const SourceManager &SM,
 const LangOptions &LangOpts);
-  
+
   /// AdvanceToTokenCharacter - If the current SourceLocation specifies a
   /// location at the start of a token, return a new location that specifies a
   /// character within the token.  This handles 

[PATCH] D39279: Stringizing raw string literals containing newline

2017-12-06 Thread Taewook Oh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC319904: Stringizing raw string literals containing newline 
(authored by twoh).

Changed prior to commit:
  https://reviews.llvm.org/D39279?vs=125564&id=125745#toc

Repository:
  rC Clang

https://reviews.llvm.org/D39279

Files:
  include/clang/Lex/Lexer.h
  lib/Lex/Lexer.cpp
  test/Preprocessor/macro_raw_string.cpp
  unittests/Lex/LexerTest.cpp

Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -209,30 +209,39 @@
   return L;
 }
 
-/// Stringify - Convert the specified string into a C string, with surrounding
-/// ""'s, and with escaped \ and " characters.
+template  void StringifyImpl(T &Str, char Quote) {
+  typename T::size_type i = 0, e = Str.size();
+  while (i < e) {
+if (Str[i] == '\\' || Str[i] == Quote) {
+  Str.insert(Str.begin() + i, '\\');
+  i += 2;
+  ++e;
+} else if (Str[i] == '\n' || Str[i] == '\r') {
+  // Replace '\r\n' and '\n\r' to '\\' followed by 'n'.
+  if ((i < e - 1) && (Str[i + 1] == '\n' || Str[i + 1] == '\r') &&
+  Str[i] != Str[i + 1]) {
+Str[i] = '\\';
+Str[i + 1] = 'n';
+  } else {
+// Replace '\n' and '\r' to '\\' followed by 'n'.
+Str[i] = '\\';
+Str.insert(Str.begin() + i + 1, 'n');
+++e;
+  }
+  i += 2;
+} else
+  ++i;
+  }
+}
+
 std::string Lexer::Stringify(StringRef Str, bool Charify) {
   std::string Result = Str;
   char Quote = Charify ? '\'' : '"';
-  for (unsigned i = 0, e = Result.size(); i != e; ++i) {
-if (Result[i] == '\\' || Result[i] == Quote) {
-  Result.insert(Result.begin()+i, '\\');
-  ++i; ++e;
-}
-  }
+  StringifyImpl(Result, Quote);
   return Result;
 }
 
-/// Stringify - Convert the specified string into a C string by escaping '\'
-/// and " characters.  This does not add surrounding ""'s to the string.
-void Lexer::Stringify(SmallVectorImpl &Str) {
-  for (unsigned i = 0, e = Str.size(); i != e; ++i) {
-if (Str[i] == '\\' || Str[i] == '"') {
-  Str.insert(Str.begin()+i, '\\');
-  ++i; ++e;
-}
-  }
-}
+void Lexer::Stringify(SmallVectorImpl &Str) { StringifyImpl(Str, '"'); }
 
 //===--===//
 // Token Spelling
@@ -367,7 +376,7 @@
 /// to point to a constant buffer with the data already in it (avoiding a
 /// copy).  The caller is not allowed to modify the returned buffer pointer
 /// if an internal buffer is returned.
-unsigned Lexer::getSpelling(const Token &Tok, const char *&Buffer, 
+unsigned Lexer::getSpelling(const Token &Tok, const char *&Buffer,
 const SourceManager &SourceMgr,
 const LangOptions &LangOpts, bool *Invalid) {
   assert((int)Tok.getLength() >= 0 && "Token character range is bogus!");
@@ -592,17 +601,17 @@
   if (TheTok.getKind() == tok::eof) {
 break;
   }
-  
+
   // If we haven't hit the end of the preprocessor directive, skip this
   // token.
   if (!TheTok.isAtStartOfLine())
 continue;
-
+
   // We've passed the end of the preprocessor directive, and will look
   // at this token again below.
   InPreprocessorDirective = false;
 }
-
+
 // Keep track of the # of lines in the preamble.
 if (TheTok.isAtStartOfLine()) {
   unsigned TokOffset = TheTok.getLocation().getRawEncoding() - StartOffset;
@@ -619,13 +628,13 @@
 ActiveCommentLoc = TheTok.getLocation();
   continue;
 }
-
+
 if (TheTok.isAtStartOfLine() && TheTok.getKind() == tok::hash) {
-  // This is the start of a preprocessor directive. 
+  // This is the start of a preprocessor directive.
   Token HashTok = TheTok;
   InPreprocessorDirective = true;
   ActiveCommentLoc = SourceLocation();
-  
+
   // Figure out which directive this is. Since we're lexing raw tokens,
   // we don't have an identifier table available. Instead, just look at
   // the raw identifier to recognize and categorize preprocessor directives.
@@ -665,7 +674,7 @@
   break;
 }
   }
-  
+
   // We only end up here if we didn't recognize the preprocessor
   // directive or it was one that can't occur in the preamble at this
   // point. Roll back the current token to the location of the '#'.
@@ -678,7 +687,7 @@
 // the preamble.
 break;
   } while (true);
-  
+
   SourceLocation End;
   if (ActiveCommentLoc.isValid())
 End = ActiveCommentLoc; // don't truncate a decl comment.
@@ -700,13 +709,13 @@
   // trigraphs.
   bool Invalid = false;
   const char *TokPtr = SM.getCharacterData(TokStart, &Invalid);
-  
+
   // If they request the first char of the token, we're trivially done.
   if (Invalid || (CharNo == 0 && Lexer::isObviouslySimpleCharacter(*TokPtr)))
 return TokStart;
-  
+

[PATCH] D40909: [clang-format] Reorganize raw string delimiters

2017-12-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, klimek.

Repository:
  rC Clang

https://reviews.llvm.org/D40909

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/Format.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestRawStrings.cpp

Index: unittests/Format/FormatTestRawStrings.cpp
===
--- unittests/Format/FormatTestRawStrings.cpp
+++ unittests/Format/FormatTestRawStrings.cpp
@@ -9,6 +9,8 @@
 
 #include "clang/Format/Format.h"
 
+#include 
+
 #include "../Tooling/ReplacementTest.h"
 #include "FormatTestUtils.h"
 
@@ -19,6 +21,12 @@
 
 #define DEBUG_TYPE "format-test"
 
+#define DBG(A) \
+  DEBUG({  \
+llvm::dbgs() << __LINE__ << ":" << __func__ << ":" << #A << " = " << A \
+ << "\n";  \
+  });
+
 using clang::tooling::ReplacementTest;
 using clang::tooling::toReplacements;
 
@@ -65,23 +73,40 @@
   FormatStyle getRawStringPbStyleWithColumns(unsigned ColumnLimit) {
 FormatStyle Style = getLLVMStyle();
 Style.ColumnLimit = ColumnLimit;
-Style.RawStringFormats = {{/*Delimiter=*/"pb",
-   /*Kind=*/FormatStyle::LK_TextProto,
-   /*BasedOnStyle=*/"google"}};
+Style.AdditionalLanguageStyles[FormatStyle::LK_TextProto] =
+std::make_shared(
+getGoogleStyle(FormatStyle::LK_TextProto));
+Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_TextProto,
+   /*Delimiters=*/{"pb"},
+   /*EnclosingFunctionNames=*/{},
+   /*CanonicalDelimiter=*/""}};
 return Style;
   }
 
-  FormatStyle getRawStringLLVMCppStyleBasedOn(std::string BasedOnStyle) {
+  FormatStyle getRawStringLLVMCppStyleBasedOn(std::string Name) {
 FormatStyle Style = getLLVMStyle();
-Style.RawStringFormats = {{/*Delimiter=*/"cpp",
-   /*Kind=*/FormatStyle::LK_Cpp, BasedOnStyle}};
+FormatStyle BasedOnStyle = getLLVMStyle();
+getPredefinedStyle(Name, FormatStyle::LK_Cpp, &BasedOnStyle);
+Style.AdditionalLanguageStyles[FormatStyle::LK_Cpp] =
+std::make_shared(BasedOnStyle);
+Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_Cpp,
+   /*Delimiters=*/{"cpp"},
+   /*EnclosingFunctionNames=*/{},
+   /*CanonicalDelimiter=*/""}};
+DBG(BasedOnStyle.PointerAlignment);
 return Style;
   }
 
-  FormatStyle getRawStringGoogleCppStyleBasedOn(std::string BasedOnStyle) {
+  FormatStyle getRawStringGoogleCppStyleBasedOn(std::string Name) {
 FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp);
-Style.RawStringFormats = {{/*Delimiter=*/"cpp",
-   /*Kind=*/FormatStyle::LK_Cpp, BasedOnStyle}};
+FormatStyle BasedOnStyle = getLLVMStyle();
+getPredefinedStyle(Name, FormatStyle::LK_Cpp, &BasedOnStyle);
+Style.AdditionalLanguageStyles[FormatStyle::LK_Cpp] =
+std::make_shared(BasedOnStyle);
+Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_Cpp,
+   /*Delimiters=*/{"cpp"},
+   /*EnclosingFunctionNames=*/{},
+   /*CanonicalDelimiter=*/""}};
 return Style;
   }
 
@@ -96,17 +121,19 @@
   // llvm style puts '*' on the right.
   // google style puts '*' on the left.
 
-  // Use the llvm style if the raw string style has no BasedOnStyle.
-  expect_eq(R"test(int *i = R"cpp(int *p = nullptr;)cpp")test",
-format(R"test(int * i = R"cpp(int * p = nullptr;)cpp")test",
-   getRawStringLLVMCppStyleBasedOn("")));
-
-  // Use the google style if the raw string style has BasedOnStyle=google.
+  // Use llvm style outside and the google style inside if the raw string style
+  // is based on google.
   expect_eq(R"test(int *i = R"cpp(int* p = nullptr;)cpp")test",
 format(R"test(int * i = R"cpp(int * p = nullptr;)cpp")test",
getRawStringLLVMCppStyleBasedOn("google")));
 
-  // Use the llvm style if the raw string style has no BasedOnStyle=llvm.
+  // Use llvm style if the raw string style has no BasedOnStyle.
+  expect_eq(R"test(int *i = R"cpp(int *p = nullptr;)cpp")test",
+format(R"test(int * i = R"cpp(int * p = nullptr;)cpp")test",
+   getRawStringLLVMCppStyleBasedOn("")));
+
+  // Use google style outside and the llvm style inside if the raw string style
+  // is based on llvm.
   expect_eq(R"test(int* i = R"cpp(int *p = nullptr;)cpp")test",
 format(R"test(int * i = R"cpp(int * p = nullptr;)cpp")test",
getRawStri

r319908 - [CUDA] Added overloads for '[unsigned] long' variants of shfl builtins.

2017-12-06 Thread Artem Belevich via cfe-commits
Author: tra
Date: Wed Dec  6 09:40:35 2017
New Revision: 319908

URL: http://llvm.org/viewvc/llvm-project?rev=319908&view=rev
Log:
[CUDA] Added overloads for '[unsigned] long' variants of shfl builtins.

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

Modified:
cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h

Modified: cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h?rev=319908&r1=319907&r2=319908&view=diff
==
--- cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h (original)
+++ cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h Wed Dec  6 09:40:35 2017
@@ -135,6 +135,24 @@ __MAKE_SHUFFLES(__shfl_xor, __nvvm_shfl_
 return static_cast(::__FnName( 
\
 __mask, static_cast(__val), __offset, __width));   
\
   }
\
+  inline __device__ long __FnName(unsigned int __mask, long __val, 
\
+  int __offset, int __width = warpSize) {  
\
+_Static_assert(sizeof(long) == sizeof(long long) ||
\
+   sizeof(long) == sizeof(int));   
\
+if (sizeof(long) == sizeof(long long)) {   
\
+  return static_cast(::__FnName( 
\
+  __mask, static_cast(__val), __offset, __width));  
\
+} else if (sizeof(long) == sizeof(int)) {  
\
+  return static_cast(
\
+  ::__FnName(__mask, static_cast(__val), __offset, __width)); 
\
+}  
\
+  }
\
+  inline __device__ unsigned long __FnName(unsigned int __mask,
\
+   unsigned long __val, int __offset,  
\
+   int __width = warpSize) {   
\
+return static_cast( 
\
+::__FnName(__mask, static_cast(__val), __offset, __width));  
\
+  }
\
   inline __device__ double __FnName(unsigned int __mask, double __val, 
\
 int __offset, int __width = warpSize) {
\
 long long __tmp;   
\


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


[PATCH] D40871: [CUDA] Added overloads for '[unsigned] long' variants of shfl builtins.

2017-12-06 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC319908: [CUDA] Added overloads for '[unsigned] long' 
variants of shfl builtins. (authored by tra).

Changed prior to commit:
  https://reviews.llvm.org/D40871?vs=125648&id=125756#toc

Repository:
  rC Clang

https://reviews.llvm.org/D40871

Files:
  lib/Headers/__clang_cuda_intrinsics.h


Index: lib/Headers/__clang_cuda_intrinsics.h
===
--- lib/Headers/__clang_cuda_intrinsics.h
+++ lib/Headers/__clang_cuda_intrinsics.h
@@ -135,6 +135,24 @@
 return static_cast(::__FnName( 
\
 __mask, static_cast(__val), __offset, __width));   
\
   }
\
+  inline __device__ long __FnName(unsigned int __mask, long __val, 
\
+  int __offset, int __width = warpSize) {  
\
+_Static_assert(sizeof(long) == sizeof(long long) ||
\
+   sizeof(long) == sizeof(int));   
\
+if (sizeof(long) == sizeof(long long)) {   
\
+  return static_cast(::__FnName( 
\
+  __mask, static_cast(__val), __offset, __width));  
\
+} else if (sizeof(long) == sizeof(int)) {  
\
+  return static_cast(
\
+  ::__FnName(__mask, static_cast(__val), __offset, __width)); 
\
+}  
\
+  }
\
+  inline __device__ unsigned long __FnName(unsigned int __mask,
\
+   unsigned long __val, int __offset,  
\
+   int __width = warpSize) {   
\
+return static_cast( 
\
+::__FnName(__mask, static_cast(__val), __offset, __width));  
\
+  }
\
   inline __device__ double __FnName(unsigned int __mask, double __val, 
\
 int __offset, int __width = warpSize) {
\
 long long __tmp;   
\


Index: lib/Headers/__clang_cuda_intrinsics.h
===
--- lib/Headers/__clang_cuda_intrinsics.h
+++ lib/Headers/__clang_cuda_intrinsics.h
@@ -135,6 +135,24 @@
 return static_cast(::__FnName( \
 __mask, static_cast(__val), __offset, __width));   \
   }\
+  inline __device__ long __FnName(unsigned int __mask, long __val, \
+  int __offset, int __width = warpSize) {  \
+_Static_assert(sizeof(long) == sizeof(long long) ||\
+   sizeof(long) == sizeof(int));   \
+if (sizeof(long) == sizeof(long long)) {   \
+  return static_cast(::__FnName( \
+  __mask, static_cast(__val), __offset, __width));  \
+} else if (sizeof(long) == sizeof(int)) {  \
+  return static_cast(\
+  ::__FnName(__mask, static_cast(__val), __offset, __width)); \
+}  \
+  }\
+  inline __device__ unsigned long __FnName(unsigned int __mask,\
+   unsigned long __val, int __offset,  \
+   int __width = warpSize) {   \
+return static_cast( \
+::__FnName(__mask, static_cast(__val), __offset, __width));  \
+  }\
   inline __device__ double __FnName(unsigned int __mask, double __val, \
 int __offset, int __width = warpSize) {\
 long long __tmp;   \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40871: [CUDA] Added overloads for '[unsigned] long' variants of shfl builtins.

2017-12-06 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319908: [CUDA] Added overloads for '[unsigned] long' 
variants of shfl builtins. (authored by tra).

Changed prior to commit:
  https://reviews.llvm.org/D40871?vs=125648&id=125755#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40871

Files:
  cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h


Index: cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
===
--- cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
+++ cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
@@ -135,6 +135,24 @@
 return static_cast(::__FnName( 
\
 __mask, static_cast(__val), __offset, __width));   
\
   }
\
+  inline __device__ long __FnName(unsigned int __mask, long __val, 
\
+  int __offset, int __width = warpSize) {  
\
+_Static_assert(sizeof(long) == sizeof(long long) ||
\
+   sizeof(long) == sizeof(int));   
\
+if (sizeof(long) == sizeof(long long)) {   
\
+  return static_cast(::__FnName( 
\
+  __mask, static_cast(__val), __offset, __width));  
\
+} else if (sizeof(long) == sizeof(int)) {  
\
+  return static_cast(
\
+  ::__FnName(__mask, static_cast(__val), __offset, __width)); 
\
+}  
\
+  }
\
+  inline __device__ unsigned long __FnName(unsigned int __mask,
\
+   unsigned long __val, int __offset,  
\
+   int __width = warpSize) {   
\
+return static_cast( 
\
+::__FnName(__mask, static_cast(__val), __offset, __width));  
\
+  }
\
   inline __device__ double __FnName(unsigned int __mask, double __val, 
\
 int __offset, int __width = warpSize) {
\
 long long __tmp;   
\


Index: cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
===
--- cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
+++ cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
@@ -135,6 +135,24 @@
 return static_cast(::__FnName( \
 __mask, static_cast(__val), __offset, __width));   \
   }\
+  inline __device__ long __FnName(unsigned int __mask, long __val, \
+  int __offset, int __width = warpSize) {  \
+_Static_assert(sizeof(long) == sizeof(long long) ||\
+   sizeof(long) == sizeof(int));   \
+if (sizeof(long) == sizeof(long long)) {   \
+  return static_cast(::__FnName( \
+  __mask, static_cast(__val), __offset, __width));  \
+} else if (sizeof(long) == sizeof(int)) {  \
+  return static_cast(\
+  ::__FnName(__mask, static_cast(__val), __offset, __width)); \
+}  \
+  }\
+  inline __device__ unsigned long __FnName(unsigned int __mask,\
+   unsigned long __val, int __offset,  \
+   int __width = warpSize) {   \
+return static_cast( \
+::__FnName(__mask, static_cast(__val), __offset, __width));  \
+  }\
   inline __device__ double __FnName(unsigned int __mask, double __val, \
 int __offset, int __width = warpSize) {\
 long long __tmp;   \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r319909 - [NVPTX, CUDA] Added llvm.nvvm.fns intrinsic and matching __nvvm_fns builtin in clang.

2017-12-06 Thread Artem Belevich via cfe-commits
Author: tra
Date: Wed Dec  6 09:50:05 2017
New Revision: 319909

URL: http://llvm.org/viewvc/llvm-project?rev=319909&view=rev
Log:
[NVPTX,CUDA] Added llvm.nvvm.fns intrinsic and matching __nvvm_fns builtin in 
clang.


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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def
cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h

Modified: cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def?rev=319909&r1=319908&r2=319909&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def Wed Dec  6 09:50:05 2017
@@ -371,6 +371,9 @@ BUILTIN(__nvvm_bitcast_i2f, "fi", "")
 BUILTIN(__nvvm_bitcast_ll2d, "dLLi", "")
 BUILTIN(__nvvm_bitcast_d2ll, "LLid", "")
 
+// FNS
+TARGET_BUILTIN(__nvvm_fns, "UiUiUii", "n", "ptx60")
+
 // Sync
 
 BUILTIN(__syncthreads, "v", "")

Modified: cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h?rev=319909&r1=319908&r2=319909&view=diff
==
--- cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h (original)
+++ cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h Wed Dec  6 09:50:05 2017
@@ -206,6 +206,10 @@ inline __device__ unsigned int __ballot_
 
 inline __device__ unsigned int __activemask() { return __nvvm_vote_ballot(1); }
 
+inline __device__ unsigned int __fns(unsigned mask, unsigned base, int offset) 
{
+  return __nvvm_fns(mask, base, offset);
+}
+
 #endif // !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 300
 
 // Define __match* builtins CUDA-9 headers expect to see.


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


[PATCH] D40872: [NVPTX, CUDA] Added llvm.nvvm.fns intrinsic and matching __nvvm_fns builtin in clang.

2017-12-06 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319909: [NVPTX,CUDA] Added llvm.nvvm.fns intrinsic and 
matching __nvvm_fns builtin in… (authored by tra).

Changed prior to commit:
  https://reviews.llvm.org/D40872?vs=125649&id=125757#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40872

Files:
  cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def
  cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
  llvm/trunk/include/llvm/IR/IntrinsicsNVVM.td
  llvm/trunk/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/trunk/test/CodeGen/NVPTX/fns.ll

Index: llvm/trunk/include/llvm/IR/IntrinsicsNVVM.td
===
--- llvm/trunk/include/llvm/IR/IntrinsicsNVVM.td
+++ llvm/trunk/include/llvm/IR/IntrinsicsNVVM.td
@@ -682,6 +682,11 @@
   def int_nvvm_bitcast_d2ll : GCCBuiltin<"__nvvm_bitcast_d2ll">,
   Intrinsic<[llvm_i64_ty], [llvm_double_ty], [IntrNoMem]>;
 
+// FNS
+
+  def int_nvvm_fns : GCCBuiltin<"__nvvm_fns">,
+  Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
+[IntrNoMem]>;
 
 // Atomics not available as llvm intrinsics.
   def int_nvvm_atomic_load_add_f32 : Intrinsic<[llvm_float_ty],
Index: llvm/trunk/test/CodeGen/NVPTX/fns.ll
===
--- llvm/trunk/test/CodeGen/NVPTX/fns.ll
+++ llvm/trunk/test/CodeGen/NVPTX/fns.ll
@@ -0,0 +1,36 @@
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_30 -mattr=+ptx60 | FileCheck %s
+
+declare i32 @llvm.nvvm.fns(i32, i32, i32)
+
+; CHECK-LABEL: .func{{.*}}fns
+define i32 @fns(i32 %mask, i32 %base, i32 %offset) {
+  ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [fns_param_0];
+  ; CHECK: ld.param.u32 	[[BASE:%r[0-9]+]], [fns_param_1];
+  ; CHECK: ld.param.u32 	[[OFFSET:%r[0-9]+]], [fns_param_2];
+
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, [[MASK]], [[BASE]], [[OFFSET]];
+  %r0 = call i32 @llvm.nvvm.fns(i32 %mask, i32 %base, i32 %offset);
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, [[MASK]], [[BASE]], 0;
+  %r1 = call i32 @llvm.nvvm.fns(i32 %mask, i32 %base, i32 0);
+  %r01 = add i32 %r0, %r1;
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, [[MASK]], 1, [[OFFSET]];
+  %r2 = call i32 @llvm.nvvm.fns(i32 %mask, i32 1, i32 %offset);
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, [[MASK]], 1, 0;
+  %r3 = call i32 @llvm.nvvm.fns(i32 %mask, i32 1, i32 0);
+  %r23 = add i32 %r2, %r3;
+  %r0123 = add i32 %r01, %r23;
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, 2, [[BASE]], [[OFFSET]];
+  %r4 = call i32 @llvm.nvvm.fns(i32 2, i32 %base, i32 %offset);
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, 2, [[BASE]], 0;
+  %r5 = call i32 @llvm.nvvm.fns(i32 2, i32 %base, i32 0);
+  %r45 = add i32 %r4, %r5;
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, 2, 1, [[OFFSET]];
+  %r6 = call i32 @llvm.nvvm.fns(i32 2, i32 1, i32 %offset);
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, 2, 1, 0;
+  %r7 = call i32 @llvm.nvvm.fns(i32 2, i32 1, i32 0);
+  %r67 = add i32 %r6, %r7;
+  %r4567 = add i32 %r45, %r67;
+  %r = add i32 %r0123, %r4567;
+  ret i32 %r;
+}
+
Index: llvm/trunk/lib/Target/NVPTX/NVPTXIntrinsics.td
===
--- llvm/trunk/lib/Target/NVPTX/NVPTXIntrinsics.td
+++ llvm/trunk/lib/Target/NVPTX/NVPTXIntrinsics.td
@@ -979,6 +979,33 @@
 def INT_NVVM_BITCAST_D2LL : F_MATH_1<"mov.b64 \t$dst, $src0;", Int64Regs,
   Float64Regs, int_nvvm_bitcast_d2ll>;
 
+//
+// FNS
+//
+
+class INT_FNS_MBO
+  : NVPTXInst<(outs Int32Regs:$dst), ins,
+   "fns.b32 \t$dst, $mask, $base, $offset;",
+   [(set Int32Regs:$dst, Operands )]>,
+Requires<[hasPTX60, hasSM30]>;
+
+def INT_FNS_rrr : INT_FNS_MBO<(ins Int32Regs:$mask, Int32Regs:$base, Int32Regs:$offset),
+ (int_nvvm_fns Int32Regs:$mask, Int32Regs:$base, Int32Regs:$offset)>;
+def INT_FNS_rri : INT_FNS_MBO<(ins Int32Regs:$mask, Int32Regs:$base,i32imm:$offset),
+ (int_nvvm_fns Int32Regs:$mask, Int32Regs:$base,   imm:$offset)>;
+def INT_FNS_rir : INT_FNS_MBO<(ins Int32Regs:$mask,i32imm:$base, Int32Regs:$offset),
+ (int_nvvm_fns Int32Regs:$mask,   imm:$base, Int32Regs:$offset)>;
+def INT_FNS_rii : INT_FNS_MBO<(ins Int32Regs:$mask,i32imm:$base,i32imm:$offset),
+ (int_nvvm_fns Int32Regs:$mask,   imm:$base,   imm:$offset)>;
+def INT_FNS_irr : INT_FNS_MBO<(insi32imm:$mask, Int32Regs:$base, Int32Regs:$offset),
+ (int_nvvm_fns   imm:$mask, Int32Regs:$base, Int32Regs:$offset)>;
+def INT_FNS_iri : INT_FNS_MBO<(insi32imm:$mask, Int32Regs:$base,i32imm:$offset),
+ (int_nvvm_fns   imm:$mask, Int32Regs:$base,   imm:$offset)>;
+def INT_FNS_iir : INT_FNS_MBO<(insi32imm:$mask,i32imm:$base, Int32Regs:$offset),
+ (int_nvvm_fns   imm:$mask,   imm:$base, Int32Regs:$offset)>;
+def INT_FNS_iii : INT_FNS_MBO<(insi32imm:$mask,i32imm:$base,i32imm:$offset),
+ (int_nvvm_fns   imm:

[PATCH] D40567: Always show template parameters in IR type names

2017-12-06 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 125761.
sepavloff added a comment.

Updated patch

- old type names are generated always if --ir-type-names is not specified,
- added new value of --ir-type-names, none, to suppress type names,
- value of --ir-type-names is stored in module properties.


Repository:
  rC Clang

https://reviews.llvm.org/D40567

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGenCXX/template-types.cpp

Index: test/CodeGenCXX/template-types.cpp
===
--- /dev/null
+++ test/CodeGenCXX/template-types.cpp
@@ -0,0 +1,118 @@
+// RUN: %clang_cc1 %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -S -emit-llvm --ir-type-names=none -o - | FileCheck %s --check-prefix=CHECK-NONE
+// RUN: %clang_cc1 %s -S -emit-llvm --ir-type-names=terse -o - | FileCheck %s --check-prefix=CHECK-TERSE
+// RUN: %clang_cc1 %s -S -emit-llvm --ir-type-names=full -o - | FileCheck %s --check-prefix=CHECK-FULL
+
+struct Empty {};
+template struct ABC {
+  T v;
+};
+struct Opaque;
+template class OpaqueClass;
+
+ABC var_1;
+ABC > var_2;
+ABC var_3;
+ABC *var_4;
+OpaqueClass *var_5;
+OpaqueClass *var_6;
+OpaqueClass *var_7;
+OpaqueClass > *var_8;
+
+
+//-- without option '--ir-type-names'
+
+// CHECK: %struct.ABC = type { i32 }
+// CHECK: %struct.ABC.0 = type { %struct.ABC.1 }
+// CHECK: %struct.ABC.1 = type { i16 }
+// CHECK: %struct.ABC.2 = type { %struct.Empty }
+// CHECK: %struct.Empty = type { i8 }
+// CHECK: %class.OpaqueClass = type opaque
+// CHECK: %class.OpaqueClass.4 = type opaque
+// CHECK: %class.OpaqueClass.5 = type opaque
+// CHECK: %class.OpaqueClass.6 = type opaque
+
+// CHECK: @var_1 = global %struct.ABC zeroinitializer
+// CHECK: @var_2 = global %struct.ABC.0 zeroinitializer
+// CHECK: @var_3 = global %struct.ABC.2 zeroinitializer
+// CHECK: @var_4 = global %struct.ABC.3* null
+// CHECK: @var_5 = global %class.OpaqueClass* null
+// CHECK: @var_6 = global %class.OpaqueClass.4* null
+// CHECK: @var_7 = global %class.OpaqueClass.5* null
+// CHECK: @var_8 = global %class.OpaqueClass.6* null
+
+// CHECK-NOT: !{{[0-9]+}} = !{{{.*}} !"type_names"
+
+
+//-- with option '--ir-type-names=none'
+
+// CHECK-NONE: %0 = type { i32 }
+// CHECK-NONE: %1 = type { %2 }
+// CHECK-NONE: %2 = type { i16 }
+// CHECK-NONE: %3 = type { %4 }
+// CHECK-NONE: %4 = type { i8 }
+// CHECK-NONE: %5 = type opaque
+// CHECK-NONE: %6 = type opaque
+// CHECK-NONE: %7 = type opaque
+// CHECK-NONE: %8 = type opaque
+// CHECK-NONE: %9 = type opaque
+
+// CHECK-NONE: @var_1 = global %0 zeroinitializer
+// CHECK-NONE: @var_2 = global %1 zeroinitializer
+// CHECK-NONE: @var_3 = global %3 zeroinitializer
+// CHECK-NONE: @var_4 = global %5* null
+// CHECK-NONE: @var_5 = global %6* null
+// CHECK-NONE: @var_6 = global %7* null
+// CHECK-NONE: @var_7 = global %8* null
+// CHECK-NONE: @var_8 = global %9* null
+
+// CHECK-NONE: !{{[0-9]+}} = !{{{.*}} !"type_names", i32 1}
+
+
+//-- with option '--ir-type-names=terse'
+
+// CHECK-TERSE: %struct.ABC = type { i32 }
+// CHECK-TERSE: %struct.ABC.0 = type { %struct.ABC.1 }
+// CHECK-TERSE: %struct.ABC.1 = type { i16 }
+// CHECK-TERSE: %struct.ABC.2 = type { %struct.Empty }
+// CHECK-TERSE: %struct.Empty = type { i8 }
+// CHECK-TERSE: %class.OpaqueClass = type opaque
+// CHECK-TERSE: %class.OpaqueClass.4 = type opaque
+// CHECK-TERSE: %class.OpaqueClass.5 = type opaque
+// CHECK-TERSE: %class.OpaqueClass.6 = type opaque
+
+// CHECK-TERSE: @var_1 = global %struct.ABC zeroinitializer
+// CHECK-TERSE: @var_2 = global %struct.ABC.0 zeroinitializer
+// CHECK-TERSE: @var_3 = global %struct.ABC.2 zeroinitializer
+// CHECK-TERSE: @var_4 = global %struct.ABC.3* null
+// CHECK-TERSE: @var_5 = global %class.OpaqueClass* null
+// CHECK-TERSE: @var_6 = global %class.OpaqueClass.4* null
+// CHECK-TERSE: @var_7 = global %class.OpaqueClass.5* null
+// CHECK-TERSE: @var_8 = global %class.OpaqueClass.6* null
+
+// CHECK-TERSE: !{{[0-9]+}} = !{{{.*}} !"type_names", i32 2}
+
+
+//-- with option '--ir-type-names=full'
+
+// CHECK-FULL: %"struct.ABC" = type { i32 }
+// CHECK-FULL: %"struct.ABC >" = type { %"struct.ABC" }
+// CHECK-FULL: %"struct.ABC" = type { i16 }
+// CHECK-FULL: %"struct.ABC" = type { %struct.Empty }
+// CHECK-FULL: %struct.Empty = type { i8 }
+// CHECK-FULL: %"struct.ABC" = type opaque
+// CHECK-FULL: %"class.OpaqueClass" = type opaque
+// CHECK-FULL: %"class.OpaqueClass" = type opaque
+// CHECK-FULL: %"class.OpaqueClass" = type opaque
+// CHECK-FULL: %"class.OpaqueClass >" = type opaque
+
+// CHECK-FULL: @var_1 = global %"struct.ABC" zeroinitializer
+// CHECK-FULL: @var_2 = global %"struct.ABC >" zeroinitializer
+// CHECK-FULL: @var_3 = global %"struct.ABC" zeroinitializer
+// CHECK-FULL: @var_4 = globa

Re: [PATCH] D40838: [OpenCL] Fix layering violation by getOpenCLTypeAddrSpace

2017-12-06 Thread David Blaikie via cfe-commits
Thanks!

On Wed, Dec 6, 2017 at 2:12 AM Sven van Haastregt via Phabricator <
revi...@reviews.llvm.org> wrote:

> This revision was automatically updated to reflect the committed changes.
> Closed by commit rC319883: [OpenCL] Fix layering violation by
> getOpenCLTypeAddrSpace (authored by svenvh).
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D40838
>
> Files:
>   include/clang/AST/ASTContext.h
>   include/clang/Basic/TargetInfo.h
>   lib/AST/ASTContext.cpp
>   lib/Basic/TargetInfo.cpp
>   lib/Basic/Targets/AMDGPU.h
>   lib/CodeGen/CGOpenCLRuntime.cpp
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r319875 - Fix a bunch of wrong "tautological unsigned enum compare" diagnostics in C++.

2017-12-06 Thread Hans Wennborg via cfe-commits
This made Clang start warning about unsigned vs enum compares on Windows.

$ echo 'enum E { foo }; bool f(unsigned a, E b) { return a == b; }' |
bin/clang -Wsign-compare -c -x c++ - -target i686-pc-win32
:1:52: warning: comparison of integers of different signs:
'unsigned int' and 'E' [-Wsign-compare]
enum E { foo }; bool f(unsigned a, E b) { return a == b; }
 ~ ^  ~

That's probably intentional and I think we can fix the ones that came
up, just wanted to let you know.


On Tue, Dec 5, 2017 at 7:00 PM, Richard Smith via cfe-commits
 wrote:
>
> Author: rsmith
> Date: Tue Dec  5 19:00:51 2017
> New Revision: 319875
>
> URL: http://llvm.org/viewvc/llvm-project?rev=319875&view=rev
> Log:
> Fix a bunch of wrong "tautological unsigned enum compare" diagnostics in C++.
>
> An enumeration with a fixed underlying type can have any value in its
> underlying type, not just those spanned by the values of its enumerators.
>
> Modified:
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=319875&r1=319874&r2=319875&view=diff
> ==
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Dec  5 19:00:51 2017
> @@ -8260,11 +8260,12 @@ struct IntRange {
>  } else if (const EnumType *ET = dyn_cast(T)) {
>// For enum types in C++, use the known bit width of the enumerators.
>EnumDecl *Enum = ET->getDecl();
> -  // In C++11, enums without definitions can have an explicitly specified
> -  // underlying type.  Use this type to compute the range.
> -  if (!Enum->isCompleteDefinition())
> +  // In C++11, enums can have a fixed underlying type. Use this type to
> +  // compute the range.
> +  if (Enum->isFixed()) {
>  return IntRange(C.getIntWidth(QualType(T, 0)),
>  !ET->isSignedIntegerOrEnumerationType());
> +  }
>
>unsigned NumPositive = Enum->getNumPositiveBits();
>unsigned NumNegative = Enum->getNumNegativeBits();
>
> Modified: cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp?rev=319875&r1=319874&r2=319875&view=diff
> ==
> --- cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp (original)
> +++ cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp Tue Dec  
> 5 19:00:51 2017
> @@ -2,11 +2,11 @@
>  // RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED 
> -verify %s
>  // RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only 
> -DSILENCE -Wno-tautological-unsigned-enum-zero-compare -verify %s
>
> -// Okay, this is where it gets complicated.
> -// Then default enum sigdness is target-specific.
> -// On windows, it is signed by default. We do not want to warn in that case.
> -
>  int main() {
> +  // On Windows, all enumerations have a fixed underlying type, which is 
> 'int'
> +  // if not otherwise specified, so A is identical to C on Windows. 
> Otherwise,
> +  // we follow the C++ rules, which say that the only valid values of A are 0
> +  // and 1.
>enum A { A_foo = 0, A_bar, };
>enum A a;
>
> @@ -87,21 +87,23 @@ int main() {
>
>if (c < 0)
>  return 0;
> -  if (0 >= c) // expected-warning {{comparison 0 >= 'enum C' is always true}}
> +  if (0 >= c)
>  return 0;
> -  if (c > 0) // expected-warning {{comparison 'enum C' > 0 is always false}}
> +  if (c > 0)
>  return 0;
>if (0 <= c)
>  return 0;
> -  if (c <= 0) // expected-warning {{comparison 'enum C' <= 0 is always true}}
> +  if (c <= 0)
>  return 0;
>if (0 > c)
>  return 0;
>if (c >= 0)
>  return 0;
> -  if (0 < c) // expected-warning {{0 < 'enum C' is always false}}
> +  if (0 < c)
>  return 0;
>
> +  // FIXME: These diagnostics are terrible. The issue here is that the signed
> +  // enumeration value was promoted to an unsigned type.
>if (c < 0U) // expected-warning {{comparison of unsigned enum expression < 
> 0 is always false}}
>  return 0;
>if (0U >= c)
> @@ -121,21 +123,23 @@ int main() {
>  #elif defined(SIGNED)
>if (a < 0)
>  return 0;
> -  if (0 >= a) // expected-warning {{comparison 0 >= 'enum A' is always true}}
> +  if (0 >= a)
>  return 0;
> -  if (a > 0) // expected-warning {{comparison 'enum A' > 0 is always false}}
> +  if (a > 0)
>  return 0;
>if (0 <= a)
>  return 0;
> -  if (a <= 0) // expected-warning {{comparison 'enum A' <= 0 is always true}}
> +  if (a <= 0)
>  return 0;
>if (0 > a)
>  return 0;
>if (a >= 0)
>  return 0;
> -  if (0 < a) //

LLVM buildmaster will be updated and restarted tonight

2017-12-06 Thread Galina Kistanova via cfe-commits
Hello everyone,

LLVM buildmaster will be updated and restarted after 7 PM Pacific time.

Thanks

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


[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld created this revision.
Herald added a subscriber: cfe-commits.

The adjustment is calculated with CreatePtrDiff() which returns
the difference in (base) elements. This is passed to CreateGEP()
so make sure that the GEP base has the correct pointer type:
It needs to be a pointer to the base type, not a pointer to a
constant sized array.


Repository:
  rC Clang

https://reviews.llvm.org/D40911

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/for_reduction_codegen.cpp
  test/OpenMP/for_reduction_codegen_UDR.cpp

Index: test/OpenMP/for_reduction_codegen_UDR.cpp
===
--- test/OpenMP/for_reduction_codegen_UDR.cpp
+++ test/OpenMP/for_reduction_codegen_UDR.cpp
@@ -735,7 +735,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VVAR2_PRIV:%.+]] = getelementptr [5 x [[S_FLOAT_TY]]], [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VVAR2_PRIV_PTR:%.+]] = bitcast [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VVAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VVAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: ret void
 
 // CHECK: define internal void [[MAIN_MICROTASK5]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, [4 x [[S_FLOAT_TY]]]* dereferenceable(48) %{{.+}})
@@ -761,8 +762,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [2 x [[S_FLOAT_TY]]], [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], i64 [[OFFSET]]
-// CHECK: [[VAR3_PRIV:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
+// CHECK: [[VAR3_PRIV_PTR:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR3_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[VAR3_PRIV:%.+]] = bitcast [[S_FLOAT_TY]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
 
 // CHECK: store [4 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], [4 x [[S_FLOAT_TY]]]** %
 
@@ -985,8 +987,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_INT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_INT_TY]]* getelementptr ([[S_INT_TY]], [[S_INT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [40 x [[S_INT_TY]]], [40 x [[S_INT_TY]]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[ARR_PRIV]] to [[S_INT_TY]]*
+// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [[S_INT_TY]], [[S_INT_TY]]* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[ARR_PRIV:%.+]] = bitcast [[S_INT_TY]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
 
 // CHECK: ret void
 
Index: test/OpenMP/for_reduction_codegen.cpp
===
--- test/OpenMP/for_reduction_codegen.cpp
+++ test/OpenMP/for_reduction_codegen.cpp
@@ -944,8 +944,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint i32* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (i32* getelementptr (i32, i32* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [1 x [2 x i32]], [1 x [2 x i32]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [1 x [2 x i32]]* [[PSEUDO_ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [1 x [2 x i32]]* [[ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV:%.+]] = getelementptr i32, i32* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
 
 // CHECK: ret void
 
@@ -1000,9 +1000,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR2_PRIV:%.+]] = getelementptr [1 x [6 x [[S_FLOAT_TY, [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VAR2_PRIV_PTR:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: store [[S_FLOAT_TY]]** [[REF:.+]], [[S_FLOAT_TY]]*** %
-// CHECK: [[VAR2_PRIV:%.+]] = bitcast [1 x [6 

[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:1110
+PrivateAddr.getPointer(),
+SharedAddresses[N].first.getPointer()->getType());
+llvm::Value *Ptr = CGF.Builder.CreateGEP(PrivatePointer, Adjustment);

Better to use `SharedAddresses[N].first.getAddress().getType()`


Repository:
  rC Clang

https://reviews.llvm.org/D40911



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


[PATCH] D40897: [clangd] Introduce a "Symbol" class.

2017-12-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In https://reviews.llvm.org/D40897#946708, @malaperle wrote:

> Hi! Have you looked into https://reviews.llvm.org/D40548 ? Maybe we need to 
> coordinate the two a bit.


Hi Marc! Thanks for the input!

Yeah, Eric and I are working closely on a prototype of global code completion. 
We have implemented the initial version (see github 
),
 and the prototype works well for LLVM project (even with a simple 
implementation), so we plan to split the patch, improve the code, and 
contribute it back to clangd repo incrementally.

For the prototype, we will load all symbols (without occurrences) into the 
memory, and build an in-memory index. From our experiment, the dataset of LLVM 
project in YAML format is ~120MB (~38,000 symbols), which is acceptable in 
clangd.

Our rough plan would be

1. Define the Symbol structure.
2. Design the interfaces of SymbolIndex, ASTIndex.
3. Combine 1) and 2) together to make global code completion work (we'd use 
YAML dataset for LLVM project, note that this is not a final solution, it would 
be hidden in an `--experimental` flag).
4. Switch to use the dataset from index-while-building when it is ready.




Comment at: clangd/Symbol.h:37
+// The class presents a C++ symbol, e.g. class, function.
+struct Symbol {
+  // The symbol identifier, using USR.

malaperle wrote:
> I think it would be nice to have methods as an interface to get this data 
> instead of storing them directly. So that an index-on-disk could go fetch the 
> data. Especially the occurrences which can take a lot of memory (I'm working 
> on a branch that does that). But perhaps defining that interface is not 
> within the scope of this patch and could be better discussed in D40548 ?
I agree. We can't load all the symbol occurrences into the memory since they 
are too large. We need to design interface for the symbol occurrences. 

We could discuss the interface here, but CodeCompletion is the main thing which 
this patch focuses on. 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40897



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


[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:1110
+PrivateAddr.getPointer(),
+SharedAddresses[N].first.getPointer()->getType());
+llvm::Value *Ptr = CGF.Builder.CreateGEP(PrivatePointer, Adjustment);

ABataev wrote:
> Better to use `SharedAddresses[N].first.getAddress().getType()`
Ok, was copied from below call to `castToBase()`. Should I adjust it there as 
well?


Repository:
  rC Clang

https://reviews.llvm.org/D40911



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


[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:1110
+PrivateAddr.getPointer(),
+SharedAddresses[N].first.getPointer()->getType());
+llvm::Value *Ptr = CGF.Builder.CreateGEP(PrivatePointer, Adjustment);

Hahnfeld wrote:
> ABataev wrote:
> > Better to use `SharedAddresses[N].first.getAddress().getType()`
> Ok, was copied from below call to `castToBase()`. Should I adjust it there as 
> well?
Yes, please


Repository:
  rC Clang

https://reviews.llvm.org/D40911



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


[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld updated this revision to Diff 125768.
Hahnfeld marked 3 inline comments as done.
Hahnfeld added a comment.

Get type from `Address`.


https://reviews.llvm.org/D40911

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/for_reduction_codegen.cpp
  test/OpenMP/for_reduction_codegen_UDR.cpp

Index: test/OpenMP/for_reduction_codegen_UDR.cpp
===
--- test/OpenMP/for_reduction_codegen_UDR.cpp
+++ test/OpenMP/for_reduction_codegen_UDR.cpp
@@ -735,7 +735,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VVAR2_PRIV:%.+]] = getelementptr [5 x [[S_FLOAT_TY]]], [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VVAR2_PRIV_PTR:%.+]] = bitcast [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VVAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VVAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: ret void
 
 // CHECK: define internal void [[MAIN_MICROTASK5]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, [4 x [[S_FLOAT_TY]]]* dereferenceable(48) %{{.+}})
@@ -761,8 +762,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [2 x [[S_FLOAT_TY]]], [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], i64 [[OFFSET]]
-// CHECK: [[VAR3_PRIV:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
+// CHECK: [[VAR3_PRIV_PTR:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR3_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[VAR3_PRIV:%.+]] = bitcast [[S_FLOAT_TY]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
 
 // CHECK: store [4 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], [4 x [[S_FLOAT_TY]]]** %
 
@@ -985,8 +987,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_INT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_INT_TY]]* getelementptr ([[S_INT_TY]], [[S_INT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [40 x [[S_INT_TY]]], [40 x [[S_INT_TY]]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[ARR_PRIV]] to [[S_INT_TY]]*
+// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [[S_INT_TY]], [[S_INT_TY]]* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[ARR_PRIV:%.+]] = bitcast [[S_INT_TY]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
 
 // CHECK: ret void
 
Index: test/OpenMP/for_reduction_codegen.cpp
===
--- test/OpenMP/for_reduction_codegen.cpp
+++ test/OpenMP/for_reduction_codegen.cpp
@@ -944,8 +944,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint i32* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (i32* getelementptr (i32, i32* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [1 x [2 x i32]], [1 x [2 x i32]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [1 x [2 x i32]]* [[PSEUDO_ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [1 x [2 x i32]]* [[ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV:%.+]] = getelementptr i32, i32* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
 
 // CHECK: ret void
 
@@ -1000,9 +1000,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR2_PRIV:%.+]] = getelementptr [1 x [6 x [[S_FLOAT_TY, [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VAR2_PRIV_PTR:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: store [[S_FLOAT_TY]]** [[REF:.+]], [[S_FLOAT_TY]]*** %
-// CHECK: [[VAR2_PRIV:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* [[PSEUDO_VAR2_PRIV]] to [[S_FLOAT_TY]]*
 // CHECK: store [[S_FLOAT_TY]]* [[VAR2_PRIV]], [[S_FLOAT_TY]]** [[REF]]
 // CHECK: ret void
 
@@ -1029,9 +1029,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY

[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D40911



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


r319931 - Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Wed Dec  6 11:15:28 2017
New Revision: 319931

URL: http://llvm.org/viewvc/llvm-project?rev=319931&view=rev
Log:
Fix PR35542: Correct adjusting of private reduction variable

The adjustment is calculated with CreatePtrDiff() which returns
the difference in (base) elements. This is passed to CreateGEP()
so make sure that the GEP base has the correct pointer type:
It needs to be a pointer to the base type, not a pointer to a
constant sized array.

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

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=319931&r1=319930&r2=319931&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed Dec  6 11:15:28 2017
@@ -1104,11 +1104,14 @@ Address ReductionCodeGen::adjustPrivateA
 OriginalBaseLValue);
 llvm::Value *Adjustment = CGF.Builder.CreatePtrDiff(
 BaseLValue.getPointer(), SharedAddresses[N].first.getPointer());
-llvm::Value *Ptr =
-CGF.Builder.CreateGEP(PrivateAddr.getPointer(), Adjustment);
+llvm::Value *PrivatePointer =
+CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
+PrivateAddr.getPointer(),
+SharedAddresses[N].first.getAddress().getType());
+llvm::Value *Ptr = CGF.Builder.CreateGEP(PrivatePointer, Adjustment);
 return castToBase(CGF, OrigVD->getType(),
   SharedAddresses[N].first.getType(),
-  OriginalBaseLValue.getPointer()->getType(),
+  OriginalBaseLValue.getAddress().getType(),
   OriginalBaseLValue.getAlignment(), Ptr);
   }
   BaseDecls.emplace_back(

Modified: cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_reduction_codegen.cpp?rev=319931&r1=319930&r2=319931&view=diff
==
--- cfe/trunk/test/OpenMP/for_reduction_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/for_reduction_codegen.cpp Wed Dec  6 11:15:28 2017
@@ -944,8 +944,8 @@ int main() {
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint i32* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (i32* 
getelementptr (i32, i32* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [1 x [2 x i32]], [1 x [2 x 
i32]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [1 x [2 x i32]]* [[PSEUDO_ARR_PRIV]] to 
i32*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [1 x [2 x i32]]* [[ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV:%.+]] = getelementptr i32, i32* [[ARR_PRIV_PTR]], i64 
[[OFFSET]]
 
 // CHECK: ret void
 
@@ -1000,9 +1000,9 @@ int main() {
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (float* 
getelementptr (float, float* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR2_PRIV:%.+]] = getelementptr [1 x [6 x [[S_FLOAT_TY, 
[1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VAR2_PRIV_PTR:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* 
[[VAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* 
[[VAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: store [[S_FLOAT_TY]]** [[REF:.+]], [[S_FLOAT_TY]]*** %
-// CHECK: [[VAR2_PRIV:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* 
[[PSEUDO_VAR2_PRIV]] to [[S_FLOAT_TY]]*
 // CHECK: store [[S_FLOAT_TY]]* [[VAR2_PRIV]], [[S_FLOAT_TY]]** [[REF]]
 // CHECK: ret void
 
@@ -1029,9 +1029,9 @@ int main() {
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (float* 
getelementptr (float, float* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR2_PRIV:%.+]] = getelementptr [1 x [6 x [[S_FLOAT_TY, 
[1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VAR2_PRIV_PTR:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* 
[[VAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* 
[[VAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: store [[S_FLOAT_TY]]** [[REF:.+]], [[S_FLOAT_TY]]*** %
-// CHECK: [[VAR2_PRIV:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* 
[[PSEUDO_VAR2_PRIV]] to [[S_FLOAT_TY]]*
 // CHECK: store [[S_FLOAT_TY]]* [[VAR2_PRIV]], [[S_FLOAT_TY]]** [[REF]]
 // CHECK: ret void
 
@@ -1080,7 +1080,8 @@ int main() {
 // CHECK: 

[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319931: Fix PR35542: Correct adjusting of private reduction 
variable (authored by Hahnfeld).

Changed prior to commit:
  https://reviews.llvm.org/D40911?vs=125768&id=125770#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40911

Files:
  cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
  cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
  cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp

Index: cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp
===
--- cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp
+++ cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp
@@ -735,7 +735,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VVAR2_PRIV:%.+]] = getelementptr [5 x [[S_FLOAT_TY]]], [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VVAR2_PRIV_PTR:%.+]] = bitcast [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VVAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VVAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: ret void
 
 // CHECK: define internal void [[MAIN_MICROTASK5]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, [4 x [[S_FLOAT_TY]]]* dereferenceable(48) %{{.+}})
@@ -761,8 +762,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [2 x [[S_FLOAT_TY]]], [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], i64 [[OFFSET]]
-// CHECK: [[VAR3_PRIV:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
+// CHECK: [[VAR3_PRIV_PTR:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR3_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[VAR3_PRIV:%.+]] = bitcast [[S_FLOAT_TY]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
 
 // CHECK: store [4 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], [4 x [[S_FLOAT_TY]]]** %
 
@@ -985,8 +987,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_INT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_INT_TY]]* getelementptr ([[S_INT_TY]], [[S_INT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [40 x [[S_INT_TY]]], [40 x [[S_INT_TY]]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[ARR_PRIV]] to [[S_INT_TY]]*
+// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [[S_INT_TY]], [[S_INT_TY]]* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[ARR_PRIV:%.+]] = bitcast [[S_INT_TY]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
 
 // CHECK: ret void
 
Index: cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
===
--- cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
+++ cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
@@ -944,8 +944,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint i32* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (i32* getelementptr (i32, i32* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [1 x [2 x i32]], [1 x [2 x i32]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [1 x [2 x i32]]* [[PSEUDO_ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [1 x [2 x i32]]* [[ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV:%.+]] = getelementptr i32, i32* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
 
 // CHECK: ret void
 
@@ -1000,9 +1000,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR2_PRIV:%.+]] = getelementptr [1 x [6 x [[S_FLOAT_TY, [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VAR2_PRIV_PTR:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: store [[S_FLOAT_TY]]** [[REF:.+]], [[S_FLOAT_TY]]*** %
-// CHECK: [[VAR2_PRIV:%.+]] = bitc

[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC319931: Fix PR35542: Correct adjusting of private reduction 
variable (authored by Hahnfeld).

Repository:
  rC Clang

https://reviews.llvm.org/D40911

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/for_reduction_codegen.cpp
  test/OpenMP/for_reduction_codegen_UDR.cpp

Index: test/OpenMP/for_reduction_codegen_UDR.cpp
===
--- test/OpenMP/for_reduction_codegen_UDR.cpp
+++ test/OpenMP/for_reduction_codegen_UDR.cpp
@@ -735,7 +735,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VVAR2_PRIV:%.+]] = getelementptr [5 x [[S_FLOAT_TY]]], [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VVAR2_PRIV_PTR:%.+]] = bitcast [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VVAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VVAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: ret void
 
 // CHECK: define internal void [[MAIN_MICROTASK5]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, [4 x [[S_FLOAT_TY]]]* dereferenceable(48) %{{.+}})
@@ -761,8 +762,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [2 x [[S_FLOAT_TY]]], [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], i64 [[OFFSET]]
-// CHECK: [[VAR3_PRIV:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
+// CHECK: [[VAR3_PRIV_PTR:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR3_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[VAR3_PRIV:%.+]] = bitcast [[S_FLOAT_TY]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
 
 // CHECK: store [4 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], [4 x [[S_FLOAT_TY]]]** %
 
@@ -985,8 +987,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_INT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_INT_TY]]* getelementptr ([[S_INT_TY]], [[S_INT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [40 x [[S_INT_TY]]], [40 x [[S_INT_TY]]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[ARR_PRIV]] to [[S_INT_TY]]*
+// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [[S_INT_TY]], [[S_INT_TY]]* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[ARR_PRIV:%.+]] = bitcast [[S_INT_TY]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
 
 // CHECK: ret void
 
Index: test/OpenMP/for_reduction_codegen.cpp
===
--- test/OpenMP/for_reduction_codegen.cpp
+++ test/OpenMP/for_reduction_codegen.cpp
@@ -944,8 +944,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint i32* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (i32* getelementptr (i32, i32* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [1 x [2 x i32]], [1 x [2 x i32]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [1 x [2 x i32]]* [[PSEUDO_ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [1 x [2 x i32]]* [[ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV:%.+]] = getelementptr i32, i32* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
 
 // CHECK: ret void
 
@@ -1000,9 +1000,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR2_PRIV:%.+]] = getelementptr [1 x [6 x [[S_FLOAT_TY, [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VAR2_PRIV_PTR:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: store [[S_FLOAT_TY]]** [[REF:.+]], [[S_FLOAT_TY]]*** %
-// CHECK: [[VAR2_PRIV:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* [[PSEUDO_VAR2_PRIV]] to [[S_FLOAT_TY]]*
 // CHECK: store [[S_FLOAT_TY]]* [[VAR2_PRIV]], [[S_FLOAT_TY]]** [[REF]]
 // CHECK: ret void
 
@@ -10

r319942 - Delete special-case "out-of-range" handling for bools, and just use the normal

2017-12-06 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Dec  6 11:23:19 2017
New Revision: 319942

URL: http://llvm.org/viewvc/llvm-project?rev=319942&view=rev
Log:
Delete special-case "out-of-range" handling for bools, and just use the normal
codepath plus the new "minimum / maximum value of type" diagnostic to get the
same effect.

Move the warning for an in-range but tautological comparison of a constant (0
or 1) against a bool out of -Wtautological-constant-out-of-range-compare into
the more-appropriate -Wtautological-constant-compare.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=319942&r1=319941&r2=319942&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Dec  6 11:23:19 
2017
@@ -5952,6 +5952,8 @@ def warn_out_of_range_compare : Warning<
   "comparison of %select{constant %0|true|false}1 with " 
   "%select{expression of type %2|boolean expression}3 is always "
   "%select{false|true}4">, InGroup;
+def warn_tautological_bool_compare : Warning,
+  InGroup;
 def warn_comparison_of_mixed_enum_types : Warning<
   "comparison of two values with different enumeration types"
   "%diff{ ($ and $)|}0,1">,

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=319942&r1=319941&r2=319942&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Dec  6 11:23:19 2017
@@ -8650,15 +8650,8 @@ static bool IsEnumConstOrFromMacro(Sema
   return false;
 }
 
-static bool isNonBooleanIntegerValue(Expr *E) {
-  return !E->isKnownToHaveBooleanValue() && E->getType()->isIntegerType();
-}
-
-static bool isNonBooleanUnsignedValue(Expr *E) {
-  // We are checking that the expression is not known to have boolean value,
-  // is an integer type; and is either unsigned after implicit casts,
-  // or was unsigned before implicit casts.
-  return isNonBooleanIntegerValue(E) &&
+static bool isKnownToHaveUnsignedValue(Expr *E) {
+  return E->getType()->isIntegerType() &&
  (!E->getType()->isSignedIntegerType() ||
   !E->IgnoreParenImpCasts()->getType()->isSignedIntegerType());
 }
@@ -8684,7 +8677,7 @@ static llvm::Optional IsTypeL
   if (IsEnumConstOrFromMacro(S, Constant))
 return llvm::Optional();
 
-  if (isNonBooleanUnsignedValue(Other) && Value == 0)
+  if (isKnownToHaveUnsignedValue(Other) && Value == 0)
 return LimitType::Min;
 
   // TODO: Investigate using GetExprRange() to get tighter bounds
@@ -8694,20 +8687,20 @@ static llvm::Optional IsTypeL
 OtherT = AT->getValueType();
 
   IntRange OtherRange = IntRange::forValueOfType(S.Context, OtherT);
+  if (Other->isKnownToHaveBooleanValue())
+OtherRange = IntRange::forBoolType();
 
   // Special-case for C++ for enum with one enumerator with value of 0.
   if (OtherRange.Width == 0)
 return Value == 0 ? LimitType::Both : llvm::Optional();
 
   if (llvm::APSInt::isSameValue(
-  llvm::APSInt::getMaxValue(OtherRange.Width,
-OtherT->isUnsignedIntegerType()),
+  llvm::APSInt::getMaxValue(OtherRange.Width, OtherRange.NonNegative),
   Value))
 return LimitType::Max;
 
   if (llvm::APSInt::isSameValue(
-  llvm::APSInt::getMinValue(OtherRange.Width,
-OtherT->isUnsignedIntegerType()),
+  llvm::APSInt::getMinValue(OtherRange.Width, OtherRange.NonNegative),
   Value))
 return LimitType::Min;
 
@@ -8726,6 +8719,20 @@ static bool HasEnumType(Expr *E) {
   return E->getType()->isEnumeralType();
 }
 
+static int classifyConstantValue(Expr *Constant) {
+  // The values of this enumeration are used in the diagnostics
+  // diag::warn_out_of_range_compare and diag::warn_tautological_bool_compare.
+  enum ConstantValueKind {
+Miscellaneous = 0,
+LiteralTrue,
+LiteralFalse
+  };
+  if (auto *BL = dyn_cast(Constant))
+return BL->getValue() ? ConstantValueKind::LiteralTrue
+  : ConstantValueKind::LiteralFalse;
+  return ConstantValueKind::Miscellaneous;
+}
+
 static bool CheckTautologicalComparison(Sema &S, BinaryOperator *E,
 Expr *Constant, Expr *Other,
 const llvm::APSInt &Value,
@@ -8738,11 +8745,12 @@ static bool CheckTautologicalComparison(
   BinaryOperatorKind Op = E->getOpcode();
 
   QualType OType = Other->IgnoreParenImpCasts()->getType();
+  if (!OType->isIntegerType())
+return false;
 
-  llvm::Optional ValueType; // Which limit (min/max) is the 
constant?

[PATCH] D39284: Allow conditions to be decomposed with structured bindings

2017-12-06 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray added a comment.

Can someone commit this please?  One more patch then I'll go get a commit bit.


Repository:
  rC Clang

https://reviews.llvm.org/D39284



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


[PATCH] D40864: [Darwin] Add a new -mstack-probe option and enable by default

2017-12-06 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: lib/CodeGen/BackendUtil.cpp:442
   Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
+  Options.EnableStackProbe = CodeGenOpts.StackProbe;
 

aemerson wrote:
> ahatanak wrote:
> > Is there a reason you can't use function attributes 
> > "probe-stack"="___chkstk_darwin" and "stack-probe-size"=4096 instead of 
> > setting a TargetOptions flag here? If you intend to use stack probing with 
> > LTO, I think you need function attributes. Also, it looks like that would 
> > simplify the changes made to X86 backend.
> I don't think there's any reason not to. Is it worth specifying the probe 
> size itself given that it'll be a known fixed value? It could be misleading 
> to give a probe size which only has a single valid value for Darwin.
If 4096B is the only valid size for Darwin and the default size is 4096B in the 
backend, you can just add attribute "probe-stack"="___chkstk_darwin" to the 
function.  The backend can check the existence of the attribute and decide 
whether to enable stack-probing.


Repository:
  rC Clang

https://reviews.llvm.org/D40864



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


[PATCH] D40562: [Sema] Ignore decls in namespaces when global decls are not wanted.

2017-12-06 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 125777.
ioeric added a comment.

- Add a new code-completion option IncludeNamespaceLevelDecls. For now, I only 
restrict this option work for qualified id completion to reduce the impact.


Repository:
  rC Clang

https://reviews.llvm.org/D40562

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Sema/CodeCompleteConsumer.h
  include/clang/Sema/CodeCompleteOptions.h
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaCodeComplete.cpp
  test/CodeCompletion/ignore-ns-level-decls.cpp

Index: test/CodeCompletion/ignore-ns-level-decls.cpp
===
--- /dev/null
+++ test/CodeCompletion/ignore-ns-level-decls.cpp
@@ -0,0 +1,21 @@
+namespace ns {
+  struct bar {
+  };
+
+  struct baz {
+  };
+
+  int func(int a, bar b, baz c);
+}
+
+void test() {
+  ns::
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:12:7 %s -o - | FileCheck %s --check-prefix=CHECK-1
+// CHECK-1-DAG: COMPLETION: bar : bar
+// CHECK-1-DAG: COMPLETION: baz : baz
+// CHECK-1-DAG: COMPLETION: func : [#int#]func(<#int a#>, <#bar b#>, <#baz c#>)
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:12:7 -no-code-completion-ns-level-decls %s -o - | FileCheck %s --check-prefix=CHECK-EMPTY
+// CHECK-EMPTY-NOT: COMPLETION: bar : bar
+// CHECK-EMPTY: {{^}}{{$}}
+}
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -4635,16 +4635,18 @@
   // qualified-id completions.
   if (!EnteringContext)
 MaybeAddOverrideCalls(*this, Ctx, Results);
-  Results.ExitScope();  
-  
-  CodeCompletionDeclConsumer Consumer(Results, CurContext);
-  LookupVisibleDecls(Ctx, LookupOrdinaryName, Consumer,
- /*IncludeGlobalScope=*/true,
- /*IncludeDependentBases=*/true);
+  Results.ExitScope();
 
-  HandleCodeCompleteResults(this, CodeCompleter, 
-Results.getCompletionContext(),
-Results.data(),Results.size());
+  if (CodeCompleter->includeNamespaceLevelDecls() ||
+  (!Ctx->isNamespace() && !Ctx->isTranslationUnit())) {
+CodeCompletionDeclConsumer Consumer(Results, CurContext);
+LookupVisibleDecls(Ctx, LookupOrdinaryName, Consumer,
+   /*IncludeGlobalScope=*/true,
+   /*IncludeDependentBases=*/true);
+  }
+
+  HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
+Results.data(), Results.size());
 }
 
 void Sema::CodeCompleteUsing(Scope *S) {
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1378,6 +1378,8 @@
 = Args.hasArg(OPT_code_completion_patterns);
   Opts.CodeCompleteOpts.IncludeGlobals
 = !Args.hasArg(OPT_no_code_completion_globals);
+  Opts.CodeCompleteOpts.IncludeNamespaceLevelDecls
+= !Args.hasArg(OPT_no_code_completion_ns_level_decls);
   Opts.CodeCompleteOpts.IncludeBriefComments
 = Args.hasArg(OPT_code_completion_brief_comments);
 
Index: include/clang/Sema/CodeCompleteOptions.h
===
--- include/clang/Sema/CodeCompleteOptions.h
+++ include/clang/Sema/CodeCompleteOptions.h
@@ -24,15 +24,20 @@
   /// Show top-level decls in code completion results.
   unsigned IncludeGlobals : 1;
 
+  /// Show decls in namespace (including the global namespace) in code
+  /// completion results. If this is 0, `IncludeGlobals` will be ignored.
+  ///
+  /// Currently, this only works when completing qualified IDs (i.e.
+  /// `Sema::CodeCompleteQualifiedId`).
+  /// FIXME: consider supporting more completion cases with this option.
+  unsigned IncludeNamespaceLevelDecls : 1;
+
   /// Show brief documentation comments in code completion results.
   unsigned IncludeBriefComments : 1;
 
-  CodeCompleteOptions() :
-  IncludeMacros(0),
-  IncludeCodePatterns(0),
-  IncludeGlobals(1),
-  IncludeBriefComments(0)
-  { }
+  CodeCompleteOptions()
+  : IncludeMacros(0), IncludeCodePatterns(0), IncludeGlobals(1),
+IncludeNamespaceLevelDecls(1), IncludeBriefComments(0) {}
 };
 
 } // namespace clang
Index: include/clang/Sema/CodeCompleteConsumer.h
===
--- include/clang/Sema/CodeCompleteConsumer.h
+++ include/clang/Sema/CodeCompleteConsumer.h
@@ -902,8 +902,13 @@
   }
 
   /// \brief Whether to include global (top-level) declaration results.
-  bool includeGlobals() const {
-return CodeCompleteOpts.IncludeGlobals;
+  bool includeGlobals() const { return CodeCompleteOpts.IncludeGlobals; }
+
+  /// \brief Whether to include declarations in namespace contexts (including
+  /// the global namespace). If this is false, `includeGlobals()` will be
+  /// 

[PATCH] D40562: [Sema] Ignore decls in namespaces when global decls are not wanted.

2017-12-06 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

In https://reviews.llvm.org/D40562#942521, @arphaman wrote:

> In https://reviews.llvm.org/D40562#941753, @ilya-biryukov wrote:
>
> > In https://reviews.llvm.org/D40562#941570, @arphaman wrote:
> >
> > > I'm not actually 100% sure, but I would imagine that this one of the 
> > > reasons, yes. It would be nice to improve the cache to have things like 
> > > namespace-level `Decl`, although how will lookup work in that case? Btw, 
> > > do you think the cache can be reused in clangd as well?
> >
> >
> > As Eric mentioned, we are planning to have project-global completion for 
> > namespace-level Decls (to have completion items not #included in the 
> > current file and add the #include directive properly).  So the cache is 
> > probably not that useful to clangd long-term.
>
>
> Interesting, thanks! Will this be something that clients of clangd can 
> opt-out from? Or at least configure certain aspects of the behaviour?


Absolutely!


Repository:
  rC Clang

https://reviews.llvm.org/D40562



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


[clang-tools-extra] r319948 - [CMake] Use PRIVATE in target_link_libraries for fuzzers.

2017-12-06 Thread Matt Morehouse via cfe-commits
Author: morehouse
Date: Wed Dec  6 11:52:40 2017
New Revision: 319948

URL: http://llvm.org/viewvc/llvm-project?rev=319948&view=rev
Log:
[CMake] Use PRIVATE in target_link_libraries for fuzzers.

Several fuzzers were missed by r319840.

Modified:
clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt

Modified: clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt?rev=319948&r1=319947&r2=319948&view=diff
==
--- clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt Wed Dec  6 11:52:40 
2017
@@ -12,6 +12,7 @@ add_clang_executable(clangd-fuzzer
   )
 
 target_link_libraries(clangd-fuzzer
+  PRIVATE
   clangBasic
   clangDaemon
   clangFormat


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


r319948 - [CMake] Use PRIVATE in target_link_libraries for fuzzers.

2017-12-06 Thread Matt Morehouse via cfe-commits
Author: morehouse
Date: Wed Dec  6 11:52:40 2017
New Revision: 319948

URL: http://llvm.org/viewvc/llvm-project?rev=319948&view=rev
Log:
[CMake] Use PRIVATE in target_link_libraries for fuzzers.

Several fuzzers were missed by r319840.

Modified:
cfe/trunk/tools/clang-format/fuzzer/CMakeLists.txt
cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt

Modified: cfe/trunk/tools/clang-format/fuzzer/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/fuzzer/CMakeLists.txt?rev=319948&r1=319947&r2=319948&view=diff
==
--- cfe/trunk/tools/clang-format/fuzzer/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-format/fuzzer/CMakeLists.txt Wed Dec  6 11:52:40 2017
@@ -10,6 +10,7 @@ add_clang_executable(clang-format-fuzzer
   )
 
 target_link_libraries(clang-format-fuzzer
+  PRIVATE
   ${CLANG_FORMAT_LIB_DEPS}
   ${LLVM_LIB_FUZZING_ENGINE}
   )

Modified: cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/CMakeLists.txt?rev=319948&r1=319947&r2=319948&view=diff
==
--- cfe/trunk/tools/clang-fuzzer/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-fuzzer/CMakeLists.txt Wed Dec  6 11:52:40 2017
@@ -48,6 +48,7 @@ if(CLANG_ENABLE_PROTO_FUZZER)
 )
 
   target_link_libraries(clang-proto-fuzzer
+PRIVATE
 ${ProtobufMutator_LIBRARIES}
 ${PROTOBUF_LIBRARIES}
 ${LLVM_LIB_FUZZING_ENGINE}

Modified: cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt?rev=319948&r1=319947&r2=319948&view=diff
==
--- cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt Wed Dec  6 
11:52:40 2017
@@ -11,4 +11,4 @@ add_clang_library(clangProtoToCXX proto_
   )
 
 add_clang_executable(clang-proto-to-cxx proto_to_cxx_main.cpp)
-target_link_libraries(clang-proto-to-cxx clangProtoToCXX)
+target_link_libraries(clang-proto-to-cxx PRIVATE clangProtoToCXX)


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


[PATCH] D40567: Always show template parameters in IR type names

2017-12-06 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D40567#943747, @sepavloff wrote:

> Although code generation (in LTO compilation) might be unaffected by this 
> distortions, other applications of IR linking suffer from it. It does not 
> allow to implement some checks, validation techniques and optimizations.


Any system trying to use IR type names to deduce information about source-level 
types is simply wrong. We simply don't provide the sort of guarantees you seem 
to be looking for here. We don't even guarantee to consistently use the same IR 
type for the same source type within a single translation unit. IR type names 
exist only for the benefit of humans reading the IR.


Repository:
  rC Clang

https://reviews.llvm.org/D40567



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


[PATCH] D40819: Implement Attribute Target MultiVersioning (Improved edition!)

2017-12-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked 14 inline comments as done.
erichkeane added a comment.

Incoming patch!




Comment at: include/clang/Basic/Attr.td:1809
   bool DuplicateArchitecture = false;
+  bool operator ==(const ParsedTargetAttr &Other) {
+return DuplicateArchitecture == Other.DuplicateArchitecture &&

rsmith wrote:
> Our normal convention is to not put a space before `==` here.
Clang format seems to keep adding it interestingly enough.  Perhaps because it 
is a .td file?  Will remove.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:9317-9318
+def err_target_required_in_redecl :
+  Error<"function declaration is missing 'target' attribute in a "
+"multiversioned function">;
+def note_multiversioning_caused_here :

rsmith wrote:
> There's some weird indentation hereabouts. Our normal convention is to put 
> the `Error<` on the `def` line, and start the diagnostic text as a 
> 2-space-indented string literal on the next line.
Thanks!  Clang-format really makes a mess of these too...



Comment at: lib/CodeGen/CodeGenModule.cpp:2144
+if (getContext().hasSameType(CurFD->getType(), FD->getType())) {
+  StringRef MangledName = getMangledName(CurFD);
+  llvm::Constant *Func = GetGlobalValue(MangledName);

rsmith wrote:
> You should skip functions you've already seen somewhere around here; we don't 
> need to handle the same function multiple times.
Will the lookup call give me duplicates?  I need to check each at least once 
through this so that I can put them into "Options" so that I can emit them 
during the resolver.  

Otherwise, I'm not terribly sure what you mean.



Comment at: lib/Sema/SemaDecl.cpp:9326-9328
+static bool CheckMultiVersionAdditionalRules(Sema &S, const FunctionDecl 
*OldFD,
+ const FunctionDecl *NewFD,
+ bool CausesMV) {

rsmith wrote:
> rsmith wrote:
> > Would it be possible to factor out the checks in `MergeFunctionDecl` that 
> > you're using here and reuse them directly?
> Maybe also check that the language linkage matches (`extern "C"` and `extern 
> "C++"` could imply different calling conventions, even though they don't on 
> any of our current targets).
I'd thought about that, but I'm being WAAY more strict, so I didn't see a good 
way to factor them out without making things pretty complicated.  Suggestions 
welcome :)



Comment at: lib/Sema/SemaDecl.cpp:9383-9384
+
+QualType OldReturnType = OldType->getReturnType();
+QualType NewReturnType = NewType->getReturnType();
+if (OldReturnType != NewReturnType) {

rsmith wrote:
> This won't do the right thing for C++14 deduced return types. I'm not 
> completely sure what the right thing is, though -- clearly we need to deduce 
> the same return type in all versions of the function, but it's less clear 
> whether we should also require the return-type-as-written to match across 
> versions (as is required across redeclarations). Example:
> 
> ```
> VERSION_FOO auto f() { return 0; } // declared return type is `auto`, actual 
> return type is `int`
> VERSION_BAR auto f(); // will fail the current check, because the return type 
> `auto` doesn't match the prior return type `int`
> VERSION_BAR auto f() { return 0.0; } // should reject this because we deduced 
> a different return type than on the VERSION_FOO version?
> ```
> 
> Perhaps the simplest thing would be to simply disallow deduced return types 
> for multiversioned functions entirely for now?
I think disallowing 'auto' return for now is a good idea. This next patch is 
using isUndeducedType, which I think is sufficient, but if there is a better 
function I'm missing, please let me know.


https://reviews.llvm.org/D40819



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


r319950 - [clang] Use PRIVATE in target_link_libraries

2017-12-06 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Wed Dec  6 12:05:42 2017
New Revision: 319950

URL: http://llvm.org/viewvc/llvm-project?rev=319950&view=rev
Log:
[clang] Use PRIVATE in target_link_libraries

I'd missed this one in r319840 because I hadn't been configuring with an
order file before.

Modified:
cfe/trunk/tools/driver/CMakeLists.txt

Modified: cfe/trunk/tools/driver/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/CMakeLists.txt?rev=319950&r1=319949&r2=319950&view=diff
==
--- cfe/trunk/tools/driver/CMakeLists.txt (original)
+++ cfe/trunk/tools/driver/CMakeLists.txt Wed Dec  6 12:05:42 2017
@@ -123,7 +123,7 @@ if(CLANG_ORDER_FILE AND (LD64_EXECUTABLE
   if("${ORDER_FILE}" STREQUAL "\n")
 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS 
${CLANG_ORDER_FILE})
   elseif(LINKER_ORDER_FILE_WORKS)
-target_link_libraries(clang ${LINKER_ORDER_FILE_OPTION})
+target_link_libraries(clang PRIVATE ${LINKER_ORDER_FILE_OPTION})
 set_target_properties(clang PROPERTIES LINK_DEPENDS ${CLANG_ORDER_FILE})
   endif()
 endif()


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


[PATCH] D40819: Implement Attribute Target MultiVersioning (Improved edition!)

2017-12-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 125779.
erichkeane marked 3 inline comments as done.
erichkeane added a comment.

Fix all rsmith's and craig's fixes, AFAIK.


https://reviews.llvm.org/D40819

Files:
  include/clang/AST/Decl.h
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/X86Target.def
  include/clang/Sema/Overload.h
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaOverload.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGen/attr-target-mv-func-ptrs.c
  test/CodeGen/attr-target-mv-va-args.c
  test/CodeGen/attr-target-mv.c
  test/CodeGenCXX/attr-target-mv-constexpr.cpp
  test/CodeGenCXX/attr-target-mv-diff-ns.cpp
  test/CodeGenCXX/attr-target-mv-func-ptrs.cpp
  test/CodeGenCXX/attr-target-mv-member-funcs.cpp
  test/CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  test/CodeGenCXX/attr-target-mv-overloads.cpp
  test/Sema/attr-target-mv.c
  test/SemaCXX/attr-target-mv.cpp

Index: test/SemaCXX/attr-target-mv.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-target-mv.cpp
@@ -0,0 +1,131 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++14
+void __attribute__((target("sse4.2"))) no_default(void);
+void __attribute__((target("arch=sandybridge")))  no_default(void);
+
+void use1(void){
+  // expected-note@-4 {{candidate ignored: non-default multiversion function cannot be called directly}}
+  // expected-note@-4 {{candidate ignored: non-default multiversion function cannot be called directly}}
+  // expected-error@+1 {{no matching function for call to 'no_default'}}
+  no_default();
+}
+constexpr int __attribute__((target("sse4.2"))) foo(void) { return 0; }
+constexpr int __attribute__((target("arch=sandybridge"))) foo(void);
+//expected-error@+1 {{multiversion function declaration has a different constexpr specification}}
+int __attribute__((target("arch=ivybridge"))) foo(void) {return 1;}
+constexpr int __attribute__((target("default"))) foo(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) foo2(void) { return 0; }
+//expected-error@+2 {{multiversion function declaration has a different constexpr specification}}
+//expected-note@+1 {{function multiversion caused by this declaration}}
+constexpr int __attribute__((target("arch=sandybridge"))) foo2(void);
+int __attribute__((target("arch=ivybridge"))) foo2(void) {return 1;}
+int __attribute__((target("default"))) foo2(void) { return 2; }
+
+static int __attribute__((target("sse4.2"))) bar(void) { return 0; }
+static int __attribute__((target("arch=sandybridge"))) bar(void);
+//expected-error@+1 {{multiversion function declaration has a different storage class}}
+int __attribute__((target("arch=ivybridge"))) bar(void) {return 1;}
+static int __attribute__((target("default"))) bar(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) bar2(void) { return 0; }
+//expected-error@+2 {{multiversion function declaration has a different storage class}}
+//expected-note@+1 {{function multiversion caused by this declaration}}
+static int __attribute__((target("arch=sandybridge"))) bar2(void);
+int __attribute__((target("arch=ivybridge"))) bar2(void) {return 1;}
+int __attribute__((target("default"))) bar2(void) { return 2; }
+
+
+inline int __attribute__((target("sse4.2"))) baz(void) { return 0; }
+inline int __attribute__((target("arch=sandybridge"))) baz(void);
+//expected-error@+1 {{multiversion function declaration has a different inline specification}}
+int __attribute__((target("arch=ivybridge"))) baz(void) {return 1;}
+inline int __attribute__((target("default"))) baz(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) baz2(void) { return 0; }
+//expected-error@+2 {{multiversion function declaration has a different inline specification}}
+//expected-note@+1 {{function multiversion caused by this declaration}}
+inline int __attribute__((target("arch=sandybridge"))) baz2(void);
+int __attribute__((target("arch=ivybridge"))) baz2(void) {return 1;}
+int __attribute__((target("default"))) baz2(void) { return 2; }
+
+float __attribute__((target("sse4.2"))) bock(void) { return 0; }
+//expected-error@+2 {{multiversion function declaration has a different return type}}
+//expected-note@+1 {{function multiversion caused by this declaration}}
+int __attribute__((target("arch=sandybridge"))) bock(void);
+//expected-error@+2 {{multiversion function declaration has a different return type}}
+//expected-note@+1 {{function multiversion caused by this declaration}}
+int __attribute__((target("arch=ivybridge"))) bock(void) {return 1;}
+//expected-error@+2 {{multiversion function declaration has a different retur

Re: r319875 - Fix a bunch of wrong "tautological unsigned enum compare" diagnostics in C++.

2017-12-06 Thread Galina Kistanova via cfe-commits
Hello Richard,

This commit broke the tests on the builder:

http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/6598

. . .
Failing Tests (1):
Clang :: SemaCXX/warn-enum-compare.cpp

Please have a look?

Thanks

Galina

On Tue, Dec 5, 2017 at 7:00 PM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Tue Dec  5 19:00:51 2017
> New Revision: 319875
>
> URL: http://llvm.org/viewvc/llvm-project?rev=319875&view=rev
> Log:
> Fix a bunch of wrong "tautological unsigned enum compare" diagnostics in
> C++.
>
> An enumeration with a fixed underlying type can have any value in its
> underlying type, not just those spanned by the values of its enumerators.
>
> Modified:
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaChecking.cpp?rev=319875&r1=319874&r2=319875&view=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Dec  5 19:00:51 2017
> @@ -8260,11 +8260,12 @@ struct IntRange {
>  } else if (const EnumType *ET = dyn_cast(T)) {
>// For enum types in C++, use the known bit width of the
> enumerators.
>EnumDecl *Enum = ET->getDecl();
> -  // In C++11, enums without definitions can have an explicitly
> specified
> -  // underlying type.  Use this type to compute the range.
> -  if (!Enum->isCompleteDefinition())
> +  // In C++11, enums can have a fixed underlying type. Use this type
> to
> +  // compute the range.
> +  if (Enum->isFixed()) {
>  return IntRange(C.getIntWidth(QualType(T, 0)),
>  !ET->isSignedIntegerOrEnumerationType());
> +  }
>
>unsigned NumPositive = Enum->getNumPositiveBits();
>unsigned NumNegative = Enum->getNumNegativeBits();
>
> Modified: cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/
> tautological-unsigned-enum-zero-compare.cpp?rev=319875&
> r1=319874&r2=319875&view=diff
> 
> ==
> --- cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp
> (original)
> +++ cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp Tue
> Dec  5 19:00:51 2017
> @@ -2,11 +2,11 @@
>  // RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only
> -DSIGNED -verify %s
>  // RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only
> -DSILENCE -Wno-tautological-unsigned-enum-zero-compare -verify %s
>
> -// Okay, this is where it gets complicated.
> -// Then default enum sigdness is target-specific.
> -// On windows, it is signed by default. We do not want to warn in that
> case.
> -
>  int main() {
> +  // On Windows, all enumerations have a fixed underlying type, which is
> 'int'
> +  // if not otherwise specified, so A is identical to C on Windows.
> Otherwise,
> +  // we follow the C++ rules, which say that the only valid values of A
> are 0
> +  // and 1.
>enum A { A_foo = 0, A_bar, };
>enum A a;
>
> @@ -87,21 +87,23 @@ int main() {
>
>if (c < 0)
>  return 0;
> -  if (0 >= c) // expected-warning {{comparison 0 >= 'enum C' is always
> true}}
> +  if (0 >= c)
>  return 0;
> -  if (c > 0) // expected-warning {{comparison 'enum C' > 0 is always
> false}}
> +  if (c > 0)
>  return 0;
>if (0 <= c)
>  return 0;
> -  if (c <= 0) // expected-warning {{comparison 'enum C' <= 0 is always
> true}}
> +  if (c <= 0)
>  return 0;
>if (0 > c)
>  return 0;
>if (c >= 0)
>  return 0;
> -  if (0 < c) // expected-warning {{0 < 'enum C' is always false}}
> +  if (0 < c)
>  return 0;
>
> +  // FIXME: These diagnostics are terrible. The issue here is that the
> signed
> +  // enumeration value was promoted to an unsigned type.
>if (c < 0U) // expected-warning {{comparison of unsigned enum
> expression < 0 is always false}}
>  return 0;
>if (0U >= c)
> @@ -121,21 +123,23 @@ int main() {
>  #elif defined(SIGNED)
>if (a < 0)
>  return 0;
> -  if (0 >= a) // expected-warning {{comparison 0 >= 'enum A' is always
> true}}
> +  if (0 >= a)
>  return 0;
> -  if (a > 0) // expected-warning {{comparison 'enum A' > 0 is always
> false}}
> +  if (a > 0)
>  return 0;
>if (0 <= a)
>  return 0;
> -  if (a <= 0) // expected-warning {{comparison 'enum A' <= 0 is always
> true}}
> +  if (a <= 0)
>  return 0;
>if (0 > a)
>  return 0;
>if (a >= 0)
>  return 0;
> -  if (0 < a) // expected-warning {{comparison 0 < 'enum A' is always
> false}}
> +  if (0 < a)
>  return 0;
>
> +  // FIXME: As above, the issue here is that the enumeration is promoted
> to
> +  // unsigned.
>if (a < 0

[PATCH] D40548: [clangd] Prototyping index support and naive index-based global code completion. WIP

2017-12-06 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Hi Marc, the patch is not ready for review yet. I am still cleaning up the 
prototype and will let you know when it's ready for review.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40548



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


[libcxx] r319959 - [libc++] Create install-stripped targets

2017-12-06 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Wed Dec  6 13:03:42 2017
New Revision: 319959

URL: http://llvm.org/viewvc/llvm-project?rev=319959&view=rev
Log:
[libc++] Create install-stripped targets

LLVM is gaining install-*-stripped targets to perform stripped installs,
and in order for this to be useful for install-distribution, all
potential distribution components should have stripped installation
targets. LLVM has a function to create these install targets, but since
we can't use LLVM CMake functions in libc++, let's do it manually.

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

Modified:
libcxx/trunk/include/CMakeLists.txt
libcxx/trunk/lib/CMakeLists.txt

Modified: libcxx/trunk/include/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/CMakeLists.txt?rev=319959&r1=319958&r2=319959&view=diff
==
--- libcxx/trunk/include/CMakeLists.txt (original)
+++ libcxx/trunk/include/CMakeLists.txt Wed Dec  6 13:03:42 2017
@@ -58,6 +58,8 @@ if (LIBCXX_INSTALL_HEADERS)
   COMMAND "${CMAKE_COMMAND}"
   -DCMAKE_INSTALL_COMPONENT=cxx-headers
   -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
+# Stripping is a no-op for headers
+add_custom_target(install-cxx-headers-stripped DEPENDS install-cxx-headers)
 
 add_custom_target(libcxx-headers)
 add_custom_target(install-libcxx-headers DEPENDS install-cxx-headers)

Modified: libcxx/trunk/lib/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/CMakeLists.txt?rev=319959&r1=319958&r2=319959&view=diff
==
--- libcxx/trunk/lib/CMakeLists.txt (original)
+++ libcxx/trunk/lib/CMakeLists.txt Wed Dec  6 13:03:42 2017
@@ -389,5 +389,13 @@ if (NOT CMAKE_CONFIGURATION_TYPES AND (L
   COMMAND "${CMAKE_COMMAND}"
   -DCMAKE_INSTALL_COMPONENT=cxx
   -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
+add_custom_target(install-cxx-stripped
+  DEPENDS ${lib_install_target}
+  ${experimental_lib_install_target}
+  ${header_install_target}
+  COMMAND "${CMAKE_COMMAND}"
+  -DCMAKE_INSTALL_COMPONENT=cxx
+  -DCMAKE_INSTALL_DO_STRIP=1
+  -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
 add_custom_target(install-libcxx DEPENDS install-cxx)
 endif()


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


[PATCH] D40680: [libc++] Create install-stripped targets

2017-12-06 Thread Shoaib Meenai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319959: [libc++] Create install-stripped targets (authored 
by smeenai).

Repository:
  rL LLVM

https://reviews.llvm.org/D40680

Files:
  libcxx/trunk/include/CMakeLists.txt
  libcxx/trunk/lib/CMakeLists.txt


Index: libcxx/trunk/include/CMakeLists.txt
===
--- libcxx/trunk/include/CMakeLists.txt
+++ libcxx/trunk/include/CMakeLists.txt
@@ -58,6 +58,8 @@
   COMMAND "${CMAKE_COMMAND}"
   -DCMAKE_INSTALL_COMPONENT=cxx-headers
   -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
+# Stripping is a no-op for headers
+add_custom_target(install-cxx-headers-stripped DEPENDS install-cxx-headers)
 
 add_custom_target(libcxx-headers)
 add_custom_target(install-libcxx-headers DEPENDS install-cxx-headers)
Index: libcxx/trunk/lib/CMakeLists.txt
===
--- libcxx/trunk/lib/CMakeLists.txt
+++ libcxx/trunk/lib/CMakeLists.txt
@@ -389,5 +389,13 @@
   COMMAND "${CMAKE_COMMAND}"
   -DCMAKE_INSTALL_COMPONENT=cxx
   -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
+add_custom_target(install-cxx-stripped
+  DEPENDS ${lib_install_target}
+  ${experimental_lib_install_target}
+  ${header_install_target}
+  COMMAND "${CMAKE_COMMAND}"
+  -DCMAKE_INSTALL_COMPONENT=cxx
+  -DCMAKE_INSTALL_DO_STRIP=1
+  -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
 add_custom_target(install-libcxx DEPENDS install-cxx)
 endif()


Index: libcxx/trunk/include/CMakeLists.txt
===
--- libcxx/trunk/include/CMakeLists.txt
+++ libcxx/trunk/include/CMakeLists.txt
@@ -58,6 +58,8 @@
   COMMAND "${CMAKE_COMMAND}"
   -DCMAKE_INSTALL_COMPONENT=cxx-headers
   -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
+# Stripping is a no-op for headers
+add_custom_target(install-cxx-headers-stripped DEPENDS install-cxx-headers)
 
 add_custom_target(libcxx-headers)
 add_custom_target(install-libcxx-headers DEPENDS install-cxx-headers)
Index: libcxx/trunk/lib/CMakeLists.txt
===
--- libcxx/trunk/lib/CMakeLists.txt
+++ libcxx/trunk/lib/CMakeLists.txt
@@ -389,5 +389,13 @@
   COMMAND "${CMAKE_COMMAND}"
   -DCMAKE_INSTALL_COMPONENT=cxx
   -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
+add_custom_target(install-cxx-stripped
+  DEPENDS ${lib_install_target}
+  ${experimental_lib_install_target}
+  ${header_install_target}
+  COMMAND "${CMAKE_COMMAND}"
+  -DCMAKE_INSTALL_COMPONENT=cxx
+  -DCMAKE_INSTALL_DO_STRIP=1
+  -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
 add_custom_target(install-libcxx DEPENDS install-cxx)
 endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38639: [clangd] #include statements support for Open definition

2017-12-06 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 125813.
Nebiroth added a comment.
Herald added a subscriber: klimek.

Using PPCallbacks interface to find non-preamble includes
Created inner class to store vectors in to find locations
Refactored methods to remove some unnecessary parameters
Refactored Unit tests
Merge with most recent master branch + clang


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D38639

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/GlobalCompilationDatabase.cpp
  clangd/Protocol.h
  unittests/clangd/ClangdTests.cpp

Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-#include "ClangdLSPServer.h"
 #include "ClangdServer.h"
 #include "Logger.h"
 #include "TestFS.h"
@@ -620,7 +619,7 @@
 AddDocument(FileIndex);
 
   Position Pos{LineDist(RandGen), ColumnDist(RandGen)};
-  ASSERT_TRUE(!!Server.findDefinitions(FilePaths[FileIndex], Pos));
+  Server.findDefinitions(FilePaths[FileIndex], Pos);
 };
 
 std::vector> AsyncRequests = {
@@ -749,6 +748,58 @@
   EXPECT_FALSE(PathResult.hasValue());
 }
 
+TEST_F(ClangdVFSTest, CheckDefinitionIncludes) {
+  MockFSProvider FS;
+  ErrorCheckingDiagConsumer DiagConsumer;
+  MockCompilationDatabase CDB;
+
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true,
+  EmptyLogger::getInstance());
+
+  auto FooCpp = getVirtualTestFilePath("foo.cpp");
+  const auto SourceContents = R"cpp(
+  #include "foo.h"
+  #include "invalid.h"
+  int b = a;
+  )cpp";
+  FS.Files[FooCpp] = SourceContents;
+  auto FooH = getVirtualTestFilePath("foo.h");
+  const auto HeaderContents = "int a;";
+
+  FS.Files[FooCpp] = SourceContents;
+  FS.Files[FooH] = HeaderContents;
+
+  Server.addDocument(FooH, HeaderContents);
+  Server.addDocument(FooCpp, SourceContents);
+
+  Position P = Position{1, 11};
+
+  std::vector Locations = Server.findDefinitions(FooCpp, P).get().Value;
+  EXPECT_TRUE(!Locations.empty());
+  std::string s("file:///");
+  std::string check = Locations[0].uri.uri;
+  check = check.erase(0, s.size());
+  check = check.substr(0, check.size() - 1);
+  ASSERT_EQ(check, FooH);
+  ASSERT_EQ(Locations[0].range.start.line, 0);
+  ASSERT_EQ(Locations[0].range.start.character, 0);
+  ASSERT_EQ(Locations[0].range.end.line, 0);
+  ASSERT_EQ(Locations[0].range.end.character, 0);
+
+  // Test ctrl-clicking on the #include part on the statement
+  Position P3 = Position{1, 3};
+
+  Locations = Server.findDefinitions(FooCpp, P3).get().Value;
+  EXPECT_TRUE(!Locations.empty());
+
+  // Test invalid include
+  Position P2 = Position{2, 11};
+
+  Locations = Server.findDefinitions(FooCpp, P2).get().Value;
+  EXPECT_TRUE(Locations.empty());
+}
+
 TEST_F(ClangdThreadingTest, NoConcurrentDiagnostics) {
   class NoConcurrentAccessDiagConsumer : public DiagnosticsConsumer {
   public:
Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -108,6 +108,14 @@
 bool fromJSON(const json::Expr &, Range &);
 json::Expr toJSON(const Range &);
 
+class RangeHash {
+public:
+  std::size_t operator()(const Range &R) const {
+return ((R.start.line & 0x18) << 3) | ((R.start.character & 0x18) << 1) |
+   ((R.end.line & 0x18) >> 1) | ((R.end.character & 0x18) >> 3);
+  }
+};
+
 struct Location {
   /// The text document's URI.
   URI uri;
Index: clangd/GlobalCompilationDatabase.cpp
===
--- clangd/GlobalCompilationDatabase.cpp
+++ clangd/GlobalCompilationDatabase.cpp
@@ -9,6 +9,7 @@
 
 #include "GlobalCompilationDatabase.h"
 #include "Logger.h"
+#include "ProtocolHandlers.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
Index: clangd/ClangdUnit.h
===
--- clangd/ClangdUnit.h
+++ clangd/ClangdUnit.h
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace llvm {
 class raw_ostream;
@@ -59,6 +60,15 @@
   std::vector Diags;
 };
 
+class IncludeReferenceMap {
+  llvm::Optional findIncludeTargetAtLoc(Location Loc);
+
+public:
+  std::unordered_map IncludeLocationMap;
+  std::vector> DataVector;
+  std::vector RangeVector;
+};
+
 /// Stores and provides access to parsed AST.
 class ParsedAST {
 public:
@@ -69,7 +79,8 @@
 std::shared_ptr Preamble,
 std::unique_ptr Buffer,
 std::shared_ptr PCHs,
-IntrusiveRefCntPtr VFS, clangd::Logger &Logger);
+IntrusiveRefCntPtr VFS, clangd::Logger &Logger,
+IncludeReferenceMap IRM);
 
   ParsedAST(ParsedAST &&Other);
   ParsedAST &operator=(Parse

[PATCH] D40398: Remove ValueDependent assertions on ICE checks.

2017-12-06 Thread Matt Davis via Phabricator via cfe-commits
mattd added a comment.

ping


https://reviews.llvm.org/D40398



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


[PATCH] D38639: [clangd] #include statements support for Open definition

2017-12-06 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 125814.
Nebiroth added a comment.

Fixed re-added include


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D38639

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/Protocol.h
  unittests/clangd/ClangdTests.cpp

Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-#include "ClangdLSPServer.h"
 #include "ClangdServer.h"
 #include "Logger.h"
 #include "TestFS.h"
@@ -620,7 +619,7 @@
 AddDocument(FileIndex);
 
   Position Pos{LineDist(RandGen), ColumnDist(RandGen)};
-  ASSERT_TRUE(!!Server.findDefinitions(FilePaths[FileIndex], Pos));
+  Server.findDefinitions(FilePaths[FileIndex], Pos);
 };
 
 std::vector> AsyncRequests = {
@@ -749,6 +748,58 @@
   EXPECT_FALSE(PathResult.hasValue());
 }
 
+TEST_F(ClangdVFSTest, CheckDefinitionIncludes) {
+  MockFSProvider FS;
+  ErrorCheckingDiagConsumer DiagConsumer;
+  MockCompilationDatabase CDB;
+
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true,
+  EmptyLogger::getInstance());
+
+  auto FooCpp = getVirtualTestFilePath("foo.cpp");
+  const auto SourceContents = R"cpp(
+  #include "foo.h"
+  #include "invalid.h"
+  int b = a;
+  )cpp";
+  FS.Files[FooCpp] = SourceContents;
+  auto FooH = getVirtualTestFilePath("foo.h");
+  const auto HeaderContents = "int a;";
+
+  FS.Files[FooCpp] = SourceContents;
+  FS.Files[FooH] = HeaderContents;
+
+  Server.addDocument(FooH, HeaderContents);
+  Server.addDocument(FooCpp, SourceContents);
+
+  Position P = Position{1, 11};
+
+  std::vector Locations = Server.findDefinitions(FooCpp, P).get().Value;
+  EXPECT_TRUE(!Locations.empty());
+  std::string s("file:///");
+  std::string check = Locations[0].uri.uri;
+  check = check.erase(0, s.size());
+  check = check.substr(0, check.size() - 1);
+  ASSERT_EQ(check, FooH);
+  ASSERT_EQ(Locations[0].range.start.line, 0);
+  ASSERT_EQ(Locations[0].range.start.character, 0);
+  ASSERT_EQ(Locations[0].range.end.line, 0);
+  ASSERT_EQ(Locations[0].range.end.character, 0);
+
+  // Test ctrl-clicking on the #include part on the statement
+  Position P3 = Position{1, 3};
+
+  Locations = Server.findDefinitions(FooCpp, P3).get().Value;
+  EXPECT_TRUE(!Locations.empty());
+
+  // Test invalid include
+  Position P2 = Position{2, 11};
+
+  Locations = Server.findDefinitions(FooCpp, P2).get().Value;
+  EXPECT_TRUE(Locations.empty());
+}
+
 TEST_F(ClangdThreadingTest, NoConcurrentDiagnostics) {
   class NoConcurrentAccessDiagConsumer : public DiagnosticsConsumer {
   public:
Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -108,6 +108,14 @@
 bool fromJSON(const json::Expr &, Range &);
 json::Expr toJSON(const Range &);
 
+class RangeHash {
+public:
+  std::size_t operator()(const Range &R) const {
+return ((R.start.line & 0x18) << 3) | ((R.start.character & 0x18) << 1) |
+   ((R.end.line & 0x18) >> 1) | ((R.end.character & 0x18) >> 3);
+  }
+};
+
 struct Location {
   /// The text document's URI.
   URI uri;
Index: clangd/ClangdUnit.h
===
--- clangd/ClangdUnit.h
+++ clangd/ClangdUnit.h
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace llvm {
 class raw_ostream;
@@ -59,6 +60,15 @@
   std::vector Diags;
 };
 
+class IncludeReferenceMap {
+  llvm::Optional findIncludeTargetAtLoc(Location Loc);
+
+public:
+  std::unordered_map IncludeLocationMap;
+  std::vector> DataVector;
+  std::vector RangeVector;
+};
+
 /// Stores and provides access to parsed AST.
 class ParsedAST {
 public:
@@ -69,7 +79,8 @@
 std::shared_ptr Preamble,
 std::unique_ptr Buffer,
 std::shared_ptr PCHs,
-IntrusiveRefCntPtr VFS, clangd::Logger &Logger);
+IntrusiveRefCntPtr VFS, clangd::Logger &Logger,
+IncludeReferenceMap IRM);
 
   ParsedAST(ParsedAST &&Other);
   ParsedAST &operator=(ParsedAST &&Other);
@@ -89,12 +100,14 @@
 
   const std::vector &getDiagnostics() const;
 
+  IncludeReferenceMap takeIRM() { return IRM; };
+
 private:
   ParsedAST(std::shared_ptr Preamble,
 std::unique_ptr Clang,
 std::unique_ptr Action,
 std::vector TopLevelDecls,
-std::vector Diags);
+std::vector Diags, IncludeReferenceMap IRM);
 
 private:
   void ensurePreambleDeclsDeserialized();
@@ -114,6 +127,8 @@
   std::vector Diags;
   std::vector TopLevelDecls;
   bool PreambleDeclsDeserialized;
+  std::vector PendingTopLevelDecls;
+  IncludeReferenceMap IRM;
 };
 
 // Provides thread-safe access to ParsedAST.
@@ -256,14 +271,14 @@
   clangd::Logger &Lo

[PATCH] D39375: [clang] Add PPCallbacks list to preprocessor when building a preacompiled preamble.

2017-12-06 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 125815.
Nebiroth added a comment.

Reverted formatting changes to ASTUnit


Repository:
  rC Clang

https://reviews.llvm.org/D39375

Files:
  include/clang/Frontend/PrecompiledPreamble.h
  lib/Frontend/ASTUnit.cpp
  lib/Frontend/PrecompiledPreamble.cpp


Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -239,7 +239,7 @@
 const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds,
 DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr VFS,
 std::shared_ptr PCHContainerOps, bool 
StoreInMemory,
-PreambleCallbacks &Callbacks) {
+PreambleCallbacks &Callbacks, std::unique_ptr PPCallbacks) {
   assert(VFS && "VFS is null");
 
   if (!Bounds.Size)
@@ -351,6 +351,7 @@
   if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
 return BuildPreambleError::BeginSourceFileFailed;
 
+  Clang->getPreprocessor().addPPCallbacks(std::move(PPCallbacks));
   Act->Execute();
 
   // Run the callbacks.
Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1293,7 +1293,7 @@
 
 llvm::ErrorOr NewPreamble = 
PrecompiledPreamble::Build(
 PreambleInvocationIn, MainFileBuffer.get(), Bounds, *Diagnostics, VFS,
-PCHContainerOps, /*StoreInMemory=*/false, Callbacks);
+PCHContainerOps, /*StoreInMemory=*/false, Callbacks, nullptr);
 if (NewPreamble) {
   Preamble = std::move(*NewPreamble);
   PreambleRebuildCounter = 1;
Index: include/clang/Frontend/PrecompiledPreamble.h
===
--- include/clang/Frontend/PrecompiledPreamble.h
+++ include/clang/Frontend/PrecompiledPreamble.h
@@ -81,7 +81,7 @@
 const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds,
 DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr 
VFS,
 std::shared_ptr PCHContainerOps,
-bool StoreInMemory, PreambleCallbacks &Callbacks);
+bool StoreInMemory, PreambleCallbacks &Callbacks, 
std::unique_ptr PPCallbacks);
 
   PrecompiledPreamble(PrecompiledPreamble &&) = default;
   PrecompiledPreamble &operator=(PrecompiledPreamble &&) = default;


Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -239,7 +239,7 @@
 const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds,
 DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr VFS,
 std::shared_ptr PCHContainerOps, bool StoreInMemory,
-PreambleCallbacks &Callbacks) {
+PreambleCallbacks &Callbacks, std::unique_ptr PPCallbacks) {
   assert(VFS && "VFS is null");
 
   if (!Bounds.Size)
@@ -351,6 +351,7 @@
   if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
 return BuildPreambleError::BeginSourceFileFailed;
 
+  Clang->getPreprocessor().addPPCallbacks(std::move(PPCallbacks));
   Act->Execute();
 
   // Run the callbacks.
Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1293,7 +1293,7 @@
 
 llvm::ErrorOr NewPreamble = PrecompiledPreamble::Build(
 PreambleInvocationIn, MainFileBuffer.get(), Bounds, *Diagnostics, VFS,
-PCHContainerOps, /*StoreInMemory=*/false, Callbacks);
+PCHContainerOps, /*StoreInMemory=*/false, Callbacks, nullptr);
 if (NewPreamble) {
   Preamble = std::move(*NewPreamble);
   PreambleRebuildCounter = 1;
Index: include/clang/Frontend/PrecompiledPreamble.h
===
--- include/clang/Frontend/PrecompiledPreamble.h
+++ include/clang/Frontend/PrecompiledPreamble.h
@@ -81,7 +81,7 @@
 const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds,
 DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr VFS,
 std::shared_ptr PCHContainerOps,
-bool StoreInMemory, PreambleCallbacks &Callbacks);
+bool StoreInMemory, PreambleCallbacks &Callbacks, std::unique_ptr PPCallbacks);
 
   PrecompiledPreamble(PrecompiledPreamble &&) = default;
   PrecompiledPreamble &operator=(PrecompiledPreamble &&) = default;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40637: [CMake] Support runtimes and monorepo layouts when looking for libc++

2017-12-06 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D40637



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


[PATCH] D40815: [libcxxabi] Use the correct variable name for target triple in lit

2017-12-06 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rCXXA libc++abi

https://reviews.llvm.org/D40815



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


[PATCH] D40814: [libcxx] Use the correct variable name for target triple in lit

2017-12-06 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rCXX libc++

https://reviews.llvm.org/D40814



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


[PATCH] D40818: [libcxxabi] Pass LIBCXXABI_SYSROOT and LIBCXXABI_GCC_TOOLCHAIN to lit

2017-12-06 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rCXXA libc++abi

https://reviews.llvm.org/D40818



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


[PATCH] D38110: [libunwind][MIPS]: Add support for unwinding in O32 and N64 processes.

2017-12-06 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd accepted this revision.
compnerd added a comment.

LGTM if @sdardis is good with it


https://reviews.llvm.org/D38110



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


r319983 - [clang] Add PRIVATE to target_link_libraries

2017-12-06 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Wed Dec  6 15:02:00 2017
New Revision: 319983

URL: http://llvm.org/viewvc/llvm-project?rev=319983&view=rev
Log:
[clang] Add PRIVATE to target_link_libraries

Another follow-up to r319840. I'd done a test configure with
LLVM_BUILD_STATIC, so I'm not sure why this didn't show up in that.

Modified:
cfe/trunk/tools/c-index-test/CMakeLists.txt

Modified: cfe/trunk/tools/c-index-test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/CMakeLists.txt?rev=319983&r1=319982&r2=319983&view=diff
==
--- cfe/trunk/tools/c-index-test/CMakeLists.txt (original)
+++ cfe/trunk/tools/c-index-test/CMakeLists.txt Wed Dec  6 15:02:00 2017
@@ -16,6 +16,7 @@ endif()
 
 if (LLVM_BUILD_STATIC)
   target_link_libraries(c-index-test
+PRIVATE
 libclang_static
 clangCodeGen
 clangIndex


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


r319986 - [Lex] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

2017-12-06 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Wed Dec  6 15:18:41 2017
New Revision: 319986

URL: http://llvm.org/viewvc/llvm-project?rev=319986&view=rev
Log:
[Lex] Fix some Clang-tidy modernize and Include What You Use warnings; other 
minor fixes (NFC).

Modified:
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
cfe/trunk/include/clang/Lex/ModuleMap.h
cfe/trunk/include/clang/Lex/PTHLexer.h
cfe/trunk/include/clang/Lex/PTHManager.h
cfe/trunk/lib/Lex/HeaderSearch.cpp
cfe/trunk/lib/Lex/ModuleMap.cpp
cfe/trunk/lib/Lex/PTHLexer.cpp

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=319986&r1=319985&r2=319986&view=diff
==
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Wed Dec  6 15:18:41 2017
@@ -1,4 +1,4 @@
-//===--- HeaderSearch.h - Resolve Header File Locations -*- C++ 
-*-===//
+//===- HeaderSearch.h - Resolve Header File Locations ---*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -14,25 +14,37 @@
 #ifndef LLVM_CLANG_LEX_HEADERSEARCH_H
 #define LLVM_CLANG_LEX_HEADERSEARCH_H
 
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Lex/DirectoryLookup.h"
 #include "clang/Lex/ModuleMap.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringSet.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Allocator.h"
+#include 
+#include 
 #include 
+#include 
+#include 
 #include 
 
 namespace clang {
-  
-class DiagnosticsEngine;  
+
+class DiagnosticsEngine;
+class DirectoryEntry;
 class ExternalPreprocessorSource;
 class FileEntry;
 class FileManager;
+class HeaderMap;
 class HeaderSearchOptions;
 class IdentifierInfo;
+class LangOptions;
+class Module;
 class Preprocessor;
+class TargetInfo;
 
 /// \brief The preprocessor keeps track of this information for each
 /// file that is \#included.
@@ -76,14 +88,14 @@ struct HeaderFileInfo {
   unsigned IsValid : 1;
   
   /// \brief The number of times the file has been included already.
-  unsigned short NumIncludes;
+  unsigned short NumIncludes = 0;
 
   /// \brief The ID number of the controlling macro.
   ///
   /// This ID number will be non-zero when there is a controlling
   /// macro whose IdentifierInfo may not yet have been loaded from
   /// external storage.
-  unsigned ControllingMacroID;
+  unsigned ControllingMacroID = 0;
 
   /// If this file has a \#ifndef XXX (or equivalent) guard that
   /// protects the entire contents of the file, this is the identifier
@@ -93,17 +105,16 @@ struct HeaderFileInfo {
   /// the controlling macro of this header, since
   /// getControllingMacro() is able to load a controlling macro from
   /// external storage.
-  const IdentifierInfo *ControllingMacro;
+  const IdentifierInfo *ControllingMacro = nullptr;
 
   /// \brief If this header came from a framework include, this is the name
   /// of the framework.
   StringRef Framework;
   
   HeaderFileInfo()
-: isImport(false), isPragmaOnce(false), DirInfo(SrcMgr::C_User), 
-  External(false), isModuleHeader(false), isCompilingModuleHeader(false),
-  Resolved(false), IndexHeaderMapHeader(false), IsValid(0),
-  NumIncludes(0), ControllingMacroID(0), ControllingMacro(nullptr)  {}
+  : isImport(false), isPragmaOnce(false), DirInfo(SrcMgr::C_User), 
+External(false), isModuleHeader(false), isCompilingModuleHeader(false),
+Resolved(false), IndexHeaderMapHeader(false), IsValid(false)  {}
 
   /// \brief Retrieve the controlling macro for this header file, if
   /// any.
@@ -135,6 +146,8 @@ public:
 /// \brief Encapsulates the information needed to find the file referenced
 /// by a \#include or \#include_next, (sub-)framework lookup, etc.
 class HeaderSearch {
+  friend class DirectoryLookup;
+
   /// This structure is used to record entries in our framework cache.
   struct FrameworkCacheEntry {
 /// The directory entry which should be used for the cached framework.
@@ -151,6 +164,7 @@ class HeaderSearch {
 
   DiagnosticsEngine &Diags;
   FileManager &FileMgr;
+
   /// \#include search path information.  Requests for \#include "x" search the
   /// directory of the \#including file first, then each directory in 
SearchDirs
   /// consecutively. Requests for  search the current dir first, then each
@@ -158,9 +172,9 @@ class HeaderSearch {
   /// NoCurDirSearch is true, then the check for the file in the current
   /// directory is suppressed.
   std::vector SearchDirs;
-  unsigned AngledDirIdx;
-  unsigned SystemDirIdx;
-  bool NoCurDirSearch;
+  unsigned AngledDirIdx = 0;
+  unsigned SystemDirIdx = 0;
+  bool NoCurDirSearch = false;
 
   /// \bri

[PATCH] D40925: Add option -fkeep-static-consts

2017-12-06 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.

Currently clang does not emit unused static constants declared globally. Local 
static constants are emitted by default. -fkeep-static-consts can be used to 
emit static constants declared globally even if they are not used.

This could be useful for producing identification strings like SVN identifiers 
inside the object file even though the string isn't used by the program.


https://reviews.llvm.org/D40925

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  lib/AST/ASTContext.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/keep-static-consts.cpp


Index: test/CodeGen/keep-static-consts.cpp
===
--- /dev/null
+++ test/CodeGen/keep-static-consts.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fkeep-static-consts -emit-llvm %s -o - 
-triple=x86_64-unknown-linux-gnu | FileCheck %s
+
+// CHECK: @_ZL3var = internal constant i32 10, align 4
+static const int var = 10;
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2509,6 +2509,7 @@
   Opts.HalfArgsAndReturns = Args.hasArg(OPT_fallow_half_arguments_and_returns)
 | Opts.NativeHalfArgsAndReturns;
   Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm);
+  Opts.KeepStaticConsts = Args.hasArg(OPT_fkeep_static_consts);
 
   // __declspec is enabled by default for the PS4 by the driver, and also
   // enabled for Microsoft Extensions or Borland Extensions, here.
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3803,6 +3803,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
   Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
+  Args.AddLastArg(CmdArgs, options::OPT_fkeep_static_consts);
   // Emulated TLS is enabled by default on Android and OpenBSD, and can be 
enabled
   // manually with -femulated-tls.
   bool EmulatedTLSDefault = Triple.isAndroid() || Triple.isOSOpenBSD() ||
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -9314,6 +9314,12 @@
   if (D->hasAttr() || D->hasAttr())
 return true;
 
+  // Emit static constants even if they are not used if KeepStaticConsts is 
set.
+  if (const VarDecl *VD = dyn_cast(D)) {
+if (LangOpts.KeepStaticConsts && VD->getType().isConstQualified())
+  return true;
+  }
+
   if (const FunctionDecl *FD = dyn_cast(D)) {
 // Forward declarations aren't required.
 if (!FD->doesThisDeclarationHaveABody())
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -835,6 +835,8 @@
 def fjump_tables : Flag<["-"], "fjump-tables">, Group;
 def fno_jump_tables : Flag<["-"], "fno-jump-tables">, Group, 
Flags<[CC1Option]>,
   HelpText<"Do not use jump tables for lowering switches">;
+def fkeep_static_consts : Flag<["-"], "fkeep-static-consts">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Keep static const variables even if unused">;
 
 // Begin sanitizer flags. These should all be core options exposed in all 
driver
 // modes.
Index: include/clang/Basic/LangOptions.def
===
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -319,6 +319,8 @@
 BENIGN_LANGOPT(AllowEditorPlaceholders, 1, 0,
"allow editor placeholders in source")
 
+BENIGN_LANGOPT(KeepStaticConsts  , 1, 0, "keep static const variables even 
if unused")
+
 #undef LANGOPT
 #undef COMPATIBLE_LANGOPT
 #undef BENIGN_LANGOPT


Index: test/CodeGen/keep-static-consts.cpp
===
--- /dev/null
+++ test/CodeGen/keep-static-consts.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fkeep-static-consts -emit-llvm %s -o - -triple=x86_64-unknown-linux-gnu | FileCheck %s
+
+// CHECK: @_ZL3var = internal constant i32 10, align 4
+static const int var = 10;
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2509,6 +2509,7 @@
   Opts.HalfArgsAndReturns = Args.hasArg(OPT_fallow_half_arguments_and_returns)
 | Opts.NativeHalfArgsAndReturns;
   Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm);
+  Opts.KeepStaticConsts = Args.hasArg(OPT_fkeep_static_consts);
 
   // __declspec is enabled by default for the PS4 by the driver, and also
   // enabled for Microsoft Extensions or Borla

[PATCH] D40929: Unblock Swift Calling Convention Mangling on Windows

2017-12-06 Thread Thomas Roughton via Phabricator via cfe-commits
troughton created this revision.
troughton added a project: clang.
Herald added a subscriber: cfe-commits.

Following discussion on the [[ 
https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20171204/006123.html | 
swift-dev mailing list] and on a pull request for swift-clang 
, unblock support for the Swift 
calling convention on targets using Microsoft mangling by mangling the name as 
per the __cdecl calling convention.

Also in this PR, replace llvm_unreachable with an error diagnostic since this 
code path can be hit.


Repository:
  rC Clang

https://reviews.llvm.org/D40929

Files:
  lib/AST/MicrosoftMangle.cpp


Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -2130,10 +2130,12 @@
   // them.)

   switch (CC) {
-default:
-  llvm_unreachable("Unsupported CC for mangling");
+  llvm::errs() << "Unsupported CC for mangling: " << CC << ".\n";
 case CC_Win64:
 case CC_X86_64SysV:
+// NOTE: SwiftCC should have its own mangling specifier.
+// For now, don't do anything special and treat SwiftCC like __cdecl.
+case CC_Swift:
 case CC_C: Out << 'A'; break;
 case CC_X86Pascal: Out << 'C'; break;
 case CC_X86ThisCall: Out << 'E'; break;


Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -2130,10 +2130,12 @@
   // them.)

   switch (CC) {
-default:
-  llvm_unreachable("Unsupported CC for mangling");
+  llvm::errs() << "Unsupported CC for mangling: " << CC << ".\n";
 case CC_Win64:
 case CC_X86_64SysV:
+// NOTE: SwiftCC should have its own mangling specifier.
+// For now, don't do anything special and treat SwiftCC like __cdecl.
+case CC_Swift:
 case CC_C: Out << 'A'; break;
 case CC_X86Pascal: Out << 'C'; break;
 case CC_X86ThisCall: Out << 'E'; break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40380: Remove old concepts parsing code

2017-12-06 Thread Hubert Tong via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC319992: Remove old concepts parsing code (authored by 
hubert.reinterpretcast).

Changed prior to commit:
  https://reviews.llvm.org/D40380?vs=124032&id=125844#toc

Repository:
  rC Clang

https://reviews.llvm.org/D40380

Files:
  include/clang/AST/DeclTemplate.h
  include/clang/Sema/DeclSpec.h
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaTemplate.cpp
  test/CXX/concepts-ts/dcl.dcl/lit.cfg.py
  test/Parser/cxx-concept-declaration.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -3464,11 +3464,6 @@
   isInvalid = DS.SetConstexprSpec(Loc, PrevSpec, DiagID);
   break;
 
-// concept
-case tok::kw_concept:
-  isInvalid = DS.SetConceptSpec(Loc, PrevSpec, DiagID);
-  break;
-
 // type-specifier
 case tok::kw_short:
   isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec,
@@ -4825,9 +4820,6 @@
   case tok::annot_decltype:
   case tok::kw_constexpr:
 
-// C++ Concepts TS - concept
-  case tok::kw_concept:
-
 // C11 _Atomic
   case tok::kw__Atomic:
 return true;
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -1299,11 +1299,9 @@
 //   'friend'
 //   'typedef'
 //   'constexpr'
-//   'concept'
   case tok::kw_friend:
   case tok::kw_typedef:
   case tok::kw_constexpr:
-  case tok::kw_concept:
 // storage-class-specifier
   case tok::kw_register:
   case tok::kw_static:
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -8342,8 +8342,7 @@
   // We leave 'friend' and 'virtual' to be rejected in the normal way.
   if (DS.hasTypeSpecifier() || DS.getTypeQualifiers() ||
   DS.getStorageClassSpecLoc().isValid() || DS.isInlineSpecified() ||
-  DS.isNoreturnSpecified() || DS.isConstexprSpecified() ||
-  DS.isConceptSpecified()) {
+  DS.isNoreturnSpecified() || DS.isConstexprSpecified()) {
 BadSpecifierDiagnoser Diagnoser(
 *this, D.getIdentifierLoc(),
 diag::err_deduction_guide_invalid_specifier);
@@ -8356,9 +8355,7 @@
 Diagnoser.check(DS.getInlineSpecLoc(), "inline");
 Diagnoser.check(DS.getNoreturnSpecLoc(), "_Noreturn");
 Diagnoser.check(DS.getConstexprSpecLoc(), "constexpr");
-Diagnoser.check(DS.getConceptSpecLoc(), "concept");
 DS.ClearConstexprSpec();
-DS.ClearConceptSpec();
 
 Diagnoser.check(DS.getConstSpecLoc(), "const");
 Diagnoser.check(DS.getRestrictSpecLoc(), "__restrict");
Index: lib/Sema/DeclSpec.cpp
===
--- lib/Sema/DeclSpec.cpp
+++ lib/Sema/DeclSpec.cpp
@@ -969,18 +969,6 @@
   return false;
 }
 
-bool DeclSpec::SetConceptSpec(SourceLocation Loc, const char *&PrevSpec,
-  unsigned &DiagID) {
-  if (Concept_specified) {
-DiagID = diag::ext_duplicate_declspec;
-PrevSpec = "concept";
-return true;
-  }
-  Concept_specified = true;
-  ConceptLoc = Loc;
-  return false;
-}
-
 void DeclSpec::SaveWrittenBuiltinSpecs() {
   writtenBS.Sign = getTypeSpecSign();
   writtenBS.Width = getTypeSpecWidth();
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -8037,15 +8037,6 @@
   // Ignore access information;  it doesn't figure into redeclaration checking.
   FunctionDecl *Specialization = cast(*Result);
 
-  // C++ Concepts TS [dcl.spec.concept]p7: A program shall not declare [...]
-  // an explicit specialization (14.8.3) [...] of a concept definition.
-  if (Specialization->getPrimaryTemplate()->isConcept()) {
-Diag(FD->getLocation(), diag::err_concept_specialized)
-<< 0 /*function*/ << 1 /*explicitly specialized*/;
-Diag(Specialization->getLocation(), diag::note_previous_declaration);
-return true;
-  }
-
   FunctionTemplateSpecializationInfo *SpecInfo
 = Specialization->getTemplateSpecializationInfo();
   assert(SpecInfo && "Function template specialization info missing?");
@@ -8932,15 +8923,6 @@
 Diag(D.getDeclSpec().getConstexprSpecLoc(),
  diag::err_explicit_instantiation_constexpr);
 
-  // C++ Concepts TS [dcl.spec.concept]p1: The concept specifier shall be
-  // applied only to the definition of a function template or variable template,
-  // declared in namespace scope.
-  if (D.getDeclSpec().isConceptSpecified()) {
-Diag(D.getDeclSpec().getConceptSpecLoc(),
- diag::err_concept_specified_specialization) << 0;
-return true;
-  }
-
   // A deduction guide is not on the l

r319992 - Remove old concepts parsing code

2017-12-06 Thread Hubert Tong via cfe-commits
Author: hubert.reinterpretcast
Date: Wed Dec  6 16:34:20 2017
New Revision: 319992

URL: http://llvm.org/viewvc/llvm-project?rev=319992&view=rev
Log:
Remove old concepts parsing code

Summary:
This is so we can implement concepts per P0734R0. Relevant failing test
cases are disabled.

Reviewers: hubert.reinterpretcast, rsmith, saar.raz, nwilson

Reviewed By: saar.raz

Subscribers: cfe-commits

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

Patch by Changyu Li!

Added:
cfe/trunk/test/CXX/concepts-ts/dcl.dcl/lit.cfg.py
Modified:
cfe/trunk/include/clang/AST/DeclTemplate.h
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/Parser/cxx-concept-declaration.cpp

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=319992&r1=319991&r2=319992&view=diff
==
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Wed Dec  6 16:34:20 2017
@@ -405,7 +405,7 @@ protected:
   TemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, DeclContext *DC,
SourceLocation L, DeclarationName Name,
TemplateParameterList *Params)
-  : NamedDecl(DK, DC, L, Name), TemplatedDecl(nullptr, false),
+  : NamedDecl(DK, DC, L, Name), TemplatedDecl(nullptr),
 TemplateParams(CTDI) {
 this->setTemplateParameters(Params);
   }
@@ -418,7 +418,7 @@ protected:
   TemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, DeclContext *DC,
SourceLocation L, DeclarationName Name,
TemplateParameterList *Params, NamedDecl *Decl)
-  : NamedDecl(DK, DC, L, Name), TemplatedDecl(Decl, false),
+  : NamedDecl(DK, DC, L, Name), TemplatedDecl(Decl),
 TemplateParams(CTDI) {
 this->setTemplateParameters(Params);
   }
@@ -450,7 +450,7 @@ public:
   }
 
   /// Get the underlying, templated declaration.
-  NamedDecl *getTemplatedDecl() const { return TemplatedDecl.getPointer(); }
+  NamedDecl *getTemplatedDecl() const { return TemplatedDecl; }
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
@@ -461,21 +461,11 @@ public:
 
   SourceRange getSourceRange() const override LLVM_READONLY {
 return SourceRange(getTemplateParameters()->getTemplateLoc(),
-   TemplatedDecl.getPointer()->getSourceRange().getEnd());
+   TemplatedDecl->getSourceRange().getEnd());
   }
 
-  /// Whether this is a (C++ Concepts TS) function or variable concept.
-  bool isConcept() const { return TemplatedDecl.getInt(); }
-  void setConcept() { TemplatedDecl.setInt(true); }
-
 protected:
-  /// \brief The named declaration from which this template was instantiated.
-  /// (or null).
-  ///
-  /// The boolean value will be true to indicate that this template
-  /// (function or variable) is a concept.
-  llvm::PointerIntPair TemplatedDecl;
-
+  NamedDecl *TemplatedDecl;
   /// \brief The template parameter list and optional requires-clause
   /// associated with this declaration; alternatively, a
   /// \c ConstrainedTemplateDeclInfo if the associated constraints of the
@@ -504,9 +494,9 @@ public:
   /// \brief Initialize the underlying templated declaration and
   /// template parameters.
   void init(NamedDecl *templatedDecl, TemplateParameterList* templateParams) {
-assert(!TemplatedDecl.getPointer() && "TemplatedDecl already set!");
+assert(!TemplatedDecl && "TemplatedDecl already set!");
 assert(!TemplateParams && "TemplateParams already set!");
-TemplatedDecl.setPointer(templatedDecl);
+TemplatedDecl = templatedDecl;
 TemplateParams = templateParams;
   }
 };
@@ -1028,7 +1018,7 @@ public:
 
   /// Get the underlying function declaration of the template.
   FunctionDecl *getTemplatedDecl() const {
-return static_cast(TemplatedDecl.getPointer());
+return static_cast(TemplatedDecl);
   }
 
   /// Returns whether this template declaration defines the primary
@@ -2120,7 +2110,7 @@ public:
 
   /// \brief Get the underlying class declarations of the template.
   CXXRecordDecl *getTemplatedDecl() const {
-return static_cast(TemplatedDecl.getPointer());
+return static_cast(TemplatedDecl);
   }
 
   /// \brief Returns whether this template declaration defines the primary
@@ -2367,7 +2357,7 @@ public:
 
   /// Get the underlying function declaration of the template.
   TypeAliasDecl *getTemplatedDecl() const {
-return static_cast(TemplatedDecl.getPointer());
+return static_cast(TemplatedDecl);
   }
 
 
@@ -2934,7 +2924,7 @@ public:
 
   /// \brief Get the underlying variable declarati

[PATCH] D40929: Unblock Swift Calling Convention Mangling on Windows

2017-12-06 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Patch is missing context.




Comment at: lib/AST/MicrosoftMangle.cpp:2133
+  llvm::errs() << "Unsupported CC for mangling: " << CC << ".\n";
 case CC_Win64:
 case CC_X86_64SysV:

You still need the default label, right?


Repository:
  rC Clang

https://reviews.llvm.org/D40929



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


[PATCH] D38110: [libunwind][MIPS]: Add support for unwinding in O32 and N64 processes.

2017-12-06 Thread Simon Dardis via Phabricator via cfe-commits
sdardis accepted this revision.
sdardis added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D38110



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


[libcxx] r319994 - [libcxx] [test] Strip trailing whitespace. NFC.

2017-12-06 Thread Stephan T. Lavavej via cfe-commits
Author: stl_msft
Date: Wed Dec  6 16:50:23 2017
New Revision: 319994

URL: http://llvm.org/viewvc/llvm-project?rev=319994&view=rev
Log:
[libcxx] [test] Strip trailing whitespace. NFC.

Modified:

libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.decompose/path.decompose.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.ends_with/ends_with.ptr.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.ends_with/ends_with.string_view.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.starts_with/starts_with.string_view.pass.cpp

libcxx/trunk/test/std/utilities/meta/meta.trans/meta.trans.other/remove_cvref.pass.cpp

Modified: 
libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.decompose/path.decompose.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.decompose/path.decompose.pass.cpp?rev=319994&r1=319993&r2=319994&view=diff
==
--- 
libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.decompose/path.decompose.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.decompose/path.decompose.pass.cpp
 Wed Dec  6 16:50:23 2017
@@ -178,7 +178,7 @@ void decompFilenameTest()
 path p(TC.raw);
 assert(p == TC.raw);
 ASSERT_NOEXCEPT(p.empty());
-
+
 assert(p.filename() == TC.filename);
 assert(p.has_filename() != TC.filename.empty());
 

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.ends_with/ends_with.ptr.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.ends_with/ends_with.ptr.pass.cpp?rev=319994&r1=319993&r2=319994&view=diff
==
--- 
libcxx/trunk/test/std/strings/basic.string/string.ends_with/ends_with.ptr.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/strings/basic.string/string.ends_with/ends_with.ptr.pass.cpp
 Wed Dec  6 16:50:23 2017
@@ -30,7 +30,7 @@ int main()
 //  S   s4  { s + 1, 4 };
 //  S   s5  { s, 5 };
 S  sNot { "def", 3 };
-
+
 LIBCPP_ASSERT_NOEXCEPT(s0.ends_with(""));
 
 assert ( s0.ends_with(""));

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.ends_with/ends_with.string_view.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.ends_with/ends_with.string_view.pass.cpp?rev=319994&r1=319993&r2=319994&view=diff
==
--- 
libcxx/trunk/test/std/strings/basic.string/string.ends_with/ends_with.string_view.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/strings/basic.string/string.ends_with/ends_with.string_view.pass.cpp
 Wed Dec  6 16:50:23 2017
@@ -31,7 +31,7 @@ int main()
 //  S   s4  { s + 1, 4 };
 //  S   s5  { s, 5 };
 S  sNot { "def", 3 };
-
+
 SV  sv0;
 SV  sv1 { s + 4, 1 };
 SV  sv2 { s + 3, 2 };

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.starts_with/starts_with.string_view.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.starts_with/starts_with.string_view.pass.cpp?rev=319994&r1=319993&r2=319994&view=diff
==
--- 
libcxx/trunk/test/std/strings/basic.string/string.starts_with/starts_with.string_view.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/strings/basic.string/string.starts_with/starts_with.string_view.pass.cpp
 Wed Dec  6 16:50:23 2017
@@ -31,7 +31,7 @@ int main()
 //  S   s4  { s, 4 };
 //  S   s5  { s, 5 };
 S  sNot { "def", 3 };
-
+
 SV  sv0;
 SV  sv1 { s, 1 };
 SV  sv2 { s, 2 };

Modified: 
libcxx/trunk/test/std/utilities/meta/meta.trans/meta.trans.other/remove_cvref.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/meta/meta.trans/meta.trans.other/remove_cvref.pass.cpp?rev=319994&r1=319993&r2=319994&view=diff
==
--- 
libcxx/trunk/test/std/utilities/meta/meta.trans/meta.trans.other/remove_cvref.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/meta/meta.trans/meta.trans.other/remove_cvref.pass.cpp
 Wed Dec  6 16:50:23 2017
@@ -32,7 +32,7 @@ int main()
 test_remove_cvref();
 test_remove_cvref();
 
-// Doesn't decay 
+// Doesn't decay
 test_remove_cvref();
 test_remove_cvref();
 test_remove_cvref();


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


[PATCH] D40929: Unblock Swift Calling Convention Mangling on Windows

2017-12-06 Thread Thomas Roughton via Phabricator via cfe-commits
troughton updated this revision to Diff 125847.
troughton added a comment.

Add back a mistakenly removed default case.


Repository:
  rC Clang

https://reviews.llvm.org/D40929

Files:
  lib/AST/MicrosoftMangle.cpp


Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -2131,9 +2131,12 @@

   switch (CC) {
 default:
-  llvm_unreachable("Unsupported CC for mangling");
+  llvm::errs() << "Unsupported CC for mangling" << CC << ".\n";
 case CC_Win64:
 case CC_X86_64SysV:
+// NOTE: SwiftCC should have its own mangling specifier.
+// For now, don't do anything special and treat SwiftCC like __cdecl.
+case CC_Swift:
 case CC_C: Out << 'A'; break;
 case CC_X86Pascal: Out << 'C'; break;
 case CC_X86ThisCall: Out << 'E'; break;


Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -2131,9 +2131,12 @@

   switch (CC) {
 default:
-  llvm_unreachable("Unsupported CC for mangling");
+  llvm::errs() << "Unsupported CC for mangling" << CC << ".\n";
 case CC_Win64:
 case CC_X86_64SysV:
+// NOTE: SwiftCC should have its own mangling specifier.
+// For now, don't do anything special and treat SwiftCC like __cdecl.
+case CC_Swift:
 case CC_C: Out << 'A'; break;
 case CC_X86Pascal: Out << 'C'; break;
 case CC_X86ThisCall: Out << 'E'; break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40560: [analyzer] WIP: Get construction into `operator new` running in simple cases.

2017-12-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 125850.
NoQ added a comment.

Replaced the live expression hack with a slightly better approach. It doesn't 
update the live variables analysis to take `CFGNewAllocator` into account, but 
at least tests now pass.

In order to keep the return value produced by the `operator new()` call around 
until `CXXNewExpr` is evaluated, i added a program state trait, 
`CXXNewAllocatorValueStack`:

1. Upon evaluating `CFGNewAllocator`, the return `SVal` of the evaluated 
allocator call is put here;
2. Upon evaluating `CXXConstructExpr`, that return value is retrieved from here;
3. Upon evaluating `CXXNewExpr`, the return value is retrieved from here again 
and then wiped.

In order to support nested allocator calls, this state trait is organized as a 
stack/FIFO, with push in `CFGNewAllocator` and pop in `CXXNewExpr`. The 
`llvm::ImmutableList` thing offers some asserts for warning us when we popped 
more times than we pushed; we might want to add more asserts here to detect 
other mismatches, but i don't see a need for implementing this as an 
environment-like map from (`Expr`, `LocationContext`) to SVal.

Why `SVal` and not `MemRegion`? Because i believe that ideally we want to 
produce constructor calls with null or undefined `this`-arguments. Constructors 
into null pointers should be skipped - this is how `operator new(std::nothrow)` 
works, for instance. Constructors into garbage pointers should be immediately 
caught by the checkers (to throw a warning and generate a sink), but we still 
need to produce them so that the checkers could catch them. But for now 
`CXXConstructorCall` has room only for one pointer, which is currently `const 
MemRegion *`, so this still remains to be tackled.

Also we need to make sure that not only the expression lives, but also its 
value lives, with all the various traits attached to it. Hence the new facility 
in `ExprEngine::removeDead()` to mark the values in `CXXNewAllocatorValueStack` 
as live. Test included in `new-ctor-inlined.cpp` (the one with `s != 0`) covers 
this situation.

Some doxygen comments updated.


https://reviews.llvm.org/D40560

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  test/Analysis/inline.cpp
  test/Analysis/new-ctor-conservative.cpp
  test/Analysis/new-ctor-inlined.cpp

Index: test/Analysis/new-ctor-inlined.cpp
===
--- /dev/null
+++ test/Analysis/new-ctor-inlined.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+
+void clang_analyzer_eval(bool);
+
+typedef __typeof__(sizeof(int)) size_t;
+
+void *conjure();
+void exit(int);
+
+void *operator new(size_t size) throw() {
+  void *x = conjure();
+  if (x == 0)
+exit(1);
+  return x;
+}
+
+struct S {
+  int x;
+  S() : x(1) {}
+  ~S() {}
+};
+
+void foo() {
+  S *s = new S;
+  clang_analyzer_eval(s != 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(s->x == 1); // expected-warning{{TRUE}}
+}
Index: test/Analysis/new-ctor-conservative.cpp
===
--- /dev/null
+++ test/Analysis/new-ctor-conservative.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+
+void clang_analyzer_eval(bool);
+
+struct S {
+  int x;
+  S() : x(1) {}
+  ~S() {}
+};
+
+void foo() {
+  S *s = new S;
+  clang_analyzer_eval(s->x == 1); // expected-warning{{TRUE}}
+}
Index: test/Analysis/inline.cpp
===
--- test/Analysis/inline.cpp
+++ test/Analysis/inline.cpp
@@ -315,17 +315,13 @@
 int value;
 
 IntWrapper(int input) : value(input) {
-  // We don't want this constructor to be inlined unless we can actually
-  // use the proper region for operator new.
-  // See PR12014 and .
-  clang_analyzer_checkInlined(false); // no-warning
+  clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
 }
   };
 
   void test() {
 IntWrapper *obj = new IntWrapper(42);
-// should be TRUE
-clang_analyzer_eval(obj->value == 42); // expected-warning{{UNKNOWN}}
+clang_analyzer_eval(obj->value == 42); // expected-warning{{TRUE}}
 delete obj;
   }
 
Index: lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -276,6 +276,13 @@
 
   state = state->BindExpr(CCE, callerCtx, ThisV);
 }
+
+if (isa(CE)) {
+  // We are currently evaluating a CXXNewAllocator CFGElement. It takes a
+  // while to reach the actua

  1   2   >