[PATCH] D46675: [clangd] Add helper for collecting #include directives in file.

2018-05-09 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: sammccall.
Herald added subscribers: cfe-commits, jkorous, MaskRay, ilya-biryukov, klimek.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46675

Files:
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/Headers.cpp
  clangd/Headers.h
  clangd/XRefs.cpp

Index: clangd/XRefs.cpp
===
--- clangd/XRefs.cpp
+++ clangd/XRefs.cpp
@@ -234,12 +234,10 @@
 
   std::vector Result;
   // Handle goto definition for #include.
-  for (auto &IncludeLoc : AST.getInclusionLocations()) {
-Range R = IncludeLoc.first;
+  for (auto &Inc : AST.getInclusions()) {
 Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg);
-
-if (R.contains(Pos))
-  Result.push_back(Location{URIForFile{IncludeLoc.second}, {}});
+if (!Inc.Resolved.empty() && Inc.R.contains(Pos))
+  Result.push_back(Location{URIForFile{Inc.Resolved}, {}});
   }
   if (!Result.empty())
 return Result;
Index: clangd/Headers.h
===
--- clangd/Headers.h
+++ clangd/Headers.h
@@ -11,7 +11,9 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_HEADERS_H
 
 #include "Path.h"
+#include "Protocol.h"
 #include "clang/Basic/VirtualFileSystem.h"
+#include "clang/Lex/PPCallbacks.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
@@ -32,6 +34,19 @@
   bool valid() const;
 };
 
+// An #include directive that we found in the main file.
+struct Inclusion {
+  Range R; // Inclusion range.
+  std::string Written; // Inclusion name as written e.g. .
+  Path Resolved;   // Resolved path of included file. Empty if not resolved.
+};
+
+/// Returns a PPCallback that collects all inclusions in the main file.
+/// Inclusions are added to \p Includes.
+std::unique_ptr
+collectInclusionsInMainFileCallback(const SourceManager &SM,
+std::vector &Inclusions);
+
 /// Determines the preferred way to #include a file, taking into account the
 /// search path. Usually this will prefer a shorter representation like
 /// 'Foo/Bar.h' over a longer one like 'Baz/include/Foo/Bar.h'.
Index: clangd/Headers.cpp
===
--- clangd/Headers.cpp
+++ clangd/Headers.cpp
@@ -10,6 +10,7 @@
 #include "Headers.h"
 #include "Compiler.h"
 #include "Logger.h"
+#include "SourceCode.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -24,26 +25,32 @@
 
 class RecordHeaders : public PPCallbacks {
 public:
-  RecordHeaders(llvm::StringSet<> &WrittenHeaders,
-llvm::StringSet<> &ResolvedHeaders)
-  : WrittenHeaders(WrittenHeaders), ResolvedHeaders(ResolvedHeaders) {}
+  RecordHeaders(const SourceManager &SM, std::vector &Includes)
+  : SM(SM), Includes(Includes) {}
 
-  void InclusionDirective(SourceLocation /*HashLoc*/,
-  const Token & /*IncludeTok*/,
+  // Record existing #includes - both written and resolved paths. Only #includes
+  // in the main file are collected.
+  void InclusionDirective(SourceLocation HashLoc, const Token & /*IncludeTok*/,
   llvm::StringRef FileName, bool IsAngled,
-  CharSourceRange /*FilenameRange*/,
-  const FileEntry *File, llvm::StringRef /*SearchPath*/,
+  CharSourceRange FilenameRange, const FileEntry *File,
+  llvm::StringRef /*SearchPath*/,
   llvm::StringRef /*RelativePath*/,
   const Module * /*Imported*/) override {
-WrittenHeaders.insert(
-(IsAngled ? "<" + FileName + ">" : "\"" + FileName + "\"").str());
-if (File != nullptr && !File->tryGetRealPathName().empty())
-  ResolvedHeaders.insert(File->tryGetRealPathName());
+// Only inclusion directives in the main file make sense. The user cannot
+// select directives not in the main file.
+if (HashLoc.isInvalid() || !SM.isInMainFile(HashLoc))
+  return;
+std::string Written =
+(IsAngled ? "<" + FileName + ">" : "\"" + FileName + "\"").str();
+std::string Resolved = (!File || File->tryGetRealPathName().empty())
+   ? ""
+   : File->tryGetRealPathName();
+Includes.push_back({halfOpenToRange(SM, FilenameRange), Written, Resolved});
   }
 
 private:
-  llvm::StringSet<> &WrittenHeaders;
-  llvm::StringSet<> &ResolvedHeaders;
+  const SourceManager &SM;
+  std::vector &Includes;
 };
 
 } // namespace
@@ -57,6 +64,12 @@
  (!Verbatim && llvm::sys::path::is_absolute(File));
 }
 
+std::unique_ptr
+collectInclusionsInMainFileCallback(const SourceManager &SM,
+std::vector &Includes) {
+  return llvm

r331958 - [X86] Change the implementation of scalar masked load/store intrinsics to not use a 512-bit intermediate vector.

2018-05-09 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Wed May  9 22:43:43 2018
New Revision: 331958

URL: http://llvm.org/viewvc/llvm-project?rev=331958&view=rev
Log:
[X86] Change the implementation of scalar masked load/store intrinsics to not 
use a 512-bit intermediate vector.

This is unnecessary for AVX512VL supporting CPUs like SKX. We can just emit a 
128-bit masked load/store here no matter what. The backend will widen it to 
512-bits on KNL CPUs.

Fixes the frontend portion of PR37386. Need to fix the backend to optimize the 
new sequences well.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/test/CodeGen/avx512f-builtins.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=331958&r1=331957&r2=331958&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Wed May  9 22:43:43 2018
@@ -1523,10 +1523,10 @@ TARGET_BUILTIN(__builtin_ia32_fixupimmps
 TARGET_BUILTIN(__builtin_ia32_fixupimmps256_mask, "V8fV8fV8fV8iIiUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_fixupimmps256_maskz, "V8fV8fV8fV8iIiUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_loadapd128_mask, "V2dV2d*V2dUc", "n", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_loadsd128_mask, "V8dV8d*V8dUc", "n", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_loadsd128_mask, "V2dV2d*V2dUc", "n", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_loadapd256_mask, "V4dV4d*V4dUc", "n", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_loadaps128_mask, "V4fV4f*V4fUc", "n", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_loadss128_mask, "V16fV16f*V16fUs", "n", 
"avx512f")
+TARGET_BUILTIN(__builtin_ia32_loadss128_mask, "V4fV4f*V4fUc", "n", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_loadaps256_mask, "V8fV8f*V8fUc", "n", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_loaddqudi128_mask, "V2LLiV2LLi*V2LLiUc", "n", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_loaddqudi256_mask, "V4LLiV4LLi*V4LLiUc", "n", 
"avx512vl")
@@ -1543,10 +1543,10 @@ TARGET_BUILTIN(__builtin_ia32_storedquhi
 TARGET_BUILTIN(__builtin_ia32_storedquqi128_mask, "vV16c*V16cUs", "n", 
"avx512vl,avx512bw")
 TARGET_BUILTIN(__builtin_ia32_storedquqi256_mask, "vV32c*V32cUi", "n", 
"avx512vl,avx512bw")
 TARGET_BUILTIN(__builtin_ia32_storeapd128_mask, "vV2d*V2dUc", "n", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_storesd128_mask, "vV8d*V8dUc", "n", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_storesd128_mask, "vV2d*V2dUc", "n", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_storeapd256_mask, "vV4d*V4dUc", "n", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_storeaps128_mask, "vV4f*V4fUc", "n", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_storess128_mask, "vV16f*V16fUs", "n", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_storess128_mask, "vV4f*V4fUc", "n", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_storeaps256_mask, "vV8f*V8fUc", "n", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_storedqudi128_mask, "vV2LLi*V2LLiUc", "n", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_storedqudi256_mask, "vV4LLi*V4LLiUc", "n", 
"avx512vl")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=331958&r1=331957&r2=331958&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed May  9 22:43:43 2018
@@ -8735,7 +8735,7 @@ Value *CodeGenFunction::EmitX86BuiltinEx
 
   case X86::BI__builtin_ia32_storess128_mask:
   case X86::BI__builtin_ia32_storesd128_mask: {
-return EmitX86MaskedStore(*this, Ops, 16);
+return EmitX86MaskedStore(*this, Ops, 1);
   }
   case X86::BI__builtin_ia32_vpopcntb_128:
   case X86::BI__builtin_ia32_vpopcntd_128:
@@ -8819,7 +8819,7 @@ Value *CodeGenFunction::EmitX86BuiltinEx
 
   case X86::BI__builtin_ia32_loadss128_mask:
   case X86::BI__builtin_ia32_loadsd128_mask:
-return EmitX86MaskedLoad(*this, Ops, 16);
+return EmitX86MaskedLoad(*this, Ops, 1);
 
   case X86::BI__builtin_ia32_loadaps128_mask:
   case X86::BI__builtin_ia32_loadaps256_mask:

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=331958&r1=331957&r2=331958&view=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Wed May  9 22:43:43 2018
@@ -9091,17 +9091,13 @@ _mm_maskz_move_sd (__mmask8 __U, __m128d
 static __inline__ void __DEFAULT_FN_ATTRS
 _mm_mask_store_ss (float * __W, __mmask8 __U, __m128 __A)
 {
-  __builtin_ia32_storess128_mask ((__v16sf *)__W,
-(__v16sf) _mm512_castps128_ps512(__A),
-(__mmask16) __U & (__mmask16)1

[PATCH] D46665: [Itanium] Emit type info names with external linkage.

2018-05-09 Thread Eric Fiselier via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC331957: [Itanium] Emit type info names with external 
linkage. (authored by EricWF, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46665?vs=146065&id=146069#toc

Repository:
  rC Clang

https://reviews.llvm.org/D46665

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/rtti-linkage.cpp

Index: test/CodeGenCXX/rtti-linkage.cpp
===
--- test/CodeGenCXX/rtti-linkage.cpp
+++ test/CodeGenCXX/rtti-linkage.cpp
@@ -1,29 +1,31 @@
-// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BOTH
-// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -fvisibility hidden -emit-llvm -o - | FileCheck -check-prefix=CHECK-WITH-HIDDEN -check-prefix=CHECK-BOTH %s
+// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o - | \
+// RUN:FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BOTH \
+// RUN:   -DLINKONCE_VIS_CONSTANT='linkonce_odr constant'
+// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -fvisibility hidden -emit-llvm -o - | \
+// RUN:FileCheck %s -check-prefix=CHECK-WITH-HIDDEN -check-prefix=CHECK-BOTH \
+// RUN:   -DLINKONCE_VIS_CONSTANT='linkonce_odr hidden constant'
 
 #include 
 
-// CHECK-BOTH: _ZTSP1C = internal constant
-// CHECK-BOTH: _ZTS1C = internal constant
+// CHECK-BOTH: _ZTSP1C = [[LINKONCE_VIS_CONSTANT]]
+// CHECK-BOTH: _ZTS1C = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTI1C = internal constant
 // CHECK-BOTH: _ZTIP1C = internal constant
-// CHECK-BOTH: _ZTSPP1C = internal constant
+// CHECK-BOTH: _ZTSPP1C = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIPP1C = internal constant
-// CHECK-BOTH: _ZTSM1Ci = internal constant
+// CHECK-BOTH: _ZTSM1Ci = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1Ci = internal constant
-// CHECK-BOTH: _ZTSPM1Ci = internal constant
+// CHECK-BOTH: _ZTSPM1Ci = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIPM1Ci = internal constant
-// CHECK-BOTH: _ZTSM1CS_ = internal constant
+// CHECK-BOTH: _ZTSM1CS_ = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1CS_ = internal constant
-// CHECK-BOTH: _ZTSM1CPS_ = internal constant
+// CHECK-BOTH: _ZTSM1CPS_ = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1CPS_ = internal constant
-// CHECK-BOTH: _ZTSM1A1C = internal constant
-// CHECK: _ZTS1A = linkonce_odr constant
-// CHECK-WITH-HIDDEN: _ZTS1A = linkonce_odr hidden constant
-// CHECK: _ZTI1A = linkonce_odr constant
-// CHECK-WITH-HIDDEN: _ZTI1A = linkonce_odr hidden constant
+// CHECK-BOTH: _ZTSM1A1C = [[LINKONCE_VIS_CONSTANT]]
+// CHECK-BOTH: _ZTS1A = [[LINKONCE_VIS_CONSTANT]]
+// CHECK-BOTH: _ZTI1A = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1A1C = internal constant
-// CHECK-BOTH: _ZTSM1AP1C = internal constant
+// CHECK-BOTH: _ZTSM1AP1C = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1AP1C = internal constant
 
 // CHECK-WITH-HIDDEN: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
@@ -52,6 +54,12 @@
 // CHECK: _ZTSFvvE = linkonce_odr constant
 // CHECK: _ZTIFvvE = linkonce_odr constant
 // CHECK: _ZTIPFvvE = linkonce_odr constant
+// CHECK: _ZTSPN12_GLOBAL__N_12DIE = internal constant
+// CHECK: _ZTSN12_GLOBAL__N_12DIE = internal constant
+// CHECK: _ZTIN12_GLOBAL__N_12DIE = internal constant
+// CHECK: _ZTIPN12_GLOBAL__N_12DIE = internal constant
+// CHECK: _ZTSMN12_GLOBAL__N_12DIEFvvE = internal constant
+// CHECK: _ZTIMN12_GLOBAL__N_12DIEFvvE = internal constant
 // CHECK: _ZTSN12_GLOBAL__N_11EE = internal constant
 // CHECK: _ZTIN12_GLOBAL__N_11EE = internal constant
 // CHECK: _ZTSA10_i = linkonce_odr constant
@@ -99,12 +107,13 @@
 }
 
 namespace {
-  // D is inside an anonymous namespace, so all type information related to D should have
-  // internal linkage.
-  struct D { };
-  
-  // E is also inside an anonymous namespace.
-  enum E { };
+// D and DI are inside an anonymous namespace, so all type information related
+// to both should have internal linkage.
+struct D {};
+struct DI;
+
+// E is also inside an anonymous namespace.
+enum E {};
   
 };
 
@@ -126,7 +135,10 @@
   // The exception specification is not part of the RTTI descriptor, so it should not have
   // internal linkage.
   (void)typeid(void (*)() throw (D));
-  
+
+  (void)typeid(DI *);
+  (void)typeid(void (DI::*)());
+
   (void)typeid(E);
   
   return typeid(getD());  
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -3008,8 +3008,46 @@
 
 /// Return the linkage that the type info and type info name constants
 /// should have for the given type.
-static llvm::GlobalVariable::LinkageTypes getTypeInfoLinkage(CodeGenModule &CGM,
- QualType Ty) {
+static std::pair
+getTypeInfoLinkage(CodeGenModule &CGM, QualType Ty) {
+  llvm

r331957 - [Itanium] Emit type info names with external linkage.

2018-05-09 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed May  9 22:25:15 2018
New Revision: 331957

URL: http://llvm.org/viewvc/llvm-project?rev=331957&view=rev
Log:
[Itanium] Emit type info names with external linkage.

Summary:
The Itanium ABI requires that the type info for pointer-to-incomplete types to 
have internal linkage, so that it doesn't interfere with the type info once 
completed.  Currently it also marks the type info name as internal as well. 
However, this causes a bug with the STL implementations, which use the type 
info name pointer to perform ordering and hashing of type infos.
For example:

```
// header.h
struct T;
extern std::type_info const& Info;

// tu_one.cpp
#include "header.h"
std::type_info const& Info = typeid(T*);

// tu_two.cpp
#include "header.h"
struct T {};
int main() {
  auto &TI1 = Info;
  auto &TI2 = typeid(T*);
  assert(TI1 == TI2); // Fails
  assert(TI1.hash_code() == TI2.hash_code()); // Fails
}
```

This patch fixes the STL bug by emitting the type info name as linkonce_odr 
when the type-info is for a pointer-to-incomplete type.

Note that libc++ could fix this without a compiler change, but the quality of 
fix would be poor. The library would either have to:

(A) Always perform strcmp/string hashes.
(B) Determine if we have a pointer-to-incomplete type, and only do strcmp then. 
This would require an ABI break for libc++.


Reviewers: rsmith, rjmccall, majnemer, vsapsai

Reviewed By: rjmccall

Subscribers: smeenai, cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/rtti-linkage.cpp

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=331957&r1=331956&r2=331957&view=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Wed May  9 22:25:15 2018
@@ -3008,8 +3008,46 @@ void ItaniumRTTIBuilder::BuildVTablePoin
 
 /// Return the linkage that the type info and type info name constants
 /// should have for the given type.
-static llvm::GlobalVariable::LinkageTypes getTypeInfoLinkage(CodeGenModule 
&CGM,
- QualType Ty) {
+static std::pair
+getTypeInfoLinkage(CodeGenModule &CGM, QualType Ty) {
+  llvm::GlobalValue::LinkageTypes TypeLinkage = [&]() {
+switch (Ty->getLinkage()) {
+case NoLinkage:
+case InternalLinkage:
+case UniqueExternalLinkage:
+  return llvm::GlobalValue::InternalLinkage;
+
+case VisibleNoLinkage:
+case ModuleInternalLinkage:
+case ModuleLinkage:
+case ExternalLinkage:
+  // RTTI is not enabled, which means that this type info struct is going
+  // to be used for exception handling. Give it linkonce_odr linkage.
+  if (!CGM.getLangOpts().RTTI)
+return llvm::GlobalValue::LinkOnceODRLinkage;
+
+  if (const RecordType *Record = dyn_cast(Ty)) {
+const CXXRecordDecl *RD = cast(Record->getDecl());
+if (RD->hasAttr())
+  return llvm::GlobalValue::WeakODRLinkage;
+if (CGM.getTriple().isWindowsItaniumEnvironment())
+  if (RD->hasAttr() &&
+  ShouldUseExternalRTTIDescriptor(CGM, Ty))
+return llvm::GlobalValue::ExternalLinkage;
+// MinGW always uses LinkOnceODRLinkage for type info.
+if (RD->isCompleteDefinition() && RD->isDynamicClass() &&
+!CGM.getContext()
+ .getTargetInfo()
+ .getTriple()
+ .isWindowsGNUEnvironment())
+  return CGM.getVTableLinkage(RD);
+  }
+
+  return llvm::GlobalValue::LinkOnceODRLinkage;
+}
+llvm_unreachable("Invalid linkage!");
+  }();
   // Itanium C++ ABI 2.9.5p7:
   //   In addition, it and all of the intermediate abi::__pointer_type_info
   //   structs in the chain down to the abi::__class_type_info for the
@@ -3020,44 +3058,8 @@ static llvm::GlobalVariable::LinkageType
   //   complete class RTTI (because the latter need not exist), possibly by
   //   making it a local static object.
   if (ContainsIncompleteClassType(Ty))
-return llvm::GlobalValue::InternalLinkage;
-
-  switch (Ty->getLinkage()) {
-  case NoLinkage:
-  case InternalLinkage:
-  case UniqueExternalLinkage:
-return llvm::GlobalValue::InternalLinkage;
-
-  case VisibleNoLinkage:
-  case ModuleInternalLinkage:
-  case ModuleLinkage:
-  case ExternalLinkage:
-// RTTI is not enabled, which means that this type info struct is going
-// to be used for exception handling. Give it linkonce_odr linkage.
-if (!CGM.getLangOpts().RTTI)
-  return llvm::GlobalValue::LinkOnceODRLinkage;
-
-if (const RecordType *Record = dyn_cast(Ty)) {
-  const CXXRecordDecl *RD = cast(Record->getDecl());
-  if (RD->hasAttr())
-return llvm::GlobalValue::WeakODRLinkage;
-  if (CGM.getTriple().is

[PATCH] D46665: [Itanium] Emit type info names with external linkage.

2018-05-09 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

@rjmccall Thank you for the quick review!


https://reviews.llvm.org/D46665



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


[PATCH] D46665: [Itanium] Emit type info names with external linkage.

2018-05-09 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Looks really good, thanks.


https://reviews.llvm.org/D46665



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


[PATCH] D46665: [Itanium] Emit type info names with external linkage.

2018-05-09 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 146065.
EricWF marked 3 inline comments as done.
EricWF added a comment.

Address @rjmccall's comments.


https://reviews.llvm.org/D46665

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/rtti-linkage.cpp

Index: test/CodeGenCXX/rtti-linkage.cpp
===
--- test/CodeGenCXX/rtti-linkage.cpp
+++ test/CodeGenCXX/rtti-linkage.cpp
@@ -1,29 +1,31 @@
-// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BOTH
-// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -fvisibility hidden -emit-llvm -o - | FileCheck -check-prefix=CHECK-WITH-HIDDEN -check-prefix=CHECK-BOTH %s
+// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o - | \
+// RUN:FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BOTH \
+// RUN:   -DLINKONCE_VIS_CONSTANT='linkonce_odr constant'
+// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -fvisibility hidden -emit-llvm -o - | \
+// RUN:FileCheck %s -check-prefix=CHECK-WITH-HIDDEN -check-prefix=CHECK-BOTH \
+// RUN:   -DLINKONCE_VIS_CONSTANT='linkonce_odr hidden constant'
 
 #include 
 
-// CHECK-BOTH: _ZTSP1C = internal constant
-// CHECK-BOTH: _ZTS1C = internal constant
+// CHECK-BOTH: _ZTSP1C = [[LINKONCE_VIS_CONSTANT]]
+// CHECK-BOTH: _ZTS1C = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTI1C = internal constant
 // CHECK-BOTH: _ZTIP1C = internal constant
-// CHECK-BOTH: _ZTSPP1C = internal constant
+// CHECK-BOTH: _ZTSPP1C = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIPP1C = internal constant
-// CHECK-BOTH: _ZTSM1Ci = internal constant
+// CHECK-BOTH: _ZTSM1Ci = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1Ci = internal constant
-// CHECK-BOTH: _ZTSPM1Ci = internal constant
+// CHECK-BOTH: _ZTSPM1Ci = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIPM1Ci = internal constant
-// CHECK-BOTH: _ZTSM1CS_ = internal constant
+// CHECK-BOTH: _ZTSM1CS_ = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1CS_ = internal constant
-// CHECK-BOTH: _ZTSM1CPS_ = internal constant
+// CHECK-BOTH: _ZTSM1CPS_ = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1CPS_ = internal constant
-// CHECK-BOTH: _ZTSM1A1C = internal constant
-// CHECK: _ZTS1A = linkonce_odr constant
-// CHECK-WITH-HIDDEN: _ZTS1A = linkonce_odr hidden constant
-// CHECK: _ZTI1A = linkonce_odr constant
-// CHECK-WITH-HIDDEN: _ZTI1A = linkonce_odr hidden constant
+// CHECK-BOTH: _ZTSM1A1C = [[LINKONCE_VIS_CONSTANT]]
+// CHECK-BOTH: _ZTS1A = [[LINKONCE_VIS_CONSTANT]]
+// CHECK-BOTH: _ZTI1A = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1A1C = internal constant
-// CHECK-BOTH: _ZTSM1AP1C = internal constant
+// CHECK-BOTH: _ZTSM1AP1C = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1AP1C = internal constant
 
 // CHECK-WITH-HIDDEN: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
@@ -52,6 +54,12 @@
 // CHECK: _ZTSFvvE = linkonce_odr constant
 // CHECK: _ZTIFvvE = linkonce_odr constant
 // CHECK: _ZTIPFvvE = linkonce_odr constant
+// CHECK: _ZTSPN12_GLOBAL__N_12DIE = internal constant
+// CHECK: _ZTSN12_GLOBAL__N_12DIE = internal constant
+// CHECK: _ZTIN12_GLOBAL__N_12DIE = internal constant
+// CHECK: _ZTIPN12_GLOBAL__N_12DIE = internal constant
+// CHECK: _ZTSMN12_GLOBAL__N_12DIEFvvE = internal constant
+// CHECK: _ZTIMN12_GLOBAL__N_12DIEFvvE = internal constant
 // CHECK: _ZTSN12_GLOBAL__N_11EE = internal constant
 // CHECK: _ZTIN12_GLOBAL__N_11EE = internal constant
 // CHECK: _ZTSA10_i = linkonce_odr constant
@@ -99,9 +107,10 @@
 }
 
 namespace {
-  // D is inside an anonymous namespace, so all type information related to D should have
-  // internal linkage.
+// D and DI are inside an anonymous namespace, so all type information related
+// to both should have internal linkage.
 struct D {};
+struct DI;
 
 // E is also inside an anonymous namespace.
 enum E {};
@@ -127,6 +136,9 @@
   // internal linkage.
   (void)typeid(void (*)() throw (D));
 
+  (void)typeid(DI *);
+  (void)typeid(void (DI::*)());
+
   (void)typeid(E);
   
   return typeid(getD());  
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -3008,20 +3008,10 @@
 
 /// Return the linkage that the type info and type info name constants
 /// should have for the given type.
-static llvm::GlobalVariable::LinkageTypes getTypeInfoLinkage(CodeGenModule &CGM,
- QualType Ty) {
-  // Itanium C++ ABI 2.9.5p7:
-  //   In addition, it and all of the intermediate abi::__pointer_type_info
-  //   structs in the chain down to the abi::__class_type_info for the
-  //   incomplete class type must be prevented from resolving to the
-  //   corresponding type_info structs for the complete class type, possibly
-  //   by making them local static objects. Finally, a dummy class RTTI is
-  //   generated for the

[PATCH] D39053: [Bitfield] Add more cases to making the bitfield a separate location

2018-05-09 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

Just wanted to explicitly say that I'm happy the updated patch reflects the 
changes to docs and comments I requested. @hfinkel - are you happy for this to 
land now?


https://reviews.llvm.org/D39053



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


[PATCH] D39053: [Bitfield] Add more cases to making the bitfield a separate location

2018-05-09 Thread Ana Pazos via Phabricator via cfe-commits
apazos added a comment.

Thanks for updating the patch, @spetrovic.
Can we have this committed?
This patch has shown to produce code size improvements for a number of targets 
(Mips, X86, ARM, RISC-V).


https://reviews.llvm.org/D39053



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


[PATCH] D46667: [OpenCL, OpenMP] Fix crash when OpenMP used in OpenCL file

2018-05-09 Thread Mike Rice via Phabricator via cfe-commits
mikerice added a comment.

1. It probably makes sense to allow omp simd with OpenCL.  Some people here 
have been successfully using it anyway.
2. I can give that a try.

The test just tests that the compiler doesn't segfault.  What would you prefer 
instead, something that checks the AST or the codegen?


Repository:
  rC Clang

https://reviews.llvm.org/D46667



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


[PATCH] D46665: [Itanium] Emit type info names with external linkage.

2018-05-09 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/ItaniumCXXABI.cpp:3098
+InfoLinkage = getTypeInfoLinkage(CGM, Ty);
+NameLinkage = getTypeInfoLinkage(CGM, Ty, /*ForName*/ true);
+  }

rjmccall wrote:
> I think we could probably just have the function return both instead of 
> requiring the callee to make two calls.
"caller" instead of "callee", of course.


https://reviews.llvm.org/D46665



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


[PATCH] D46665: [Itanium] Emit type info names with external linkage.

2018-05-09 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/ItaniumCXXABI.cpp:3098
+InfoLinkage = getTypeInfoLinkage(CGM, Ty);
+NameLinkage = getTypeInfoLinkage(CGM, Ty, /*ForName*/ true);
+  }

I think we could probably just have the function return both instead of 
requiring the callee to make two calls.



Comment at: lib/CodeGen/ItaniumCXXABI.cpp:3110
   ItaniumCXXABI::RTTIUniquenessKind RTTIUniqueness =
-  CXXABI.classifyRTTIUniqueness(Ty, Linkage);
+  CXXABI.classifyRTTIUniqueness(Ty, InfoLinkage);
   if (RTTIUniqueness != ItaniumCXXABI::RUK_Unique) {

This should be the name linkage, I think.  The targets using non-unique RTTI 
names (i.e. Darwin ARM64) would want this bit to be set for the types they use 
non-unique RTTI names for, i.e. for external types with default visibility, 
even if the type is incomplete in the current translation unit and thus the 
type_info object has been demoted to internal linkage.  (A complete type with 
internal linkage should not have the bit set.)


https://reviews.llvm.org/D46665



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


[PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers

2018-05-09 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

In https://reviews.llvm.org/D42933#1093503, @smeenai wrote:

> Yeah, I think we all agree now that a portability warning isn't really 
> tractable. Note that even for the warnings that motivated this diff, they 
> should have only fired if `size_t` and NSInteger had separate types, so it 
> wasn't a portability warning in that sense to begin with (as in, it would 
> only warn if there was a mismatch for your current target, not if there was a 
> potential mismatch for any target).
>
> We still have two options:
>
> 1. Special-case NSInteger/NSUInteger on Apple platforms so that they can 
> always be printed using `%z` without any issues.
> 2. Relax the format specifier warnings (either under a new warning option, 
> e.g. `-Wformat-relaxed`, or by relaxing `-Wformat` itself and adding 
> something like `-Wformat-pedantic`) so that you don't warn when the specifier 
> and the actual type have the same size and alignment, even when the actual 
> type is different (which would also cover the case in 1).
>
>   I'm personally in favor of 2, and I can start a discussion on cfe-dev if 
> you think we should try to achieve a broader consensus. Whichever option we 
> went with, we would also have to ensure that the optimizer didn't do anything 
> bad (as @aaron.ballman pointed out), both now and in the future.


2 sounds better overall. However I don’t like a relaxed flag because it’s weird 
when you have relaxed/normal/pedantic. How do they mix? What if I want format 
warnings, but not “portability” ones. I think we either want to move this to 
pedantic and (as you propose) only warm on `-Wformat` if size or alignment 
don’t match. We can also have a separate `-Wformat-portability` warning where 
we try (and fail) to be helpful.

Please do start a thread on cfe-dev, much appreciated!


Repository:
  rC Clang

https://reviews.llvm.org/D42933



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


[PATCH] D46665: [Itanium] Emit type info names with external linkage.

2018-05-09 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 146053.
EricWF marked an inline comment as done.
EricWF added a comment.

Address @rsmith's inline comments.

- Calculate the linkage for the type name using the linkage for the type.
- Promote the type name visibility for the incomplete class types as well as 
for pointer and member pointers.


https://reviews.llvm.org/D46665

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/rtti-linkage.cpp

Index: test/CodeGenCXX/rtti-linkage.cpp
===
--- test/CodeGenCXX/rtti-linkage.cpp
+++ test/CodeGenCXX/rtti-linkage.cpp
@@ -1,29 +1,31 @@
-// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BOTH
-// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -fvisibility hidden -emit-llvm -o - | FileCheck -check-prefix=CHECK-WITH-HIDDEN -check-prefix=CHECK-BOTH %s
+// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o - | \
+// RUN:FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BOTH \
+// RUN:   -DLINKONCE_VIS_CONSTANT='linkonce_odr constant'
+// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -fvisibility hidden -emit-llvm -o - | \
+// RUN:FileCheck %s -check-prefix=CHECK-WITH-HIDDEN -check-prefix=CHECK-BOTH \
+// RUN:   -DLINKONCE_VIS_CONSTANT='linkonce_odr hidden constant'
 
 #include 
 
-// CHECK-BOTH: _ZTSP1C = internal constant
-// CHECK-BOTH: _ZTS1C = internal constant
+// CHECK-BOTH: _ZTSP1C = [[LINKONCE_VIS_CONSTANT]]
+// CHECK-BOTH: _ZTS1C = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTI1C = internal constant
 // CHECK-BOTH: _ZTIP1C = internal constant
-// CHECK-BOTH: _ZTSPP1C = internal constant
+// CHECK-BOTH: _ZTSPP1C = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIPP1C = internal constant
-// CHECK-BOTH: _ZTSM1Ci = internal constant
+// CHECK-BOTH: _ZTSM1Ci = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1Ci = internal constant
-// CHECK-BOTH: _ZTSPM1Ci = internal constant
+// CHECK-BOTH: _ZTSPM1Ci = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIPM1Ci = internal constant
-// CHECK-BOTH: _ZTSM1CS_ = internal constant
+// CHECK-BOTH: _ZTSM1CS_ = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1CS_ = internal constant
-// CHECK-BOTH: _ZTSM1CPS_ = internal constant
+// CHECK-BOTH: _ZTSM1CPS_ = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1CPS_ = internal constant
-// CHECK-BOTH: _ZTSM1A1C = internal constant
-// CHECK: _ZTS1A = linkonce_odr constant
-// CHECK-WITH-HIDDEN: _ZTS1A = linkonce_odr hidden constant
-// CHECK: _ZTI1A = linkonce_odr constant
-// CHECK-WITH-HIDDEN: _ZTI1A = linkonce_odr hidden constant
+// CHECK-BOTH: _ZTSM1A1C = [[LINKONCE_VIS_CONSTANT]]
+// CHECK-BOTH: _ZTS1A = [[LINKONCE_VIS_CONSTANT]]
+// CHECK-BOTH: _ZTI1A = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1A1C = internal constant
-// CHECK-BOTH: _ZTSM1AP1C = internal constant
+// CHECK-BOTH: _ZTSM1AP1C = [[LINKONCE_VIS_CONSTANT]]
 // CHECK-BOTH: _ZTIM1AP1C = internal constant
 
 // CHECK-WITH-HIDDEN: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
@@ -52,6 +54,12 @@
 // CHECK: _ZTSFvvE = linkonce_odr constant
 // CHECK: _ZTIFvvE = linkonce_odr constant
 // CHECK: _ZTIPFvvE = linkonce_odr constant
+// CHECK: _ZTSPN12_GLOBAL__N_12DIE = internal constant
+// CHECK: _ZTSN12_GLOBAL__N_12DIE = internal constant
+// CHECK: _ZTIN12_GLOBAL__N_12DIE = internal constant
+// CHECK: _ZTIPN12_GLOBAL__N_12DIE = internal constant
+// CHECK: _ZTSMN12_GLOBAL__N_12DIEFvvE = internal constant
+// CHECK: _ZTIMN12_GLOBAL__N_12DIEFvvE = internal constant
 // CHECK: _ZTSN12_GLOBAL__N_11EE = internal constant
 // CHECK: _ZTIN12_GLOBAL__N_11EE = internal constant
 // CHECK: _ZTSA10_i = linkonce_odr constant
@@ -99,9 +107,10 @@
 }
 
 namespace {
-  // D is inside an anonymous namespace, so all type information related to D should have
-  // internal linkage.
+// D and DI are inside an anonymous namespace, so all type information related
+// to both should have internal linkage.
 struct D {};
+struct DI;
 
 // E is also inside an anonymous namespace.
 enum E {};
@@ -127,6 +136,9 @@
   // internal linkage.
   (void)typeid(void (*)() throw (D));
 
+  (void)typeid(DI *);
+  (void)typeid(void (DI::*)());
+
   (void)typeid(E);
   
   return typeid(getD());  
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -3008,8 +3008,8 @@
 
 /// \brief Return the linkage that the type info and type info name constants
 /// should have for the given type.
-static llvm::GlobalVariable::LinkageTypes getTypeInfoLinkage(CodeGenModule &CGM,
- QualType Ty) {
+static llvm::GlobalVariable::LinkageTypes
+getTypeInfoLinkage(CodeGenModule &CGM, QualType Ty, bool ForName = false) {
   // Itanium C++ ABI 2.9.5p7:
   //   In addition, it and all of the intermediate abi::__pointer_type_info
   //

[PATCH] D46670: [clangd] Move helpers that convert Replacements to TextEdits to SourceCode.h

2018-05-09 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, jkorous, MaskRay, klimek.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46670

Files:
  clangd/ClangdLSPServer.cpp
  clangd/SourceCode.cpp
  clangd/SourceCode.h


Index: clangd/SourceCode.h
===
--- clangd/SourceCode.h
+++ clangd/SourceCode.h
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H
 #include "Protocol.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Core/Replacement.h"
 
 namespace clang {
 class SourceManager;
@@ -54,6 +55,14 @@
 /// qualifier.
 std::pair
 splitQualifiedName(llvm::StringRef QName);
+TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R);
+
+std::vector
+replacementsToEdits(StringRef Code,
+const std::vector &Replacements);
+
+std::vector replacementsToEdits(StringRef Code,
+  const tooling::Replacements &Repls);
 
 } // namespace clangd
 } // namespace clang
Index: clangd/SourceCode.cpp
===
--- clangd/SourceCode.cpp
+++ clangd/SourceCode.cpp
@@ -166,5 +166,31 @@
   return {QName.substr(0, Pos + 2), QName.substr(Pos + 2)};
 }
 
+TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R) {
+  Range ReplacementRange = {
+  offsetToPosition(Code, R.getOffset()),
+  offsetToPosition(Code, R.getOffset() + R.getLength())};
+  return {ReplacementRange, R.getReplacementText()};
+}
+
+std::vector
+replacementsToEdits(StringRef Code,
+const std::vector &Replacements) {
+  // Turn the replacements into the format specified by the Language Server
+  // Protocol. Fuse them into one big JSON array.
+  std::vector Edits;
+  for (const auto &R : Replacements)
+Edits.push_back(replacementToEdit(Code, R));
+  return Edits;
+}
+
+std::vector replacementsToEdits(StringRef Code,
+  const tooling::Replacements &Repls) {
+  std::vector Edits;
+  for (const auto &R : Repls)
+Edits.push_back(replacementToEdit(Code, R));
+  return Edits;
+}
+
 } // namespace clangd
 } // namespace clang
Index: clangd/ClangdLSPServer.cpp
===
--- clangd/ClangdLSPServer.cpp
+++ clangd/ClangdLSPServer.cpp
@@ -60,32 +60,6 @@
 static URISchemeRegistry::Add
 X("test", "Test scheme for clangd lit tests.");
 
-TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R) {
-  Range ReplacementRange = {
-  offsetToPosition(Code, R.getOffset()),
-  offsetToPosition(Code, R.getOffset() + R.getLength())};
-  return {ReplacementRange, R.getReplacementText()};
-}
-
-std::vector
-replacementsToEdits(StringRef Code,
-const std::vector &Replacements) {
-  // Turn the replacements into the format specified by the Language Server
-  // Protocol. Fuse them into one big JSON array.
-  std::vector Edits;
-  for (const auto &R : Replacements)
-Edits.push_back(replacementToEdit(Code, R));
-  return Edits;
-}
-
-std::vector replacementsToEdits(StringRef Code,
-  const tooling::Replacements &Repls) {
-  std::vector Edits;
-  for (const auto &R : Repls)
-Edits.push_back(replacementToEdit(Code, R));
-  return Edits;
-}
-
 SymbolKindBitset defaultSymbolKinds() {
   SymbolKindBitset Defaults;
   for (size_t I = SymbolKindMin; I <= static_cast(SymbolKind::Array);


Index: clangd/SourceCode.h
===
--- clangd/SourceCode.h
+++ clangd/SourceCode.h
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H
 #include "Protocol.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Core/Replacement.h"
 
 namespace clang {
 class SourceManager;
@@ -54,6 +55,14 @@
 /// qualifier.
 std::pair
 splitQualifiedName(llvm::StringRef QName);
+TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R);
+
+std::vector
+replacementsToEdits(StringRef Code,
+const std::vector &Replacements);
+
+std::vector replacementsToEdits(StringRef Code,
+  const tooling::Replacements &Repls);
 
 } // namespace clangd
 } // namespace clang
Index: clangd/SourceCode.cpp
===
--- clangd/SourceCode.cpp
+++ clangd/SourceCode.cpp
@@ -166,5 +166,31 @@
   return {QName.substr(0, Pos + 2), QName.substr(Pos + 2)};
 }
 
+TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R) {
+  Range ReplacementRange = {
+  offsetToPosition(Code, R.getOffset()),
+  offsetToPosition(Code, R.getOffset() + R.getLength())};
+  return {ReplacementRange, R.getReplacementText()};
+}
+
+std::vector
+replacementsToEdits(StringRef Code,
+const st

[PATCH] D46497: [clangd] Populate #include insertions as additional edits in completion items.

2018-05-09 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 146046.
ioeric added a comment.

- Minor cleanup


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46497

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/Headers.cpp
  clangd/Headers.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/SourceCode.cpp
  clangd/SourceCode.h
  clangd/XRefs.cpp
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test
  test/clangd/insert-include.test
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/HeadersTests.cpp

Index: unittests/clangd/HeadersTests.cpp
===
--- unittests/clangd/HeadersTests.cpp
+++ unittests/clangd/HeadersTests.cpp
@@ -8,38 +8,96 @@
 //===--===//
 
 #include "Headers.h"
+
+#include "Compiler.h"
 #include "TestFS.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Lex/PreprocessorOptions.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
 namespace {
 
+using ::testing::AllOf;
+using ::testing::UnorderedElementsAre;
+
 class HeadersTest : public ::testing::Test {
 public:
   HeadersTest() {
 CDB.ExtraClangFlags = {SearchDirArg.c_str()};
 FS.Files[MainFile] = "";
+// Make sure directory sub/ exists.
+FS.Files[testPath("sub/EMPTY")] = "";
+  }
+
+private:
+  std::unique_ptr setupClang() {
+auto Cmd = CDB.getCompileCommand(MainFile);
+assert(static_cast(Cmd));
+auto VFS = FS.getFileSystem();
+VFS->setCurrentWorkingDirectory(Cmd->Directory);
+
+std::vector Argv;
+for (const auto &S : Cmd->CommandLine)
+  Argv.push_back(S.c_str());
+auto CI = clang::createInvocationFromCommandLine(
+Argv,
+CompilerInstance::createDiagnostics(new DiagnosticOptions(),
+&IgnoreDiags, false),
+VFS);
+EXPECT_TRUE(static_cast(CI));
+CI->getFrontendOpts().DisableFree = false;
+
+// The diagnostic options must be set before creating a CompilerInstance.
+CI->getDiagnosticOpts().IgnoreWarnings = true;
+auto Clang = prepareCompilerInstance(
+std::move(CI), /*Preamble=*/nullptr,
+llvm::MemoryBuffer::getMemBuffer(FS.Files[MainFile], MainFile),
+std::make_shared(), VFS, IgnoreDiags);
+
+EXPECT_FALSE(Clang->getFrontendOpts().Inputs.empty());
+return Clang;
   }
 
 protected:
+  std::vector collectIncludes() {
+auto Clang = setupClang();
+PreprocessOnlyAction Action;
+EXPECT_TRUE(
+Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]));
+std::vector Inclusions;
+Clang->getPreprocessor().addPPCallbacks(collectInclusionsInMainFileCallback(
+Clang->getSourceManager(), Inclusions));
+EXPECT_TRUE(Action.Execute());
+Action.EndSourceFile();
+return Inclusions;
+  }
+
   // Calculates the include path, or returns "" on error.
   std::string calculate(PathRef Original, PathRef Preferred = "",
+const std::vector &Inclusions = {},
 bool ExpectError = false) {
+auto Clang = setupClang();
+PreprocessOnlyAction Action;
+EXPECT_TRUE(
+Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]));
+
 if (Preferred.empty())
   Preferred = Original;
-auto VFS = FS.getFileSystem();
-auto Cmd = CDB.getCompileCommand(MainFile);
-assert(static_cast(Cmd));
-VFS->setCurrentWorkingDirectory(Cmd->Directory);
 auto ToHeaderFile = [](llvm::StringRef Header) {
   return HeaderFile{Header,
 /*Verbatim=*/!llvm::sys::path::is_absolute(Header)};
 };
-auto Path = calculateIncludePath(MainFile, FS.Files[MainFile],
- ToHeaderFile(Original),
- ToHeaderFile(Preferred), *Cmd, VFS);
+
+auto Path = calculateIncludePath(
+MainFile, CDB.getCompileCommand(MainFile)->Directory,
+Clang->getPreprocessor().getHeaderSearchInfo(), Inclusions,
+ToHeaderFile(Original), ToHeaderFile(Preferred));
+Action.EndSourceFile();
 if (!Path) {
   llvm::consumeError(Path.takeError());
   EXPECT_TRUE(ExpectError);
@@ -49,52 +107,31 @@
 }
 return std::move(*Path);
   }
+
   MockFSProvider FS;
   MockCompilationDatabase CDB;
   std::string MainFile = testPath("main.cpp");
   std::string Subdir = testPath("sub");
   std::string SearchDirArg = (llvm::Twine("-I") + Subdir).str();
+  IgnoringDiagConsumer IgnoreDiags;
 };
 
-TEST_F(HeadersTest, InsertInclude) {
-  std::string Path = testPath("sub/bar.h");
-  FS.Files[Path] = "";
-  EXPECT_EQ(c

[PATCH] D46497: [clangd] Populate #include insertions as additional edits in completion items.

2018-05-09 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

In https://reviews.llvm.org/D46497#1089755, @sammccall wrote:

> I'm concerned about the scope of this patch - it does too many things and 
> touches too many files for me to feel comfortable that I understand it well 
> enough to review.
>  Is it possible to split it up? (You mention 6 distinct things in the 
> description).


Sorry about the big change! And thanks for the early feedback on headers 
library!

I think there are a few things going on here:

1. Removing the existing way of include insertion (additional command)
2. Populating #include insertion in code completion workflow.
3. Refactoring #include path calculation to make 2 work
4. Move some helpers (e.g. replacementToEdit) to public header.
5. Share InclusionLocation between preamble code and header insertion code.

I was trying to keep 1 and 2 in the same patch so that we don't regress 
features, but it's probably fine if no one is actually using it... I'm happy to 
split that out if having them in the same patch makes review hard.

I think 2 and 3 could stay in the same patch as it would be hard to see where 
the design in 3 came from without 2. But if you got the idea, I guess they 
could still be split.

4 and 5 should be independent enough to be 2 separate patches. I thought the 
changes were small and could be included in this patch. I'll split them as well 
now that you mention.




Comment at: clangd/Headers.h:1
 //===--- Headers.h - Include headers -*- 
C++-*-===//
 //

sammccall wrote:
> The interface to this header looks a bit complex and entangled after this 
> change.
> - The construction/lifecycle of IncludePaths is confusing (comments below)
> - here we provide all the information needed to compute the edits (style, 
> code...) but don't actually do so
> 
> it would be nice to achieve a simpler interface with the restricted set of 
> functionality, or expand the functionality...
Refactored code according to your suggestions. PTAL

> here we provide all the information needed to compute the edits (style, 
> code...) but don't actually do so
Sorry... forgot to delete some leftover after an earlier revision. 



Comment at: clangd/Headers.h:29
 
+// A header inclusion in the main file.
+struct InclusionLocation {

sammccall wrote:
> I had some trouble working out the role of this struct (e.g. that it might 
> have been a *proposed* inclusion).
> Strictly it's not just the location, but also identifies the header being 
> included.
> 
> So this could maybe be
> ```
> // An #include directive that we found in the main file.
> struct Inclusion
> ```
> 
> but it does also seem a little strange that this is part of the public 
> interface at all (other than for testing)
Thanks! `Inclusion` sounds better.

Apart from header insertion and testing, this is also shared with the preamble 
code.



Comment at: clangd/Headers.h:57
+/// preprocessor and build configs.
+class IncludePaths {
+public:

sammccall wrote:
> This name suggests a set or sequence of include path entries (`-I` flags).
> Can we merge this with `IncludeInsertion` and call it `IncludeInserter` or 
> similar?
I think there are three pretty independent parts of include insertion:
1. URI/Verbatim to `HeaderFile` conversion (which lives in HeaderInsertion in 
CodeComplete.cpp right now).
2. Calculate include paths based on existing inclusions and HeaderSearch.
3. Calculate include insertion edits using `tooling::HeaderIncludes`.

Initially, I grouped all these in one class (something like `HeaderInsertion`) 
which returns an edit given the URIs in the symbol info, but it turned out to 
be hard to test. For example, among all 3 components, 2 was the most 
interesting piece to test, while an integration test is probably enough for 1 
and 3, but we would need to create URIs (due to 1) and retrieve include name 
from edits (due to 3) in order to test 2. Since each individual piece seemed 
independent enough, I decided to keep them separated. I also kept URI logic out 
of the header library so that it could potentially be shared with other 
features that are not index-based include insertion, or be moved out of clangd 
as a tooling library. 

In the new revision, I refactored the code according to your suggestions and 
got rid of this class.



Comment at: clangd/Headers.h:60
+  /// This must be called before preprocessor is run (this registers a
+  /// PPCallback on \p PP).
+  /// \p SM is used in the PPCallbacks to filter source locations in main file.

sammccall wrote:
> hmm, if we require the InclusionLocations to be prebuilt for the preamble, 
> why can't we do the same for non-preamble includes? i.e. can't we split up 
> the "collect existing includes" and "calculate new includes" parts to 
> simplify the interface here? Among other things, testing would be a ton 
> easier.
Good idea! 


==

[PATCH] D46497: [clangd] Populate #include insertions as additional edits in completion items.

2018-05-09 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 146045.
ioeric marked 15 inline comments as done.
ioeric added a comment.

- Merged with origin/master
- Address review comments.
- Revert unintended change.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46497

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/Headers.cpp
  clangd/Headers.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/SourceCode.cpp
  clangd/SourceCode.h
  clangd/XRefs.cpp
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test
  test/clangd/insert-include.test
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/HeadersTests.cpp

Index: unittests/clangd/HeadersTests.cpp
===
--- unittests/clangd/HeadersTests.cpp
+++ unittests/clangd/HeadersTests.cpp
@@ -8,38 +8,96 @@
 //===--===//
 
 #include "Headers.h"
+
+#include "Compiler.h"
 #include "TestFS.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Lex/PreprocessorOptions.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
 namespace {
 
+using ::testing::AllOf;
+using ::testing::UnorderedElementsAre;
+
 class HeadersTest : public ::testing::Test {
 public:
   HeadersTest() {
 CDB.ExtraClangFlags = {SearchDirArg.c_str()};
 FS.Files[MainFile] = "";
+// Make sure directory sub/ exists.
+FS.Files[testPath("sub/EMPTY")] = "";
+  }
+
+private:
+  std::unique_ptr setupClang() {
+auto Cmd = CDB.getCompileCommand(MainFile);
+assert(static_cast(Cmd));
+auto VFS = FS.getFileSystem();
+VFS->setCurrentWorkingDirectory(Cmd->Directory);
+
+std::vector Argv;
+for (const auto &S : Cmd->CommandLine)
+  Argv.push_back(S.c_str());
+auto CI = clang::createInvocationFromCommandLine(
+Argv,
+CompilerInstance::createDiagnostics(new DiagnosticOptions(),
+&IgnoreDiags, false),
+VFS);
+EXPECT_TRUE(static_cast(CI));
+CI->getFrontendOpts().DisableFree = false;
+
+// The diagnostic options must be set before creating a CompilerInstance.
+CI->getDiagnosticOpts().IgnoreWarnings = true;
+auto Clang = prepareCompilerInstance(
+std::move(CI), /*Preamble=*/nullptr,
+llvm::MemoryBuffer::getMemBuffer(FS.Files[MainFile], MainFile),
+std::make_shared(), VFS, IgnoreDiags);
+
+EXPECT_FALSE(Clang->getFrontendOpts().Inputs.empty());
+return Clang;
   }
 
 protected:
+  std::vector collectIncludes() {
+auto Clang = setupClang();
+PreprocessOnlyAction Action;
+EXPECT_TRUE(
+Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]));
+std::vector Inclusions;
+Clang->getPreprocessor().addPPCallbacks(collectInclusionsInMainFileCallback(
+Clang->getSourceManager(), Inclusions));
+EXPECT_TRUE(Action.Execute());
+Action.EndSourceFile();
+return Inclusions;
+  }
+
   // Calculates the include path, or returns "" on error.
   std::string calculate(PathRef Original, PathRef Preferred = "",
+const std::vector &Inclusions = {},
 bool ExpectError = false) {
+auto Clang = setupClang();
+PreprocessOnlyAction Action;
+EXPECT_TRUE(
+Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]));
+
 if (Preferred.empty())
   Preferred = Original;
-auto VFS = FS.getFileSystem();
-auto Cmd = CDB.getCompileCommand(MainFile);
-assert(static_cast(Cmd));
-VFS->setCurrentWorkingDirectory(Cmd->Directory);
 auto ToHeaderFile = [](llvm::StringRef Header) {
   return HeaderFile{Header,
 /*Verbatim=*/!llvm::sys::path::is_absolute(Header)};
 };
-auto Path = calculateIncludePath(MainFile, FS.Files[MainFile],
- ToHeaderFile(Original),
- ToHeaderFile(Preferred), *Cmd, VFS);
+
+auto Path = calculateIncludePath(
+MainFile, CDB.getCompileCommand(MainFile)->Directory,
+Clang->getPreprocessor().getHeaderSearchInfo(), Inclusions,
+ToHeaderFile(Original), ToHeaderFile(Preferred));
+Action.EndSourceFile();
 if (!Path) {
   llvm::consumeError(Path.takeError());
   EXPECT_TRUE(ExpectError);
@@ -49,52 +107,31 @@
 }
 return std::move(*Path);
   }
+
   MockFSProvider FS;
   MockCompilationDatabase CDB;
   std::string MainFile = testPath("main.cpp");
   std::string Subdir = testPath("sub");
   std::string SearchDirArg = (llvm::Twine("-I") + Subdir).str();
+  IgnoringDiagConsumer IgnoreDiags;
 };
 
-TEST_F(Head

[PATCH] D46665: [Itanium] Emit type info names with external linkage.

2018-05-09 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF marked an inline comment as done.
EricWF added a comment.

@rsmith What should the visibility of the type name be in cases where the type 
info is hidden?




Comment at: lib/CodeGen/ItaniumCXXABI.cpp:3033
+  return {llvm::GlobalValue::InternalLinkage,
+  llvm::GlobalValue::LinkOnceODRLinkage};
+return {llvm::GlobalValue::InternalLinkage,

rsmith wrote:
> Shouldn't this be based on the type's linkage? Eg:
> 
> ```
> namespace { struct Incomplete; }
> auto x = typeid(Incomplete*);
> ```
> 
> should have an `internal` type info name, not a `linkonce_odr` name. I think 
> we should compute the linkage per the code below and then demote the type's 
> linkage to internal in the incomplete-class case.
That sounds correct to me.



Comment at: lib/CodeGen/ItaniumCXXABI.cpp:3034-3035
+  llvm::GlobalValue::LinkOnceODRLinkage};
+return {llvm::GlobalValue::InternalLinkage,
+llvm::GlobalValue::InternalLinkage};
+  }

rsmith wrote:
> Should we promote the type info name in this case too? (We get here for the 
> incomplete-class type info we generate as a detail of the pointer type info, 
> but the names of such types are accessible via the  interface, so 
> it seems reasonable to apply the same global-uniqueness to them too.)
Hmm. I think it seems reasonable.

I don't think there exists a case where a user can perform `type_info` equality 
or hashing on an incomplete class type,  so in terms of solving the libc++ bug 
I think it's unneeded. (which is why I omitted it).

I also don't see exactly what part of `cxxabi.h` might expose the `type_info` 
to users in a way where type name pointer equality is important to the user.

What would you rather?



https://reviews.llvm.org/D46665



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


[PATCH] D43320: Allow dllimport non-type template arguments in C++17

2018-05-09 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/AST/ExprConstant.cpp:1871-1902
   if (!CheckConstantExpression(Info, DiagLoc, EltTy,
Value.getArrayInitializedElt(I)))
 return false;
 }
 if (!Value.hasArrayFiller())
   return true;
 return CheckConstantExpression(Info, DiagLoc, EltTy,

`Usage`  should be passed into these recursive calls to 
`CheckConstantExpression`, although that's NFC for now, until/unless we start 
allowing class types as template parameters.


https://reviews.llvm.org/D43320



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


[PATCH] D46496: [Tooling] Pull #include manipulation code from clangFormat into libToolingCore.

2018-05-09 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 146042.
ioeric added a comment.

- Merged with origin/master


Repository:
  rC Clang

https://reviews.llvm.org/D46496

Files:
  include/clang/Format/Format.h
  include/clang/Tooling/Core/HeaderIncludes.h
  lib/Format/Format.cpp
  lib/Tooling/Core/CMakeLists.txt
  lib/Tooling/Core/HeaderIncludes.cpp
  unittests/Format/CleanupTest.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/SortIncludesTest.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/HeaderIncludesTest.cpp

Index: unittests/Tooling/HeaderIncludesTest.cpp
===
--- /dev/null
+++ unittests/Tooling/HeaderIncludesTest.cpp
@@ -0,0 +1,527 @@
+//===- unittest/Tooling/CleanupTest.cpp - Include insertion/deletion tests ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Tooling/Core/HeaderIncludes.h"
+#include "../Tooling/ReplacementTest.h"
+#include "../Tooling/RewriterTestContext.h"
+#include "clang/Format/Format.h"
+#include "clang/Tooling/Core/Replacement.h"
+
+#include "gtest/gtest.h"
+
+using clang::tooling::ReplacementTest;
+using clang::tooling::toReplacements;
+
+namespace clang {
+namespace tooling {
+namespace {
+
+class HeaderIncludesTest : public ::testing::Test {
+protected:
+  std::string insert(llvm::StringRef Code, llvm::StringRef Header) {
+HeaderIncludes Includes(FileName, Code, Style);
+assert(Header.startswith("\"") || Header.startswith("<"));
+auto R = Includes.insert(Header.trim("\"<>"), Header.startswith("<"));
+if (!R)
+  return Code;
+auto Result = applyAllReplacements(Code, Replacements(*R));
+EXPECT_TRUE(static_cast(Result));
+return *Result;
+  }
+
+  std::string remove(llvm::StringRef Code, llvm::StringRef Header) {
+HeaderIncludes Includes(FileName, Code, Style);
+assert(Header.startswith("\"") || Header.startswith("<"));
+auto Replaces = Includes.remove(Header.trim("\"<>"), Header.startswith("<"));
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+return *Result;
+  }
+
+  const std::string FileName = "fix.cpp";
+  IncludeStyle Style = format::getLLVMStyle().IncludeStyle;
+};
+
+TEST_F(HeaderIncludesTest, NoExistingIncludeWithoutDefine) {
+  std::string Code = "int main() {}";
+  std::string Expected = "#include \"a.h\"\n"
+ "int main() {}";
+  EXPECT_EQ(Expected, insert(Code, "\"a.h\""));
+}
+
+TEST_F(HeaderIncludesTest, NoExistingIncludeWithDefine) {
+  std::string Code = "#ifndef A_H\n"
+ "#define A_H\n"
+ "class A {};\n"
+ "#define MMM 123\n"
+ "#endif";
+  std::string Expected = "#ifndef A_H\n"
+ "#define A_H\n"
+ "#include \"b.h\"\n"
+ "class A {};\n"
+ "#define MMM 123\n"
+ "#endif";
+
+  EXPECT_EQ(Expected, insert(Code, "\"b.h\""));
+}
+
+TEST_F(HeaderIncludesTest, InsertBeforeCategoryWithLowerPriority) {
+  std::string Code = "#ifndef A_H\n"
+ "#define A_H\n"
+ "\n"
+ "\n"
+ "\n"
+ "#include \n"
+ "class A {};\n"
+ "#define MMM 123\n"
+ "#endif";
+  std::string Expected = "#ifndef A_H\n"
+ "#define A_H\n"
+ "\n"
+ "\n"
+ "\n"
+ "#include \"a.h\"\n"
+ "#include \n"
+ "class A {};\n"
+ "#define MMM 123\n"
+ "#endif";
+
+  EXPECT_EQ(Expected, insert(Code, "\"a.h\""));
+}
+
+TEST_F(HeaderIncludesTest, InsertAfterMainHeader) {
+  std::string Code = "#include \"fix.h\"\n"
+ "\n"
+ "int main() {}";
+  std::string Expected = "#include \"fix.h\"\n"
+ "#include \n"
+ "\n"
+ "int main() {}";
+  Style = format::getGoogleStyle(format::FormatStyle::LanguageKind::LK_Cpp)
+  .IncludeStyle;
+  EXPECT_EQ(Expected, insert(Code, ""));
+}
+
+TEST_F(HeaderIncludesTest, InsertBeforeSystemHeaderLLVM) {
+  std::string Code = "#include \n"
+ "\n"
+ "int main() {}";
+  std::string Expected = "#include \"z.h\"\n"
+ "#include \n"
+ "\n"
+ "int main() {}";
+  EXPECT_EQ(Expected, insert(Code, "\"z.h\""));
+}
+
+TEST_F(HeaderIncludesTest, InsertAfterSystemHeaderGoogle) {
+  std::strin

[PATCH] D46667: [OpenCL, OpenMP] Fix crash when OpenMP used in OpenCL file

2018-05-09 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

1. Is this allowed to use OpenMP for OpenCL programs at all?
2. If it is allowed, I think it would be better to set the TypeSourceInfo for 
the artificial variable


Repository:
  rC Clang

https://reviews.llvm.org/D46667



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


[PATCH] D46667: [OpenCL, OpenMP] Fix crash when OpenMP used in OpenCL file

2018-05-09 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

BTW, the test itself does not check anything.


Repository:
  rC Clang

https://reviews.llvm.org/D46667



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


[PATCH] D46664: Fix null MSInheritanceAttr deref in CXXRecordDecl::getMSInheritanceModel()

2018-05-09 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Is it possible to fix this in assignInheritanceModel instead? I'd imagine we'd 
get the most recent decl. If that's not the issue, maybe you're fixing the bug 
in the right spot, but we need to find out where other class template 
attributes are moved from instantiation to real declaration.




Comment at: lib/Sema/SemaTemplate.cpp:7079
 
+void Sema::CheckCXXRecordDecl(CXXRecordDecl *Record, CXXRecordDecl *Prev)
+{

This seems like an overly-generic name for what it does, which currently is 
specific to class template instantiations.


Repository:
  rC Clang

https://reviews.llvm.org/D46664



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


[PATCH] D43320: Allow dllimport non-type template arguments in C++17

2018-05-09 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: clang/include/clang/AST/Expr.h:662
+  /// Indicates how the constant expression will be used.
+  enum ConstExprUsage { EvaluateForCodeGen, EvaluateForMangling };
+

I expect we could come up with a better name, but is this closer to what you 
had in mind?


https://reviews.llvm.org/D43320



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


[PATCH] D43320: Allow dllimport non-type template arguments in C++17

2018-05-09 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 146039.
rnk added a comment.

- getting closer


https://reviews.llvm.org/D43320

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/dllimport-constexpr.cpp
  clang/test/SemaCXX/dllimport-memptr.cpp

Index: clang/test/SemaCXX/dllimport-memptr.cpp
===
--- clang/test/SemaCXX/dllimport-memptr.cpp
+++ clang/test/SemaCXX/dllimport-memptr.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -verify -std=c++17 %s
 
 // expected-no-diagnostics
 
Index: clang/test/SemaCXX/dllimport-constexpr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/dllimport-constexpr.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -std=c++14 %s -verify -fms-extensions -triple x86_64-windows-msvc
+// RUN: %clang_cc1 -std=c++17 %s -verify -fms-extensions -triple x86_64-windows-msvc
+
+__declspec(dllimport) void imported_func();
+__declspec(dllimport) int imported_int;
+struct Foo {
+  void __declspec(dllimport) imported_method();
+};
+
+// Instantiation is OK.
+template  struct TemplateFnPtr {
+  static void getit() { FP(); }
+};
+template  struct TemplateFnRef {
+  static void getit() { FP(); }
+};
+void instantiate1() {
+  TemplateFnPtr<&imported_func>::getit();
+  TemplateFnRef::getit();
+}
+
+// Check variable template instantiation.
+template  struct TemplateIntPtr {
+  static int getit() { return *GI; }
+};
+template  struct TemplateIntRef {
+  static int getit() { return GI; }
+};
+int instantiate2() {
+  int r = 0;
+  r += TemplateIntPtr<&imported_int>::getit();
+  r += TemplateIntRef::getit();
+  return r;
+}
+
+// Member pointer instantiation.
+template  struct TemplateMemPtr { };
+TemplateMemPtr<&Foo::imported_method> instantiate_mp;
+
+// constexpr initialization doesn't work for dllimport things.
+// expected-error@+1{{must be initialized by a constant expression}}
+constexpr void (*constexpr_import_func)() = &imported_func;
+// expected-error@+1{{must be initialized by a constant expression}}
+constexpr int *constexpr_import_int = &imported_int;
+// expected-error@+1{{must be initialized by a constant expression}}
+constexpr void (Foo::*constexpr_memptr)() = &Foo::imported_method;
+
+// We make dynamic initializers for 'const' globals, but not constexpr ones.
+void (*const const_import_func)() = &imported_func;
+int *const const_import_int = &imported_int;
+void (Foo::*const const_memptr)() = &Foo::imported_method;
+
+// Check that using a non-type template parameter for constexpr global
+// initialization is correctly diagnosed during template instantiation.
+template  struct StaticConstexpr {
+  // expected-error@+1{{must be initialized by a constant expression}}
+  static constexpr void (*g_fp)() = FP;
+};
+void instantiate3() {
+  // expected-note@+1 {{requested here}}
+  StaticConstexpr::g_fp();
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -5407,10 +5407,11 @@
   SmallVector Notes;
   Expr::EvalResult Eval;
   Eval.Diag = &Notes;
+  Expr::ConstExprUsage Usage = CCE == Sema::CCEK_TemplateArg
+   ? Expr::EvaluateForMangling
+   : Expr::EvaluateForCodeGen;
 
-  if ((T->isReferenceType()
-   ? !Result.get()->EvaluateAsLValue(Eval, S.Context)
-   : !Result.get()->EvaluateAsRValue(Eval, S.Context)) ||
+  if (!Result.get()->EvaluateAsConstantExpr(Eval, Usage, S.Context) ||
   (RequireInt && !Eval.Val.isInt())) {
 // The expression can't be folded, so we can't keep it at this position in
 // the AST.
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -1720,7 +1720,8 @@
 /// value for an address or reference constant expression. Return true if we
 /// can fold this expression, whether or not it's a constant expression.
 static bool CheckLValueConstantExpression(EvalInfo &Info, SourceLocation Loc,
-  QualType Type, const LValue &LVal) {
+  QualType Type, const LValue &LVal,
+  Expr::ConstExprUsage Usage) {
   bool IsReferenceType = Type->isReferenceType();
 
   APValue::LValueBase Base = LVal.getLValueBase();
@@ -1753,7 +1754,7 @@
 return false;
 
   // A dllimport variable never acts like a constant.
-  if (Var->hasAttr())
+  if (Usage == Expr::EvaluateForCodeGen && Var->hasAttr())
 return false;
 }
 if (const auto *FD = dyn_cast(VD)) {
@@ -1767,7 +1768,8 @@
   // The C language has 

[libcxx] r331910 - Allow copy elision in path concatenation

2018-05-09 Thread David Bolvansky via cfe-commits
Author: xbolva00
Date: Wed May  9 11:57:17 2018
New Revision: 331910

URL: http://llvm.org/viewvc/llvm-project?rev=331910&view=rev
Log:
Allow copy elision in path concatenation

Summary:
Just port of libstdc++'s fix to libc++ fs: 
https://github.com/gcc-mirror/gcc/commit/e6ac4004fe49d785c63bf87aec4b095b5ce1d19f

Author of fix: Jonathan Wakely

Reviewers: EricWF, mclow.lists

Reviewed By: EricWF

Subscribers: smeenai, christof, cfe-commits, llvm-commits

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

Modified:
libcxx/trunk/include/experimental/filesystem

Modified: libcxx/trunk/include/experimental/filesystem
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/filesystem?rev=331910&r1=331909&r2=331910&view=diff
==
--- libcxx/trunk/include/experimental/filesystem (original)
+++ libcxx/trunk/include/experimental/filesystem Wed May  9 11:57:17 2018
@@ -1140,7 +1140,9 @@ bool operator>=(const path& __lhs, const
 
 inline _LIBCPP_INLINE_VISIBILITY
 path operator/(const path& __lhs, const path& __rhs) {
-return path(__lhs) /= __rhs;
+path __result(__lhs);
+__result /= __rhs;
+return __result;
 }
 
 template 


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


[PATCH] D46667: [OpenCL, OpenMP] Fix crash when OpenMP used in OpenCL file

2018-05-09 Thread Mike Rice via Phabricator via cfe-commits
mikerice created this revision.
mikerice added reviewers: Anastasia, ABataev, erichkeane, cfe-commits.
Herald added subscribers: guansong, yaxunl.

Compiler crashes when omp simd is used in an OpenCL file:

clang -c -fopenmp omp_simd.cl

__kernel void test(__global int *data, int size) {

  #pragma omp simd
  for (int i = 0; i < size; ++i) {
  }

}

The problem seems to be the check added to verify block pointers have 
initializers.  An OMPCapturedExprDecl is created to capture ‘size’ but there is 
no TypeSourceInfo.

The change just uses getType() directly.


Repository:
  rC Clang

https://reviews.llvm.org/D46667

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaOpenCL/omp_simd.cl


Index: test/SemaOpenCL/omp_simd.cl
===
--- /dev/null
+++ test/SemaOpenCL/omp_simd.cl
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -verify -fopenmp -fsyntax-only -x cl %s
+// expected-no-diagnostics
+
+__kernel void test(__global int *data, int size) {
+  #pragma omp simd
+  for (int i = 0; i < size; ++i) {
+  }
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -11345,8 +11345,7 @@
   if (getLangOpts().OpenCL) {
 // OpenCL v2.0 s6.12.5 - Every block variable declaration must have an
 // initialiser
-if (var->getTypeSourceInfo()->getType()->isBlockPointerType() &&
-!var->hasInit()) {
+if (var->getType()->isBlockPointerType() && !var->hasInit()) {
   Diag(var->getLocation(), diag::err_opencl_invalid_block_declaration)
   << 1 /*Init*/;
   var->setInvalidDecl();


Index: test/SemaOpenCL/omp_simd.cl
===
--- /dev/null
+++ test/SemaOpenCL/omp_simd.cl
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -verify -fopenmp -fsyntax-only -x cl %s
+// expected-no-diagnostics
+
+__kernel void test(__global int *data, int size) {
+  #pragma omp simd
+  for (int i = 0; i < size; ++i) {
+  }
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -11345,8 +11345,7 @@
   if (getLangOpts().OpenCL) {
 // OpenCL v2.0 s6.12.5 - Every block variable declaration must have an
 // initialiser
-if (var->getTypeSourceInfo()->getType()->isBlockPointerType() &&
-!var->hasInit()) {
+if (var->getType()->isBlockPointerType() && !var->hasInit()) {
   Diag(var->getLocation(), diag::err_opencl_invalid_block_declaration)
   << 1 /*Init*/;
   var->setInvalidDecl();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46656: [Builtins] Improve the IR emitted for MSVC compatible rotr/rotl builtins to match what the middle and backends understand

2018-05-09 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331943: [Builtins] Improve the IR emitted for MSVC 
compatible rotr/rotl builtins to… (authored by ctopper, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46656?vs=145979&id=146036#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46656

Files:
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c

Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -1409,20 +1409,14 @@
 
 llvm::Type *ArgType = Val->getType();
 Shift = Builder.CreateIntCast(Shift, ArgType, false);
-unsigned ArgWidth = cast(ArgType)->getBitWidth();
-Value *ArgTypeSize = llvm::ConstantInt::get(ArgType, ArgWidth);
-Value *ArgZero = llvm::Constant::getNullValue(ArgType);
-
+unsigned ArgWidth = ArgType->getIntegerBitWidth();
 Value *Mask = llvm::ConstantInt::get(ArgType, ArgWidth - 1);
-Shift = Builder.CreateAnd(Shift, Mask);
-Value *LeftShift = Builder.CreateSub(ArgTypeSize, Shift);
-
-Value *RightShifted = Builder.CreateLShr(Val, Shift);
-Value *LeftShifted = Builder.CreateShl(Val, LeftShift);
-Value *Rotated = Builder.CreateOr(LeftShifted, RightShifted);
 
-Value *ShiftIsZero = Builder.CreateICmpEQ(Shift, ArgZero);
-Value *Result = Builder.CreateSelect(ShiftIsZero, Val, Rotated);
+Value *RightShiftAmt = Builder.CreateAnd(Shift, Mask);
+Value *RightShifted = Builder.CreateLShr(Val, RightShiftAmt);
+Value *LeftShiftAmt = Builder.CreateAnd(Builder.CreateNeg(Shift), Mask);
+Value *LeftShifted = Builder.CreateShl(Val, LeftShiftAmt);
+Value *Result = Builder.CreateOr(LeftShifted, RightShifted);
 return RValue::get(Result);
   }
   case Builtin::BI_rotl8:
@@ -1435,20 +1429,14 @@
 
 llvm::Type *ArgType = Val->getType();
 Shift = Builder.CreateIntCast(Shift, ArgType, false);
-unsigned ArgWidth = cast(ArgType)->getBitWidth();
-Value *ArgTypeSize = llvm::ConstantInt::get(ArgType, ArgWidth);
-Value *ArgZero = llvm::Constant::getNullValue(ArgType);
-
+unsigned ArgWidth = ArgType->getIntegerBitWidth();
 Value *Mask = llvm::ConstantInt::get(ArgType, ArgWidth - 1);
-Shift = Builder.CreateAnd(Shift, Mask);
-Value *RightShift = Builder.CreateSub(ArgTypeSize, Shift);
-
-Value *LeftShifted = Builder.CreateShl(Val, Shift);
-Value *RightShifted = Builder.CreateLShr(Val, RightShift);
-Value *Rotated = Builder.CreateOr(LeftShifted, RightShifted);
 
-Value *ShiftIsZero = Builder.CreateICmpEQ(Shift, ArgZero);
-Value *Result = Builder.CreateSelect(ShiftIsZero, Val, Rotated);
+Value *LeftShiftAmt = Builder.CreateAnd(Shift, Mask);
+Value *LeftShifted = Builder.CreateShl(Val, LeftShiftAmt);
+Value *RightShiftAmt = Builder.CreateAnd(Builder.CreateNeg(Shift), Mask);
+Value *RightShifted = Builder.CreateLShr(Val, RightShiftAmt);
+Value *Result = Builder.CreateOr(LeftShifted, RightShifted);
 return RValue::get(Result);
   }
   case Builtin::BI__builtin_unpredictable: {
Index: cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c
===
--- cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c
+++ cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c
@@ -30,69 +30,64 @@
   return _rotl8(value, shift);
 }
 // CHECK: i8 @test_rotl8
-// CHECK:   [[SHIFT:%[0-9]+]] = and i8 %{{[0-9]+}}, 7
-// CHECK:   [[NEGSHIFT:%[0-9]+]] = sub i8 8, [[SHIFT]]
-// CHECK:   [[HIGH:%[0-9]+]] = shl i8 [[VALUE:%[0-9]+]], [[SHIFT]]
-// CHECK:   [[LOW:%[0-9]+]] = lshr i8 [[VALUE]], [[NEGSHIFT]]
-// CHECK:   [[ROTATED:%[0-9]+]] = or i8 [[HIGH]], [[LOW]]
-// CHECK:   [[ISZERO:%[0-9]+]] = icmp eq i8 [[SHIFT]], 0
-// CHECK:   [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i8 [[VALUE]], i8 [[ROTATED]]
+// CHECK:   [[LSHIFT:%[0-9]+]] = and i8 [[SHIFT:%[0-9]+]], 7
+// CHECK:   [[HIGH:%[0-9]+]] = shl i8 [[VALUE:%[0-9]+]], [[LSHIFT]]
+// CHECK:   [[NEGATE:%[0-9]+]] = sub i8 0, [[SHIFT]]
+// CHECK:   [[RSHIFT:%[0-9]+]] = and i8 [[NEGATE]], 7
+// CHECK:   [[LOW:%[0-9]+]] = lshr i8 [[VALUE]], [[RSHIFT]]
+// CHECK:   [[RESULT:%[0-9]+]] = or i8 [[HIGH]], [[LOW]]
 // CHECK:   ret i8 [[RESULT]]
 // CHECK  }
 
 unsigned short test_rotl16(unsigned short value, unsigned char shift) {
   return _rotl16(value, shift);
 }
 // CHECK: i16 @test_rotl16
-// CHECK:   [[SHIFT:%[0-9]+]] = and i16 %{{[0-9]+}}, 15
-// CHECK:   [[NEGSHIFT:%[0-9]+]] = sub i16 16, [[SHIFT]]
-// CHECK:   [[HIGH:%[0-9]+]] = shl i16 [[VALUE:%[0-9]+]], [[SHIFT]]
-// CHECK:   [[LOW:%[0-9]+]] = lshr i16 [[VALUE]], [[NEGSHIFT]]
-// CHECK:   [[ROTATED:%[0-9]+]] = or i16 [[HIGH]], [[LOW]]
-// CHECK:   [[ISZERO:%[0-9]+]] = icmp eq i16 [[SHIFT]], 0
-// CHECK:   [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i16 [[VALUE]], i16 [[ROTATED]]

r331943 - [Builtins] Improve the IR emitted for MSVC compatible rotr/rotl builtins to match what the middle and backends understand

2018-05-09 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Wed May  9 17:05:13 2018
New Revision: 331943

URL: http://llvm.org/viewvc/llvm-project?rev=331943&view=rev
Log:
[Builtins] Improve the IR emitted for MSVC compatible rotr/rotl builtins to 
match what the middle and backends understand

Previously we emitted something like

rotl(x, n) {
  n &= bitwidth-1;
  return n != 0 ? ((x << n) | (x >> (bitwidth - n)) : x;
}

We use a select to avoid the undefined behavior on the (bitwidth - n) shift.

The middle and backend don't really recognize this as a rotate and end up 
emitting a cmov or control flow because of the select.

A better pattern is (x << (n & mask)) | (x << (-n & mask)) where mask is 
bitwidth - 1.

Fixes the main complaint in PR37387. There's still some work to be done if the 
user writes that sequence directly on a short or char where type promotion 
rules can prevent it from being recognized. The builtin is emitting direct IR 
with unpromoted types so that isn't a problem for it.

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

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=331943&r1=331942&r2=331943&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed May  9 17:05:13 2018
@@ -1409,20 +1409,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 
 llvm::Type *ArgType = Val->getType();
 Shift = Builder.CreateIntCast(Shift, ArgType, false);
-unsigned ArgWidth = cast(ArgType)->getBitWidth();
-Value *ArgTypeSize = llvm::ConstantInt::get(ArgType, ArgWidth);
-Value *ArgZero = llvm::Constant::getNullValue(ArgType);
-
+unsigned ArgWidth = ArgType->getIntegerBitWidth();
 Value *Mask = llvm::ConstantInt::get(ArgType, ArgWidth - 1);
-Shift = Builder.CreateAnd(Shift, Mask);
-Value *LeftShift = Builder.CreateSub(ArgTypeSize, Shift);
-
-Value *RightShifted = Builder.CreateLShr(Val, Shift);
-Value *LeftShifted = Builder.CreateShl(Val, LeftShift);
-Value *Rotated = Builder.CreateOr(LeftShifted, RightShifted);
 
-Value *ShiftIsZero = Builder.CreateICmpEQ(Shift, ArgZero);
-Value *Result = Builder.CreateSelect(ShiftIsZero, Val, Rotated);
+Value *RightShiftAmt = Builder.CreateAnd(Shift, Mask);
+Value *RightShifted = Builder.CreateLShr(Val, RightShiftAmt);
+Value *LeftShiftAmt = Builder.CreateAnd(Builder.CreateNeg(Shift), Mask);
+Value *LeftShifted = Builder.CreateShl(Val, LeftShiftAmt);
+Value *Result = Builder.CreateOr(LeftShifted, RightShifted);
 return RValue::get(Result);
   }
   case Builtin::BI_rotl8:
@@ -1435,20 +1429,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 
 llvm::Type *ArgType = Val->getType();
 Shift = Builder.CreateIntCast(Shift, ArgType, false);
-unsigned ArgWidth = cast(ArgType)->getBitWidth();
-Value *ArgTypeSize = llvm::ConstantInt::get(ArgType, ArgWidth);
-Value *ArgZero = llvm::Constant::getNullValue(ArgType);
-
+unsigned ArgWidth = ArgType->getIntegerBitWidth();
 Value *Mask = llvm::ConstantInt::get(ArgType, ArgWidth - 1);
-Shift = Builder.CreateAnd(Shift, Mask);
-Value *RightShift = Builder.CreateSub(ArgTypeSize, Shift);
-
-Value *LeftShifted = Builder.CreateShl(Val, Shift);
-Value *RightShifted = Builder.CreateLShr(Val, RightShift);
-Value *Rotated = Builder.CreateOr(LeftShifted, RightShifted);
 
-Value *ShiftIsZero = Builder.CreateICmpEQ(Shift, ArgZero);
-Value *Result = Builder.CreateSelect(ShiftIsZero, Val, Rotated);
+Value *LeftShiftAmt = Builder.CreateAnd(Shift, Mask);
+Value *LeftShifted = Builder.CreateShl(Val, LeftShiftAmt);
+Value *RightShiftAmt = Builder.CreateAnd(Builder.CreateNeg(Shift), Mask);
+Value *RightShifted = Builder.CreateLShr(Val, RightShiftAmt);
+Value *Result = Builder.CreateOr(LeftShifted, RightShifted);
 return RValue::get(Result);
   }
   case Builtin::BI__builtin_unpredictable: {

Modified: cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c?rev=331943&r1=331942&r2=331943&view=diff
==
--- cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c (original)
+++ cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c Wed May  9 17:05:13 2018
@@ -30,13 +30,12 @@ unsigned char test_rotl8(unsigned char v
   return _rotl8(value, shift);
 }
 // CHECK: i8 @test_rotl8
-// CHECK:   [[SHIFT:%[0-9]+]] = and i8 %{{[0-9]+}}, 7
-// CHECK:   [[NEGSHIFT:%[0-9]+]] = sub i8 8, [[SHIFT]]
-// CHECK:   [[HIGH:%[0-9]+]] = shl i8 [[VALUE:%[0-9]+]], [[SHIFT]]
-// CHECK:   [[LOW:%[0-9]+]] = lshr i8 [[VALUE]], [[NEGSHIFT]]
-// CHECK:   [[ROTATED:%[0-9]+]] = or i8 [[HIGH]], [[LOW]]
-// CHECK:   [[ISZERO:%

[PATCH] D46665: [Itanium] Emit type info names with external linkage.

2018-05-09 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/CodeGen/ItaniumCXXABI.cpp:3033
+  return {llvm::GlobalValue::InternalLinkage,
+  llvm::GlobalValue::LinkOnceODRLinkage};
+return {llvm::GlobalValue::InternalLinkage,

Shouldn't this be based on the type's linkage? Eg:

```
namespace { struct Incomplete; }
auto x = typeid(Incomplete*);
```

should have an `internal` type info name, not a `linkonce_odr` name. I think we 
should compute the linkage per the code below and then demote the type's 
linkage to internal in the incomplete-class case.



Comment at: lib/CodeGen/ItaniumCXXABI.cpp:3034-3035
+  llvm::GlobalValue::LinkOnceODRLinkage};
+return {llvm::GlobalValue::InternalLinkage,
+llvm::GlobalValue::InternalLinkage};
+  }

Should we promote the type info name in this case too? (We get here for the 
incomplete-class type info we generate as a detail of the pointer type info, 
but the names of such types are accessible via the  interface, so it 
seems reasonable to apply the same global-uniqueness to them too.)


https://reviews.llvm.org/D46665



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


[PATCH] D46665: [Itanium] Emit type info names with external linkage.

2018-05-09 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 146034.
EricWF added a comment.

- Correct copy-paste error.


https://reviews.llvm.org/D46665

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/rtti-linkage.cpp

Index: test/CodeGenCXX/rtti-linkage.cpp
===
--- test/CodeGenCXX/rtti-linkage.cpp
+++ test/CodeGenCXX/rtti-linkage.cpp
@@ -3,27 +3,27 @@
 
 #include 
 
-// CHECK-BOTH: _ZTSP1C = internal constant
+// CHECK-BOTH: _ZTSP1C = linkonce_odr constant
 // CHECK-BOTH: _ZTS1C = internal constant
 // CHECK-BOTH: _ZTI1C = internal constant
 // CHECK-BOTH: _ZTIP1C = internal constant
-// CHECK-BOTH: _ZTSPP1C = internal constant
+// CHECK-BOTH: _ZTSPP1C = linkonce_odr constant
 // CHECK-BOTH: _ZTIPP1C = internal constant
-// CHECK-BOTH: _ZTSM1Ci = internal constant
+// CHECK-BOTH: _ZTSM1Ci = linkonce_odr constant
 // CHECK-BOTH: _ZTIM1Ci = internal constant
-// CHECK-BOTH: _ZTSPM1Ci = internal constant
+// CHECK-BOTH: _ZTSPM1Ci = linkonce_odr constant
 // CHECK-BOTH: _ZTIPM1Ci = internal constant
-// CHECK-BOTH: _ZTSM1CS_ = internal constant
+// CHECK-BOTH: _ZTSM1CS_ = linkonce_odr constant
 // CHECK-BOTH: _ZTIM1CS_ = internal constant
-// CHECK-BOTH: _ZTSM1CPS_ = internal constant
+// CHECK-BOTH: _ZTSM1CPS_ = linkonce_odr constant
 // CHECK-BOTH: _ZTIM1CPS_ = internal constant
-// CHECK-BOTH: _ZTSM1A1C = internal constant
+// CHECK-BOTH: _ZTSM1A1C = linkonce_odr constant
 // CHECK: _ZTS1A = linkonce_odr constant
 // CHECK-WITH-HIDDEN: _ZTS1A = linkonce_odr hidden constant
 // CHECK: _ZTI1A = linkonce_odr constant
 // CHECK-WITH-HIDDEN: _ZTI1A = linkonce_odr hidden constant
 // CHECK-BOTH: _ZTIM1A1C = internal constant
-// CHECK-BOTH: _ZTSM1AP1C = internal constant
+// CHECK-BOTH: _ZTSM1AP1C = linkonce_odr constant
 // CHECK-BOTH: _ZTIM1AP1C = internal constant
 
 // CHECK-WITH-HIDDEN: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -3008,8 +3008,9 @@
 
 /// \brief Return the linkage that the type info and type info name constants
 /// should have for the given type.
-static llvm::GlobalVariable::LinkageTypes getTypeInfoLinkage(CodeGenModule &CGM,
- QualType Ty) {
+static std::pair
+getTypeInfoLinkage(CodeGenModule &CGM, QualType Ty) {
   // Itanium C++ ABI 2.9.5p7:
   //   In addition, it and all of the intermediate abi::__pointer_type_info
   //   structs in the chain down to the abi::__class_type_info for the
@@ -3019,9 +3020,22 @@
   //   generated for the incomplete type that will not resolve to the final
   //   complete class RTTI (because the latter need not exist), possibly by
   //   making it a local static object.
-  if (ContainsIncompleteClassType(Ty))
-return llvm::GlobalValue::InternalLinkage;
+  if (ContainsIncompleteClassType(Ty)) {
+// Itanium C++ ABI 2.9.3:
+//  The name() member function returns the address of an NTBS, unique to the
+//  type, ...
+//
+// This means we should emit the type info name visibly, so that the type
+// info objects for the complete and incomplete types share the same string.
+// See llvm.org/PR37398
+if (Ty->isPointerType() || Ty->isMemberPointerType())
+  return {llvm::GlobalValue::InternalLinkage,
+  llvm::GlobalValue::LinkOnceODRLinkage};
+return {llvm::GlobalValue::InternalLinkage,
+llvm::GlobalValue::InternalLinkage};
+  }
 
+  llvm::GlobalValue::LinkageTypes LinkageForType = [&]() {
 switch (Ty->getLinkage()) {
 case NoLinkage:
 case InternalLinkage:
@@ -3046,18 +3060,18 @@
   ShouldUseExternalRTTIDescriptor(CGM, Ty))
 return llvm::GlobalValue::ExternalLinkage;
 // MinGW always uses LinkOnceODRLinkage for type info.
-  if (RD->isDynamicClass() &&
-  !CGM.getContext()
+if (RD->isDynamicClass() && !CGM.getContext()
  .getTargetInfo()
  .getTriple()
  .isWindowsGNUEnvironment())
   return CGM.getVTableLinkage(RD);
   }
 
   return llvm::GlobalValue::LinkOnceODRLinkage;
 }
-
 llvm_unreachable("Invalid linkage!");
+  }();
+  return {LinkageForType, LinkageForType};
 }
 
 llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(QualType Ty, bool Force,
@@ -3084,23 +3098,25 @@
 return GetAddrOfExternalRTTIDescriptor(Ty);
 
   // Emit the standard library with external linkage.
-  llvm::GlobalVariable::LinkageTypes Linkage;
+  llvm::GlobalVariable::LinkageTypes TInfoLinkage, NameLinkage;
   if (IsStdLib)
-Linkage = llvm::GlobalValue::ExternalLinkage;
-  else
-Linkage = getTypeInfoLinkage(CGM, Ty);
-
+TInfoLinkage = NameLinkage = llvm::GlobalValue::ExternalLinkage;
+  else {
+auto TInfoNameLinkage 

[PATCH] D46614: [clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 146032.
juliehockett added a comment.

Reverted because of memory leak in PPCallbacksTest, this fixes it.


https://reviews.llvm.org/D46614

Files:
  include/clang/Lex/PPCallbacks.h
  include/clang/Lex/PreprocessingRecord.h
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/Frontend/DependencyFile.cpp
  lib/Frontend/DependencyGraph.cpp
  lib/Frontend/ModuleDependencyCollector.cpp
  lib/Frontend/PrintPreprocessedOutput.cpp
  lib/Frontend/Rewrite/InclusionRewriter.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PreprocessingRecord.cpp
  tools/libclang/Indexing.cpp
  unittests/Lex/PPCallbacksTest.cpp

Index: unittests/Lex/PPCallbacksTest.cpp
===
--- unittests/Lex/PPCallbacksTest.cpp
+++ unittests/Lex/PPCallbacksTest.cpp
@@ -39,16 +39,18 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
-  this->HashLoc = HashLoc;
-  this->IncludeTok = IncludeTok;
-  this->FileName = FileName.str();
-  this->IsAngled = IsAngled;
-  this->FilenameRange = FilenameRange;
-  this->File = File;
-  this->SearchPath = SearchPath.str();
-  this->RelativePath = RelativePath.str();
-  this->Imported = Imported;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
+this->HashLoc = HashLoc;
+this->IncludeTok = IncludeTok;
+this->FileName = FileName.str();
+this->IsAngled = IsAngled;
+this->FilenameRange = FilenameRange;
+this->File = File;
+this->SearchPath = SearchPath.str();
+this->RelativePath = RelativePath.str();
+this->Imported = Imported;
+this->FileType = FileType;
   }
 
   SourceLocation HashLoc;
@@ -60,6 +62,7 @@
   SmallString<16> SearchPath;
   SmallString<16> RelativePath;
   const Module* Imported;
+  SrcMgr::CharacteristicKind FileType;
 };
 
 // Stub to collect data from PragmaOpenCLExtension callbacks.
@@ -134,10 +137,34 @@
 return StringRef(B, E - B);
   }
 
+  std::unique_ptr getPreprocessor(const char *SourceText,
+const char *HeaderPath,
+bool SystemHeader) {
+std::unique_ptr Buf =
+llvm::MemoryBuffer::getMemBuffer(SourceText);
+SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
+
+TrivialModuleLoader ModLoader;
+MemoryBufferCache PCMCache;
+
+HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,
+Diags, LangOpts, Target.get());
+AddFakeHeader(HeaderInfo, HeaderPath, SystemHeader);
+
+std::unique_ptr PP = llvm::make_unique(
+std::make_shared(), Diags, LangOpts, SourceMgr,
+PCMCache, HeaderInfo, ModLoader,
+/*IILookup =*/nullptr,
+/*OwnsHeaderSearch =*/false);
+PP->Initialize(*Target);
+return PP;
+  }
+
   // Run lexer over SourceText and collect FilenameRange from
   // the InclusionDirective callback.
-  CharSourceRange InclusionDirectiveFilenameRange(const char* SourceText, 
-  const char* HeaderPath, bool SystemHeader) {
+  CharSourceRange InclusionDirectiveFilenameRange(const char *SourceText,
+  const char *HeaderPath,
+  bool SystemHeader) {
 std::unique_ptr Buf =
 llvm::MemoryBuffer::getMemBuffer(SourceText);
 SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
@@ -149,26 +176,52 @@
 Diags, LangOpts, Target.get());
 AddFakeHeader(HeaderInfo, HeaderPath, SystemHeader);
 
-Preprocessor PP(std::make_shared(), Diags, LangOpts,
-SourceMgr, PCMCache, HeaderInfo, ModLoader,
-/*IILookup =*/nullptr,
-/*OwnsHeaderSearch =*/false);
-PP.Initialize(*Target);
-InclusionDirectiveCallbacks* Callbacks = new InclusionDirectiveCallbacks;
-PP.addPPCallbacks(std::unique_ptr(Callbacks));
+std::unique_ptr PP = llvm::make_unique(
+std::make_shared(), Diags, LangOpts, SourceMgr,
+PCMCache, HeaderInfo, ModLoader,
+/*IILookup =*/nullptr,
+/*OwnsHeaderSearch =*/false);
+return InclusionDirectiveCallback(PP.get())->FilenameRange;
+  }
 
+  SrcMgr::CharacteristicKind InclusionDirectiveCharacteristicKind(
+  const char *SourceText, const char *HeaderPath, bool SystemHeader) {
+std::unique_ptr Buf =
+llvm::MemoryBuffer::getMemBuffer(SourceText);
+SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
+
+TrivialModuleLoader ModLoader;
+MemoryBufferCache PCMCache;
+
+HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,

[PATCH] D43320: Allow dllimport non-type template arguments in C++17

2018-05-09 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/include/clang/AST/Expr.h:670-672
+  /// Evaluate an expression that is required to be a core constant expression.
+  bool EvaluateAsCoreConstExpr(EvalResult &Result, QualType ParamType,
+   CCEKind CCE, const ASTContext &Ctx) const;

rnk wrote:
> rsmith wrote:
> > Seems strange to pass a converted constant expression kind to an 'evaluate 
> > as core constant expression' function. And it seems like we don't need the 
> > kind here, just an "evaluating for emission w/relocations" vs "evaluating 
> > for mangling" enum.
> > 
> > Also, we need to evaluate non-type template arguments as constant 
> > expressions, not just as core constant expressions, which the 
> > implementation does, but the name and comment here don't reflect. (The 
> > difference is that you can't result in a pointer/reference to a temporary 
> > or automatic / thread storage duration entity.)
> So... what are these things? Converted constant expressions? What are we 
> evaluating them as? I guess they're not rvalues or lvalues.
I think this should just be called `EvaluateAsConstantExpr`, and you should 
drop all the "core"s throughout. The difference between a constant expression 
and a core constant expression is that a core constant expression allows the 
evaluated value to refer to entities with automatic storage duration etc, which 
is exactly the case you want to disallow here :)

I also don't think you need the `ParamType`, and can instead just look at 
whether the expression itself is an rvalue.



Comment at: clang/include/clang/AST/Expr.h:663
+  bool EvaluateAsCoreConstExpr(EvalResult &Result, QualType ParamType,
+   bool IsTemplateArg, const ASTContext &Ctx) 
const;
+

I would prefer an `enum { EvaluateForCodeGen, EvaluateForMangling }` over a 
bool `IsTemplateArg`; I would not be surprised if we find other cases where we 
want to evaluate an expression for mangling purposes only.



Comment at: clang/lib/AST/ExprConstant.cpp:707
 
+  /// Evaluate as a C++17 non-type template argument, which is a core
+  /// constant expression with a special case for dllimport declarations.

No "core" here.



Comment at: clang/lib/AST/ExprConstant.cpp:709
+  /// constant expression with a special case for dllimport declarations.
+  EM_TemplateArgument,
+

I don't think we need this. See below.



Comment at: clang/lib/AST/ExprConstant.cpp:10384-10385
+if (!EvaluateLValue(this, LV, Info) || Result.HasSideEffects ||
+!CheckLValueConstantExpression(
+Info, getExprLoc(), Ctx.getLValueReferenceType(getType()), LV))
+  return false;

Instead of a new `EvaluationMode` which is actually not used by evaluation, we 
could pass a parameter into `CheckLValueConstantExpression` to indicate if 
we're in the "for-mangling" mode.



Comment at: clang/lib/AST/ExprConstant.cpp:10397
+  EvalInfo Info(Ctx, Result, EM);
+  return ::EvaluateAsRValue(Info, this, Result.Val);
+}

If you switch from using `ParamType->isReferenceType()` to asking the 
expression for its value category, you don't need the 
implicit-lvalue-to-rvalue-conversion semantics of `EvaluateAsRValue`, and can 
just call `::Evaluate` here followed by a call to `CheckConstantExpression` 
(passing the latter the `IsTemplateArg` flag).

In fact, you don't need the separate case for lvalues above, either, since 
`::Evaluate` does the right thing for an lvalue expression by itself.



Comment at: clang/lib/Sema/SemaOverload.cpp:5401
 
-  if ((T->isReferenceType()
-   ? !Result.get()->EvaluateAsLValue(Eval, S.Context)
-   : !Result.get()->EvaluateAsRValue(Eval, S.Context)) ||
+  if (!Result.get()->EvaluateAsNonTypeTemplateArgument(Eval, T, S.Context) ||
   (RequireInt && !Eval.Val.isInt())) {

rnk wrote:
> rsmith wrote:
> > Don't we get here for `CCEKind`s other than the non-type template argument 
> > case?
> You're right, but I wasn't able to construct a test case where we would call 
> `CheckConvertedConstantExpression` and we would reject it today because it is 
> dllimported. This was my best idea, using `if constexpr`:
> ```
> struct __declspec(dllimport) Foo {
>   static constexpr bool imported_foo = true;
> };
> const bool some_bool = false;
> const bool *f() {
>   if constexpr (Foo::imported_foo) {
> return &Foo::imported_foo;
>   } else {
> return &some_bool;
>   }
> }
> ```
> 
> Any other ideas on how to get more coverage of this path through 
> CheckConvertedConstantExpression?
All the other forms of `CCEKind` also set `RequireInt` to `true`, and so any 
case your check catches would also be caught on the line below.


https://reviews.llvm.org/D43320



__

[PATCH] D46593: Allow copy elision in path concatenation

2018-05-09 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc added a comment.

In https://reviews.llvm.org/D46593#1093758, @jwakely wrote:

> @chandlerc thanks for catching this.
>
> As the original author I agree to contribute this patch to libc++ under the 
> terms of the MIT and the University of Illinois licences, and under the terms 
> of "Apache 2 with LLVM exception" if necessary in future.
>
> This permission applies only to this patch, not any other code from GCC.


Thanks so much for the fast response! And yeah, let's try to follow a more 
obvious process in the future. =D


Repository:
  rCXX libc++

https://reviews.llvm.org/D46593



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


[PATCH] D46665: [Itanium] Emit type info names with external linkage.

2018-05-09 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF created this revision.
EricWF added reviewers: rsmith, rjmccall, majnemer, vsapsai.

The Itanium ABI requires that the type info for pointer-to-incomplete types to 
have internal linkage, so that it doesn't interfere with the type info once 
completed.  Currently it also marks the type info name as internal as well. 
However, this causes a bug with the STL implementations, which use the type 
info name pointer to perform ordering and hashing of type infos.
For example:

  // header.h
  struct T;
  extern std::type_info const& Info;
  
  // tu_one.cpp
  #include "header.h"
  std::type_info const& Info = typeid(T*);
  
  // tu_two.cpp
  #include "header.h"
  struct T {};
  int main() {
auto &TI1 = Info;
auto &TI2 = typeid(T*);
assert(TI1 == TI2); // Fails
assert(TI1.hash_code() == TI2.hash_code()); // Fails
  }

This patch fixes the STL bug by emitting the type info name as linkonce_odr 
when the type-info is for a pointer-to-incomplete type.

Note that libc++ could fix this without a compiler change, but the quality of 
fix would be poor. The library would either have to:

(A) Always perform strcmp/string hashes.
(B) Determine if we have a pointer-to-incomplete type, and only do strcmp then. 
This would require an ABI break for libc++.


https://reviews.llvm.org/D46665

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/rtti-linkage.cpp

Index: test/CodeGenCXX/rtti-linkage.cpp
===
--- test/CodeGenCXX/rtti-linkage.cpp
+++ test/CodeGenCXX/rtti-linkage.cpp
@@ -3,27 +3,27 @@
 
 #include 
 
-// CHECK-BOTH: _ZTSP1C = internal constant
+// CHECK-BOTH: _ZTSP1C = linkonce_odr constant
 // CHECK-BOTH: _ZTS1C = internal constant
 // CHECK-BOTH: _ZTI1C = internal constant
 // CHECK-BOTH: _ZTIP1C = internal constant
-// CHECK-BOTH: _ZTSPP1C = internal constant
+// CHECK-BOTH: _ZTSPP1C = linkonce_odr constant
 // CHECK-BOTH: _ZTIPP1C = internal constant
-// CHECK-BOTH: _ZTSM1Ci = internal constant
+// CHECK-BOTH: _ZTSM1Ci = linkonce_odr constant
 // CHECK-BOTH: _ZTIM1Ci = internal constant
-// CHECK-BOTH: _ZTSPM1Ci = internal constant
+// CHECK-BOTH: _ZTSPM1Ci = linkonce_odr constant
 // CHECK-BOTH: _ZTIPM1Ci = internal constant
-// CHECK-BOTH: _ZTSM1CS_ = internal constant
+// CHECK-BOTH: _ZTSM1CS_ = linkonce_odr constant
 // CHECK-BOTH: _ZTIM1CS_ = internal constant
-// CHECK-BOTH: _ZTSM1CPS_ = internal constant
+// CHECK-BOTH: _ZTSM1CPS_ = linkonce_odr constant
 // CHECK-BOTH: _ZTIM1CPS_ = internal constant
-// CHECK-BOTH: _ZTSM1A1C = internal constant
+// CHECK-BOTH: _ZTSM1A1C = linkonce_odr constant
 // CHECK: _ZTS1A = linkonce_odr constant
 // CHECK-WITH-HIDDEN: _ZTS1A = linkonce_odr hidden constant
 // CHECK: _ZTI1A = linkonce_odr constant
 // CHECK-WITH-HIDDEN: _ZTI1A = linkonce_odr hidden constant
 // CHECK-BOTH: _ZTIM1A1C = internal constant
-// CHECK-BOTH: _ZTSM1AP1C = internal constant
+// CHECK-BOTH: _ZTSM1AP1C = linkonce_odr constant
 // CHECK-BOTH: _ZTIM1AP1C = internal constant
 
 // CHECK-WITH-HIDDEN: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -3008,8 +3008,9 @@
 
 /// \brief Return the linkage that the type info and type info name constants
 /// should have for the given type.
-static llvm::GlobalVariable::LinkageTypes getTypeInfoLinkage(CodeGenModule &CGM,
- QualType Ty) {
+static std::pair
+getTypeInfoLinkage(CodeGenModule &CGM, QualType Ty) {
   // Itanium C++ ABI 2.9.5p7:
   //   In addition, it and all of the intermediate abi::__pointer_type_info
   //   structs in the chain down to the abi::__class_type_info for the
@@ -3019,9 +3020,22 @@
   //   generated for the incomplete type that will not resolve to the final
   //   complete class RTTI (because the latter need not exist), possibly by
   //   making it a local static object.
-  if (ContainsIncompleteClassType(Ty))
-return llvm::GlobalValue::InternalLinkage;
+  if (ContainsIncompleteClassType(Ty)) {
+// Itanium C++ ABI 2.9.3:
+//  The name() member function returns the address of an NTBS, unique to the
+//  type, ...
+//
+// This means we should emit the type info name visibly, so that the type
+// info objects for the complete and incomplete types share the same string.
+// See llvm.org/PR37398
+if (Ty->isPointerType() || Ty->isMemberPointerType())
+  return {llvm::GlobalValue::InternalLinkage,
+  llvm::GlobalValue::LinkOnceODRLinkage};
+return {llvm::GlobalValue::InternalLinkage,
+llvm::GlobalValue::InternalLinkage};
+  }
 
+  llvm::GlobalValue::LinkageTypes LinkageForType = [&]() {
 switch (Ty->getLinkage()) {
 case NoLinkage:
 case InternalLinkage:
@@ -3046,18 +3060,18 @@
   ShouldUseExternalRTTIDescriptor(CGM, Ty))
   

[PATCH] D46593: Allow copy elision in path concatenation

2018-05-09 Thread Jonathan Wakely via Phabricator via cfe-commits
jwakely added a comment.

@chandlerc thanks for catching this.

As the original author I agree to contribute this patch to libc++ under the 
terms of the MIT and the University of Illinois licences, and under the terms 
of "Apache 2 with LLVM exception" if necessary in future.

This permission applies only to this patch, not any other code from GCC.


Repository:
  rCXX libc++

https://reviews.llvm.org/D46593



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


r331938 - [CUDA] Added -f[no-]cuda-short-ptr option

2018-05-09 Thread Artem Belevich via cfe-commits
Author: tra
Date: Wed May  9 16:10:09 2018
New Revision: 331938

URL: http://llvm.org/viewvc/llvm-project?rev=331938&view=rev
Log:
[CUDA] Added -f[no-]cuda-short-ptr option

The option enables use of 32-bit pointers for accessing
const/local/shared memory. The feature is disabled by default.

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

Modified:
cfe/trunk/include/clang/Basic/TargetOptions.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Basic/Targets/NVPTX.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Basic/TargetOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetOptions.h?rev=331938&r1=331937&r2=331938&view=diff
==
--- cfe/trunk/include/clang/Basic/TargetOptions.h (original)
+++ cfe/trunk/include/clang/Basic/TargetOptions.h Wed May  9 16:10:09 2018
@@ -63,6 +63,10 @@ public:
 
   /// If given, enables support for __int128_t and __uint128_t types.
   bool ForceEnableInt128 = false;
+
+  /// \brief If enabled, use 32-bit pointers for accessing const/local/shared
+  /// address space.
+  bool NVPTXUseShortPointers = false;
 };
 
 }  // end namespace clang

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=331938&r1=331937&r2=331938&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed May  9 16:10:09 2018
@@ -581,6 +581,9 @@ def fno_cuda_approx_transcendentals : Fl
 def fcuda_rdc : Flag<["-"], "fcuda-rdc">, Flags<[CC1Option]>,
   HelpText<"Generate relocatable device code, also known as separate 
compilation mode.">;
 def fno_cuda_rdc : Flag<["-"], "fno-cuda-rdc">;
+def fcuda_short_ptr : Flag<["-"], "fcuda-short-ptr">, Flags<[CC1Option]>,
+  HelpText<"Use 32-bit pointers for accessing const/local/shared address 
spaces.">;
+def fno_cuda_short_ptr : Flag<["-"], "fno-cuda-short-ptr">;
 def dA : Flag<["-"], "dA">, Group;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,
   HelpText<"Print macro definitions in -E mode in addition to normal output">;

Modified: cfe/trunk/lib/Basic/Targets/NVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/NVPTX.cpp?rev=331938&r1=331937&r2=331938&view=diff
==
--- cfe/trunk/lib/Basic/Targets/NVPTX.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/NVPTX.cpp Wed May  9 16:10:09 2018
@@ -68,6 +68,9 @@ NVPTXTargetInfo::NVPTXTargetInfo(const l
 
   if (TargetPointerWidth == 32)
 resetDataLayout("e-p:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
+  else if (Opts.NVPTXUseShortPointers)
+resetDataLayout(
+
"e-p3:32:32-p4:32:32-p5:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
   else
 resetDataLayout("e-i64:64-i128:128-v16:16-v32:32-n16:32:64");
 

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=331938&r1=331937&r2=331938&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed May  9 16:10:09 2018
@@ -4714,6 +4714,9 @@ void Clang::ConstructJob(Compilation &C,
 
 if (Args.hasFlag(options::OPT_fcuda_rdc, options::OPT_fno_cuda_rdc, false))
   CmdArgs.push_back("-fcuda-rdc");
+if (Args.hasFlag(options::OPT_fcuda_short_ptr,
+ options::OPT_fno_cuda_short_ptr, false))
+  CmdArgs.push_back("-fcuda-short-ptr");
   }
 
   // OpenMP offloading device jobs take the argument -fopenmp-host-ir-file-path

Modified: cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Cuda.cpp?rev=331938&r1=331937&r2=331938&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Cuda.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Cuda.cpp Wed May  9 16:10:09 2018
@@ -635,8 +635,10 @@ void CudaToolChain::addClangTargetOption
 // CUDA-9.0 uses new instructions that are only available in PTX6.0+
 PtxFeature = "+ptx60";
   }
-  CC1Args.push_back("-target-feature");
-  CC1Args.push_back(PtxFeature);
+  CC1Args.append({"-target-feature", PtxFeature});
+  if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
+ options::OPT_fno_cuda_short_ptr, false))
+CC1Args.append({"-mllvm", "--nvptx-short-ptr"});
 
   if (DeviceOffloadingKind == Action::OFK_OpenMP) {
 SmallVector LibraryPaths;

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc

[PATCH] D46148: [CUDA] Added -f[no-]cuda-short-ptr option

2018-05-09 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331938: [CUDA] Added -f[no-]cuda-short-ptr option (authored 
by tra, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46148?vs=144419&id=146027#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46148

Files:
  cfe/trunk/include/clang/Basic/TargetOptions.h
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/lib/Basic/Targets/NVPTX.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp


Index: cfe/trunk/include/clang/Basic/TargetOptions.h
===
--- cfe/trunk/include/clang/Basic/TargetOptions.h
+++ cfe/trunk/include/clang/Basic/TargetOptions.h
@@ -63,6 +63,10 @@
 
   /// If given, enables support for __int128_t and __uint128_t types.
   bool ForceEnableInt128 = false;
+
+  /// \brief If enabled, use 32-bit pointers for accessing const/local/shared
+  /// address space.
+  bool NVPTXUseShortPointers = false;
 };
 
 }  // end namespace clang
Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -581,6 +581,9 @@
 def fcuda_rdc : Flag<["-"], "fcuda-rdc">, Flags<[CC1Option]>,
   HelpText<"Generate relocatable device code, also known as separate 
compilation mode.">;
 def fno_cuda_rdc : Flag<["-"], "fno-cuda-rdc">;
+def fcuda_short_ptr : Flag<["-"], "fcuda-short-ptr">, Flags<[CC1Option]>,
+  HelpText<"Use 32-bit pointers for accessing const/local/shared address 
spaces.">;
+def fno_cuda_short_ptr : Flag<["-"], "fno-cuda-short-ptr">;
 def dA : Flag<["-"], "dA">, Group;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,
   HelpText<"Print macro definitions in -E mode in addition to normal output">;
Index: cfe/trunk/lib/Basic/Targets/NVPTX.cpp
===
--- cfe/trunk/lib/Basic/Targets/NVPTX.cpp
+++ cfe/trunk/lib/Basic/Targets/NVPTX.cpp
@@ -68,6 +68,9 @@
 
   if (TargetPointerWidth == 32)
 resetDataLayout("e-p:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
+  else if (Opts.NVPTXUseShortPointers)
+resetDataLayout(
+
"e-p3:32:32-p4:32:32-p5:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
   else
 resetDataLayout("e-i64:64-i128:128-v16:16-v32:32-n16:32:64");
 
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -2922,6 +2922,8 @@
 Opts.Triple = llvm::sys::getDefaultTargetTriple();
   Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ);
   Opts.ForceEnableInt128 = Args.hasArg(OPT_fforce_enable_int128);
+  Opts.NVPTXUseShortPointers = Args.hasFlag(
+  options::OPT_fcuda_short_ptr, options::OPT_fno_cuda_short_ptr, false);
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -4714,6 +4714,9 @@
 
 if (Args.hasFlag(options::OPT_fcuda_rdc, options::OPT_fno_cuda_rdc, false))
   CmdArgs.push_back("-fcuda-rdc");
+if (Args.hasFlag(options::OPT_fcuda_short_ptr,
+ options::OPT_fno_cuda_short_ptr, false))
+  CmdArgs.push_back("-fcuda-short-ptr");
   }
 
   // OpenMP offloading device jobs take the argument -fopenmp-host-ir-file-path
Index: cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
@@ -635,8 +635,10 @@
 // CUDA-9.0 uses new instructions that are only available in PTX6.0+
 PtxFeature = "+ptx60";
   }
-  CC1Args.push_back("-target-feature");
-  CC1Args.push_back(PtxFeature);
+  CC1Args.append({"-target-feature", PtxFeature});
+  if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
+ options::OPT_fno_cuda_short_ptr, false))
+CC1Args.append({"-mllvm", "--nvptx-short-ptr"});
 
   if (DeviceOffloadingKind == Action::OFK_OpenMP) {
 SmallVector LibraryPaths;


Index: cfe/trunk/include/clang/Basic/TargetOptions.h
===
--- cfe/trunk/include/clang/Basic/TargetOptions.h
+++ cfe/trunk/include/clang/Basic/TargetOptions.h
@@ -63,6 +63,10 @@
 
   /// If given, enables support for __int128_t and __uint128_t types.
   bool ForceEnableInt128 = false;
+
+  /// \brief If enabled, use 32-bit pointers for accessing const/local/shared
+  /// address space.
+  bool NVPTXUseShortPointers = false;
 };
 
 }  // 

[PATCH] D43320: Allow dllimport non-type template arguments in C++17

2018-05-09 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: clang/include/clang/AST/Expr.h:670-672
+  /// Evaluate an expression that is required to be a core constant expression.
+  bool EvaluateAsCoreConstExpr(EvalResult &Result, QualType ParamType,
+   CCEKind CCE, const ASTContext &Ctx) const;

rsmith wrote:
> Seems strange to pass a converted constant expression kind to an 'evaluate as 
> core constant expression' function. And it seems like we don't need the kind 
> here, just an "evaluating for emission w/relocations" vs "evaluating for 
> mangling" enum.
> 
> Also, we need to evaluate non-type template arguments as constant 
> expressions, not just as core constant expressions, which the implementation 
> does, but the name and comment here don't reflect. (The difference is that 
> you can't result in a pointer/reference to a temporary or automatic / thread 
> storage duration entity.)
So... what are these things? Converted constant expressions? What are we 
evaluating them as? I guess they're not rvalues or lvalues.


https://reviews.llvm.org/D43320



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


[PATCH] D43320: Allow dllimport non-type template arguments in C++17

2018-05-09 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 146025.
rnk added a comment.

- don't expose CCEK, use a bool


https://reviews.llvm.org/D43320

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/dllimport-constexpr.cpp
  clang/test/SemaCXX/dllimport-memptr.cpp

Index: clang/test/SemaCXX/dllimport-memptr.cpp
===
--- clang/test/SemaCXX/dllimport-memptr.cpp
+++ clang/test/SemaCXX/dllimport-memptr.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -verify -std=c++17 %s
 
 // expected-no-diagnostics
 
Index: clang/test/SemaCXX/dllimport-constexpr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/dllimport-constexpr.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -std=c++14 %s -verify -fms-extensions -triple x86_64-windows-msvc
+// RUN: %clang_cc1 -std=c++17 %s -verify -fms-extensions -triple x86_64-windows-msvc
+
+__declspec(dllimport) void imported_func();
+__declspec(dllimport) int imported_int;
+struct Foo {
+  void __declspec(dllimport) imported_method();
+};
+
+// Instantiation is OK.
+template  struct TemplateFnPtr {
+  static void getit() { FP(); }
+};
+template  struct TemplateFnRef {
+  static void getit() { FP(); }
+};
+void instantiate1() {
+  TemplateFnPtr<&imported_func>::getit();
+  TemplateFnRef::getit();
+}
+
+// Check variable template instantiation.
+template  struct TemplateIntPtr {
+  static int getit() { return *GI; }
+};
+template  struct TemplateIntRef {
+  static int getit() { return GI; }
+};
+int instantiate2() {
+  int r = 0;
+  r += TemplateIntPtr<&imported_int>::getit();
+  r += TemplateIntRef::getit();
+  return r;
+}
+
+// Member pointer instantiation.
+template  struct TemplateMemPtr { };
+TemplateMemPtr<&Foo::imported_method> instantiate_mp;
+
+// constexpr initialization doesn't work for dllimport things.
+// expected-error@+1{{must be initialized by a constant expression}}
+constexpr void (*constexpr_import_func)() = &imported_func;
+// expected-error@+1{{must be initialized by a constant expression}}
+constexpr int *constexpr_import_int = &imported_int;
+// expected-error@+1{{must be initialized by a constant expression}}
+constexpr void (Foo::*constexpr_memptr)() = &Foo::imported_method;
+
+// We make dynamic initializers for 'const' globals, but not constexpr ones.
+void (*const const_import_func)() = &imported_func;
+int *const const_import_int = &imported_int;
+void (Foo::*const const_memptr)() = &Foo::imported_method;
+
+// Check that using a non-type template parameter for constexpr global
+// initialization is correctly diagnosed during template instantiation.
+template  struct StaticConstexpr {
+  // expected-error@+1{{must be initialized by a constant expression}}
+  static constexpr void (*g_fp)() = FP;
+};
+void instantiate3() {
+  // expected-note@+1 {{requested here}}
+  StaticConstexpr::g_fp();
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -5408,9 +5408,8 @@
   Expr::EvalResult Eval;
   Eval.Diag = &Notes;
 
-  if ((T->isReferenceType()
-   ? !Result.get()->EvaluateAsLValue(Eval, S.Context)
-   : !Result.get()->EvaluateAsRValue(Eval, S.Context)) ||
+  if (!Result.get()->EvaluateAsCoreConstExpr(
+  Eval, T, CCE == Sema::CCEK_TemplateArg, S.Context) ||
   (RequireInt && !Eval.Val.isInt())) {
 // The expression can't be folded, so we can't keep it at this position in
 // the AST.
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -704,6 +704,10 @@
   /// a constant expression.
   EM_PotentialConstantExpression,
 
+  /// Evaluate as a C++17 non-type template argument, which is a core
+  /// constant expression with a special case for dllimport declarations.
+  EM_TemplateArgument,
+
   /// Fold the expression to a constant. Stop if we hit a side-effect that
   /// we can't model.
   EM_ConstantFold,
@@ -793,6 +797,14 @@
   return false;
 }
 
+/// Return true if this declaration is dllimport and we cannot treat the
+/// address as a constant expression. Generally, we do not want to constant
+/// fold dllimport declarations unless they are used in a non-type template
+/// parameter.
+bool isNonConstDllImportDecl(const Decl *D) {
+  return EvalMode != EM_TemplateArgument && D->hasAttr();
+}
+
 CallStackFrame *getCallFrame(unsigned CallIndex) {
   assert(CallIndex && "no call index in getCallFrame");
   // We will eventually hit BottomFrame, which has Index 1, so Frame can't
@@ -845,6 +857,7 @@
  

[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett reopened this revision.
juliehockett added a comment.

Sorry, branches got crossed. Reverted and reopened.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43778



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


[clang-tools-extra] r331934 - Revert "[clang-tidy] Adding RestrictSystemIncludes check to Fuchsia module"

2018-05-09 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Wed May  9 15:28:18 2018
New Revision: 331934

URL: http://llvm.org/viewvc/llvm-project?rev=331934&view=rev
Log:
Revert "[clang-tidy] Adding RestrictSystemIncludes check to Fuchsia module"

This reverts commit r331930, which was landed by accident.

Removed:
clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/a.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/j.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/s.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/t.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h

clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt?rev=331934&r1=331933&r2=331934&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt Wed May  9 
15:28:18 2018
@@ -5,7 +5,6 @@ add_clang_library(clangTidyFuchsiaModule
   FuchsiaTidyModule.cpp
   MultipleInheritanceCheck.cpp
   OverloadedOperatorCheck.cpp
-  RestrictSystemIncludesCheck.cpp
   StaticallyConstructedObjectsCheck.cpp
   TrailingReturnCheck.cpp
   VirtualInheritanceCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp?rev=331934&r1=331933&r2=331934&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp Wed May  9 
15:28:18 2018
@@ -14,7 +14,6 @@
 #include "DefaultArgumentsCheck.h"
 #include "MultipleInheritanceCheck.h"
 #include "OverloadedOperatorCheck.h"
-#include "RestrictSystemIncludesCheck.h"
 #include "StaticallyConstructedObjectsCheck.h"
 #include "TrailingReturnCheck.h"
 #include "VirtualInheritanceCheck.h"
@@ -37,8 +36,6 @@ public:
 "fuchsia-multiple-inheritance");
 CheckFactories.registerCheck(
 "fuchsia-overloaded-operator");
-CheckFactories.registerCheck(
-"fuchsia-restrict-system-includes");
 CheckFactories.registerCheck(
 "fuchsia-statically-constructed-objects");
 CheckFactories.registerCheck(

Removed: 
clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp?rev=331933&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp 
(removed)
@@ -1,126 +0,0 @@
-//===--- RestrictSystemIncludesCheck.cpp - 
clang-tidy--===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include "RestrictSystemIncludesCheck.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Lex/HeaderSearch.h"
-#include "clang/Lex/PPCallbacks.h"
-#include "clang/Lex/Preprocessor.h"
-#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/Path.h"
-#include 
-
-namespace clang {
-namespace tidy {
-namespace fuchsia {
-
-class RestrictedIncludesPPCallbacks : public PPCallbacks {
-public:
-  explicit RestrictedIncludesPPCallbacks(RestrictSystemIncludesCheck &Check,
- SourceManager &SM)
-  : Check(Check), SM(SM) {}
-
-  void InclusionDirective(SourceLocation HashLoc, cons

[PATCH] D46664: Fix null MSInheritanceAttr deref in CXXRecordDecl::getMSInheritanceModel()

2018-05-09 Thread Andrew Rogers via Phabricator via cfe-commits
adr26 created this revision.
adr26 added a reviewer: rnk.
adr26 added a project: clang.
Herald added a subscriber: cfe-commits.

Ensure latest MPT decl has a MSInheritanceAttr when instantiating templates, to 
avoid null MSInheritanceAttr deref in CXXRecordDecl::getMSInheritanceModel().

See PR#37399 for repo / details.


Repository:
  rC Clang

https://reviews.llvm.org/D46664

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp


Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1551,6 +1551,8 @@
 LocalInstantiations.perform();
   }
 
+  SemaRef.CheckCXXRecordDecl(Record, PrevDecl);
+
   SemaRef.DiagnoseUnusedNestedTypedefs(Record);
 
   return Record;
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -7076,6 +7076,21 @@
 << TemplateParams->getSourceRange();
 }
 
+void Sema::CheckCXXRecordDecl(CXXRecordDecl *Record, CXXRecordDecl *Prev)
+{
+  if (Prev && Prev->hasAttr()) {
+MSInheritanceAttr::Spelling IM = Prev->getMSInheritanceModel();
+Record->addAttr(MSInheritanceAttr::CreateImplicit(
+getASTContext(), IM,
+/*BestCase=*/MSPointerToMemberRepresentationMethod ==
+LangOptions::PPTMK_BestCase,
+ImplicitMSInheritanceAttrLoc.isValid()
+? ImplicitMSInheritanceAttrLoc
+: Record->getSourceRange()));
+Consumer.AssignInheritanceModel(Record);
+  }
+}
+
 /// Determine what kind of template specialization the given declaration
 /// is.
 static TemplateSpecializationKind getTemplateSpecializationKind(Decl *D) {
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -6470,6 +6470,8 @@
 
   bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
 
+  void CheckCXXRecordDecl(CXXRecordDecl *Record, CXXRecordDecl *Prev);
+
   /// Called when the parser has parsed a C++ typename
   /// specifier, e.g., "typename T::type".
   ///


Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1551,6 +1551,8 @@
 LocalInstantiations.perform();
   }
 
+  SemaRef.CheckCXXRecordDecl(Record, PrevDecl);
+
   SemaRef.DiagnoseUnusedNestedTypedefs(Record);
 
   return Record;
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -7076,6 +7076,21 @@
 << TemplateParams->getSourceRange();
 }
 
+void Sema::CheckCXXRecordDecl(CXXRecordDecl *Record, CXXRecordDecl *Prev)
+{
+  if (Prev && Prev->hasAttr()) {
+MSInheritanceAttr::Spelling IM = Prev->getMSInheritanceModel();
+Record->addAttr(MSInheritanceAttr::CreateImplicit(
+getASTContext(), IM,
+/*BestCase=*/MSPointerToMemberRepresentationMethod ==
+LangOptions::PPTMK_BestCase,
+ImplicitMSInheritanceAttrLoc.isValid()
+? ImplicitMSInheritanceAttrLoc
+: Record->getSourceRange()));
+Consumer.AssignInheritanceModel(Record);
+  }
+}
+
 /// Determine what kind of template specialization the given declaration
 /// is.
 static TemplateSpecializationKind getTemplateSpecializationKind(Decl *D) {
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -6470,6 +6470,8 @@
 
   bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
 
+  void CheckCXXRecordDecl(CXXRecordDecl *Record, CXXRecordDecl *Prev);
+
   /// Called when the parser has parsed a C++ typename
   /// specifier, e.g., "typename T::type".
   ///
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r331905 - [tools] Updating PPCallbacks::InclusionDirective calls

2018-05-09 Thread Julie Hockett via cfe-commits
Reverted, found the memory leak and will put up a patch to fix it & reland
in a bit. Thanks!

On Wed, May 9, 2018 at 3:13 PM Evgenii Stepanov 
wrote:

> HI,
>
> ASan says there is a use-after-free after this change:
>
> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/5410/steps/check-clang%20asan/logs/stdio
>
> MSan also sees a problem, but ASan's is likely closer to the root cause:
>
> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-msan/builds/4529/steps/check-clang%20msan/logs/stdio
>
> On Wed, May 9, 2018 at 11:27 AM, Julie Hockett via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: juliehockett
>> Date: Wed May  9 11:27:37 2018
>> New Revision: 331905
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=331905&view=rev
>> Log:
>> [tools] Updating PPCallbacks::InclusionDirective calls
>>
>> [revision] added SrcMgr::CharacteristicKind to the InclusionDirective
>> callback, this revision updates instances of it in clang-tools-extra.
>>
>> Differential Revision: https://reviews.llvm.org/D46615
>>
>> Modified:
>> clang-tools-extra/trunk/clang-move/ClangMove.cpp
>> clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
>>
>> clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
>> clang-tools-extra/trunk/clangd/ClangdUnit.cpp
>> clang-tools-extra/trunk/clangd/Headers.cpp
>> clang-tools-extra/trunk/modularize/CoverageChecker.cpp
>> clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
>> clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp
>> clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.h
>>
>> Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=331905&r1=331904&r2=331905&view=diff
>>
>> ==
>> --- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
>> +++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Wed May  9 11:27:37
>> 2018
>> @@ -131,7 +131,8 @@ public:
>>clang::CharSourceRange FilenameRange,
>>const clang::FileEntry * /*File*/,
>>StringRef SearchPath, StringRef
>> /*RelativePath*/,
>> -  const clang::Module * /*Imported*/) override {
>> +  const clang::Module * /*Imported*/,
>> +  SrcMgr::CharacteristicKind /*FileType*/)
>> override {
>>  if (const auto *FileEntry =
>> SM.getFileEntryForID(SM.getFileID(HashLoc)))
>>MoveTool->addIncludes(FileName, IsAngled, SearchPath,
>>  FileEntry->getName(), FilenameRange, SM);
>>
>> Modified: clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp?rev=331905&r1=331904&r2=331905&view=diff
>>
>> ==
>> --- clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
>> (original)
>> +++ clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp Wed
>> May  9 11:27:37 2018
>> @@ -28,7 +28,8 @@ public:
>>StringRef FileName, bool IsAngled,
>>CharSourceRange FilenameRange, const FileEntry
>> *File,
>>StringRef SearchPath, StringRef RelativePath,
>> -  const Module *Imported) override;
>> +  const Module *Imported,
>> +  SrcMgr::CharacteristicKind FileType) override;
>>void EndOfMainFile() override;
>>
>>  private:
>> @@ -76,7 +77,8 @@ static int getPriority(StringRef Filenam
>>  void IncludeOrderPPCallbacks::InclusionDirective(
>>  SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
>>  bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
>> -StringRef SearchPath, StringRef RelativePath, const Module
>> *Imported) {
>> +StringRef SearchPath, StringRef RelativePath, const Module *Imported,
>> +SrcMgr::CharacteristicKind FileType) {
>>// We recognize the first include as a special main module header and
>> want
>>// to leave it in the top position.
>>IncludeDirective ID = {HashLoc, FilenameRange, FileName, IsAngled,
>> false};
>>
>> Modified:
>> clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp?rev=331905&r1=331904&r2=331905&view=diff
>>
>> ==
>> ---
>> clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
>> (original)
>> +++
>> clang-tools-extra/trunk/c

[clang-tools-extra] r331931 - Revert "[tools] Updating PPCallbacks::InclusionDirective calls"

2018-05-09 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Wed May  9 15:25:43 2018
New Revision: 331931

URL: http://llvm.org/viewvc/llvm-project?rev=331931&view=rev
Log:
Revert "[tools] Updating PPCallbacks::InclusionDirective calls"

This reverts commit r331905, since it's dependent on reverted r331905.

Modified:
clang-tools-extra/trunk/clang-move/ClangMove.cpp
clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/Headers.cpp
clang-tools-extra/trunk/modularize/CoverageChecker.cpp
clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp
clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.h

Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=331931&r1=331930&r2=331931&view=diff
==
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Wed May  9 15:25:43 2018
@@ -131,8 +131,7 @@ public:
   clang::CharSourceRange FilenameRange,
   const clang::FileEntry * /*File*/,
   StringRef SearchPath, StringRef /*RelativePath*/,
-  const clang::Module * /*Imported*/,
-  SrcMgr::CharacteristicKind /*FileType*/) override {
+  const clang::Module * /*Imported*/) override {
 if (const auto *FileEntry = SM.getFileEntryForID(SM.getFileID(HashLoc)))
   MoveTool->addIncludes(FileName, IsAngled, SearchPath,
 FileEntry->getName(), FilenameRange, SM);

Modified: clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp?rev=331931&r1=331930&r2=331931&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp Wed May  9 
15:25:43 2018
@@ -28,8 +28,7 @@ public:
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported,
-  SrcMgr::CharacteristicKind FileType) override;
+  const Module *Imported) override;
   void EndOfMainFile() override;
 
 private:
@@ -77,8 +76,7 @@ static int getPriority(StringRef Filenam
 void IncludeOrderPPCallbacks::InclusionDirective(
 SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
 bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
-StringRef SearchPath, StringRef RelativePath, const Module *Imported,
-SrcMgr::CharacteristicKind FileType) {
+StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
   // We recognize the first include as a special main module header and want
   // to leave it in the top position.
   IncludeDirective ID = {HashLoc, FilenameRange, FileName, IsAngled, false};

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp?rev=331931&r1=331930&r2=331931&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp Wed 
May  9 15:25:43 2018
@@ -30,8 +30,7 @@ public:
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported,
-  SrcMgr::CharacteristicKind FileType) override;
+  const Module *Imported) override;
 
 private:
   ClangTidyCheck &Check;
@@ -95,8 +94,7 @@ IncludeModernizePPCallbacks::IncludeMode
 void IncludeModernizePPCallbacks::InclusionDirective(
 SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
 bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
-StringRef SearchPath, StringRef RelativePath, const Module *Imported,
-SrcMgr::CharacteristicKind FileType) {
+StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
   // FIXME: Take care 

[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE331930: [clang-tidy] Adding RestrictSystemIncludes check 
to Fuchsia module (authored by juliehockett, committed by ).

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43778

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
  clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/a.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/j.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/s.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/t.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
  test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
  test/clang-tidy/fuchsia-restrict-system-includes.cpp

Index: clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
===
--- clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
+++ clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
@@ -0,0 +1,46 @@
+//===--- RestrictSystemIncludesCheck.h - clang-tidy-- *- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H
+
+#include "../ClangTidy.h"
+#include "../utils/OptionsUtils.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Checks for allowed includes and suggests removal of any others. If no
+/// includes are specified, the check will exit without issuing any warnings.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-restrict-system-includes.html
+class RestrictSystemIncludesCheck : public ClangTidyCheck {
+public:
+  RestrictSystemIncludesCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context),
+AllowedIncludes(
+utils::options::parseStringList(Options.get("Includes", ""))) {}
+
+  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  const std::vector &getAllowedIncludes() const {
+return AllowedIncludes;
+  }
+
+private:
+  std::vector AllowedIncludes;
+};
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H
Index: clang-tidy/fuchsia/CMakeLists.txt
===
--- clang-tidy/fuchsia/CMakeLists.txt
+++ clang-tidy/fuchsia/CMakeLists.txt
@@ -5,6 +5,7 @@
   FuchsiaTidyModule.cpp
   MultipleInheritanceCheck.cpp
   OverloadedOperatorCheck.cpp
+  RestrictSystemIncludesCheck.cpp
   StaticallyConstructedObjectsCheck.cpp
   TrailingReturnCheck.cpp
   VirtualInheritanceCheck.cpp
Index: clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
===
--- clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
+++ clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
@@ -0,0 +1,126 @@
+//===--- RestrictSystemIncludesCheck.cpp - clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "RestrictSystemIncludesCheck.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Path.h"
+#include 
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+class RestrictedIncludesPPCallbacks : public PPCallbacks {
+public:
+  explicit RestrictedIncludesPPCallbacks(RestrictSystemIncludesCheck &Check,
+ SourceManager &SM)
+  : Check(Check), SM(SM) {}
+
+  void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
+  StringRef FileName, bool IsAngled,
+  CharSourceRange FilenameRange, con

r331932 - Revert "[clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective"

2018-05-09 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Wed May  9 15:25:47 2018
New Revision: 331932

URL: http://llvm.org/viewvc/llvm-project?rev=331932&view=rev
Log:
Revert "[clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective"

This reverts commit r331904 because of a memory leak.

Modified:
cfe/trunk/include/clang/Lex/PPCallbacks.h
cfe/trunk/include/clang/Lex/PreprocessingRecord.h
cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp
cfe/trunk/lib/CodeGen/MacroPPCallbacks.h
cfe/trunk/lib/Frontend/DependencyFile.cpp
cfe/trunk/lib/Frontend/DependencyGraph.cpp
cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PreprocessingRecord.cpp
cfe/trunk/tools/libclang/Indexing.cpp
cfe/trunk/unittests/Lex/PPCallbacksTest.cpp

Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=331932&r1=331931&r2=331932&view=diff
==
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Wed May  9 15:25:47 2018
@@ -117,10 +117,6 @@ public:
   /// \param Imported The module, whenever an inclusion directive was
   /// automatically turned into a module import or null otherwise.
   ///
-  /// \param FileType The characteristic kind, indicates whether a file or
-  /// directory holds normal user code, system code, or system code which is
-  /// implicitly 'extern "C"' in C++ mode.
-  ///
   virtual void InclusionDirective(SourceLocation HashLoc,
   const Token &IncludeTok,
   StringRef FileName,
@@ -129,8 +125,7 @@ public:
   const FileEntry *File,
   StringRef SearchPath,
   StringRef RelativePath,
-  const Module *Imported,
-  SrcMgr::CharacteristicKind FileType) {
+  const Module *Imported) {
   }
 
   /// Callback invoked whenever there was an explicit module-import
@@ -372,14 +367,13 @@ public:
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported,
-  SrcMgr::CharacteristicKind FileType) override {
+  const Module *Imported) override {
 First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
   FilenameRange, File, SearchPath, RelativePath,
-  Imported, FileType);
+  Imported);
 Second->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
FilenameRange, File, SearchPath, RelativePath,
-   Imported, FileType);
+   Imported);
   }
 
   void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path,

Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=331932&r1=331931&r2=331932&view=diff
==
--- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Wed May  9 15:25:47 2018
@@ -532,8 +532,8 @@ class Token;
 StringRef FileName, bool IsAngled,
 CharSourceRange FilenameRange,
 const FileEntry *File, StringRef SearchPath,
-StringRef RelativePath, const Module *Imported,
-SrcMgr::CharacteristicKind FileType) override;
+StringRef RelativePath,
+const Module *Imported) override;
 void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDefinition &MD) override;
 void Ifndef(SourceLocation Loc, const Token &MacroNameTok,

Modified: cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp?rev=331932&r1=331931&r2=331932&view=diff
==
--- cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp (original)
+++ cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp Wed May  9 15:25:47 2018
@@ -178,8 +178,7 @@ void MacroPPCallbacks::FileChanged(Sourc
 void MacroPPCallbacks::InclusionDirective(
 SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
 bool I

[clang-tools-extra] r331930 - [clang-tidy] Adding RestrictSystemIncludes check to Fuchsia module

2018-05-09 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Wed May  9 15:25:42 2018
New Revision: 331930

URL: http://llvm.org/viewvc/llvm-project?rev=331930&view=rev
Log:
[clang-tidy] Adding RestrictSystemIncludes check to Fuchsia module

Adding a check to restrict system includes to a whitelist. Given a list
of includes that are explicitly allowed, the check issues a fixit to
remove any system include not on that list from the source file.

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

Added:
clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/a.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/j.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/s.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/t.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h

clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt?rev=331930&r1=331929&r2=331930&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt Wed May  9 
15:25:42 2018
@@ -5,6 +5,7 @@ add_clang_library(clangTidyFuchsiaModule
   FuchsiaTidyModule.cpp
   MultipleInheritanceCheck.cpp
   OverloadedOperatorCheck.cpp
+  RestrictSystemIncludesCheck.cpp
   StaticallyConstructedObjectsCheck.cpp
   TrailingReturnCheck.cpp
   VirtualInheritanceCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp?rev=331930&r1=331929&r2=331930&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp Wed May  9 
15:25:42 2018
@@ -14,6 +14,7 @@
 #include "DefaultArgumentsCheck.h"
 #include "MultipleInheritanceCheck.h"
 #include "OverloadedOperatorCheck.h"
+#include "RestrictSystemIncludesCheck.h"
 #include "StaticallyConstructedObjectsCheck.h"
 #include "TrailingReturnCheck.h"
 #include "VirtualInheritanceCheck.h"
@@ -36,6 +37,8 @@ public:
 "fuchsia-multiple-inheritance");
 CheckFactories.registerCheck(
 "fuchsia-overloaded-operator");
+CheckFactories.registerCheck(
+"fuchsia-restrict-system-includes");
 CheckFactories.registerCheck(
 "fuchsia-statically-constructed-objects");
 CheckFactories.registerCheck(

Added: 
clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp?rev=331930&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp 
Wed May  9 15:25:42 2018
@@ -0,0 +1,126 @@
+//===--- RestrictSystemIncludesCheck.cpp - 
clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "RestrictSystemIncludesCheck.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Suppor

[PATCH] D46241: [CodeGen] Recognize more cases of zero initialization

2018-05-09 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGExprConstant.cpp:1413
+  } else if (!Init->isEvaluatable(CE.CGM.getContext())) {
+return false;
+  } else if (InitTy->hasPointerRepresentation()) {

sepavloff wrote:
> rsmith wrote:
> > sepavloff wrote:
> > > rjmccall wrote:
> > > > Aren't the null-pointer and integer-constant-expression checks below 
> > > > already checking this?  Also, `isEvaluatable` actually computes the 
> > > > full value internally (as an `APValue`), so if you're worried about the 
> > > > memory and compile-time effects of producing such a value, you really 
> > > > shouldn't call it.
> > > > 
> > > > You could reasonably move this entire function to be a method on `Expr` 
> > > > that takes an `ASTContext`.
> > > Comment for `EvaluateAsRValue` says that it tries calculate expression 
> > > agressively. Indeed, for the code:
> > > ```
> > >   decltype(nullptr) null();
> > >   int *p = null();
> > > ```
> > > compiler ignores potential side effect of `null()` and removes the call, 
> > > leaving only zero initialization. `isNullPointerConstant` behaves 
> > > similarly.
> > Nonetheless, it looks like this function could evaluate `Init` up to three 
> > times, which seems unreasonable. Instead of the checks based on trying to 
> > evaluate the initializer (`isNullPointerConstant` + 
> > `isIntegerConstantExpr`), how about calling `VarDecl::evaluateValue()` 
> > (which will return a potentially pre-computed and cached initializer value) 
> > and checking if the result is a zero constant?
> > 
> > In fact, `tryEmitPrivateForVarInit` already does most of that for you, and 
> > the right place to make this change is probably in 
> > `tryEmitPrivateForMemory`, where you can test to see if the `APValue` is 
> > zero-initialized and produce a `zeroinitializer` if so. As a side-benefit, 
> > putting the change there will mean we'll also start using `zeroinitializer` 
> > for zero-initialized subobjects of objects that have non-zero pieces.
> An important point in this patch is that CodeGen tries to find out, if the 
> initializer can be replaced with zeroinitializer, *prior* to the evaluation 
> of it. For huge arrays the evaluation consumes huge amount of memory and time 
> and it must be avoided.
> 
> With this patch CodeGen may evaluate parts of the initializer, if it is 
> represented by `InitListExpr`. It may cause redundant calculation, for 
> instance if the check for zero initialization failed but the initializer is 
> constant. To avoid this redundancy we could cache result of evaluation in 
> instances of `Expr` and then use the partial values in the evaluation of the 
> initializer. The simple use case solved by this patch probably is not a 
> sufficient justification for such redesign.
I really think you should have some sort of type restriction in front of this 
so that you don't end up creating a huge APValue only to throw it away because 
it's not an int or a pointer.  It's quite possible to have something like an 
array initializer in a nested position that's not within an InitListExpr , e.g. 
due to compound literals or std::initializer_list.


Repository:
  rC Clang

https://reviews.llvm.org/D46241



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


Re: [clang-tools-extra] r331905 - [tools] Updating PPCallbacks::InclusionDirective calls

2018-05-09 Thread Evgenii Stepanov via cfe-commits
HI,

ASan says there is a use-after-free after this change:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/5410/steps/check-clang%20asan/logs/stdio

MSan also sees a problem, but ASan's is likely closer to the root cause:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-msan/builds/4529/steps/check-clang%20msan/logs/stdio

On Wed, May 9, 2018 at 11:27 AM, Julie Hockett via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: juliehockett
> Date: Wed May  9 11:27:37 2018
> New Revision: 331905
>
> URL: http://llvm.org/viewvc/llvm-project?rev=331905&view=rev
> Log:
> [tools] Updating PPCallbacks::InclusionDirective calls
>
> [revision] added SrcMgr::CharacteristicKind to the InclusionDirective
> callback, this revision updates instances of it in clang-tools-extra.
>
> Differential Revision: https://reviews.llvm.org/D46615
>
> Modified:
> clang-tools-extra/trunk/clang-move/ClangMove.cpp
> clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
> clang-tools-extra/trunk/clang-tidy/modernize/
> DeprecatedHeadersCheck.cpp
> clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
> clang-tools-extra/trunk/clangd/ClangdUnit.cpp
> clang-tools-extra/trunk/clangd/Headers.cpp
> clang-tools-extra/trunk/modularize/CoverageChecker.cpp
> clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
> clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp
> clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.h
>
> Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/clang-move/ClangMove.cpp?rev=331905&r1=331904&r2=331905&view=diff
> 
> ==
> --- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
> +++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Wed May  9 11:27:37
> 2018
> @@ -131,7 +131,8 @@ public:
>clang::CharSourceRange FilenameRange,
>const clang::FileEntry * /*File*/,
>StringRef SearchPath, StringRef
> /*RelativePath*/,
> -  const clang::Module * /*Imported*/) override {
> +  const clang::Module * /*Imported*/,
> +  SrcMgr::CharacteristicKind /*FileType*/)
> override {
>  if (const auto *FileEntry = SM.getFileEntryForID(SM.
> getFileID(HashLoc)))
>MoveTool->addIncludes(FileName, IsAngled, SearchPath,
>  FileEntry->getName(), FilenameRange, SM);
>
> Modified: clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/clang-tidy/llvm/IncludeOrderCheck.cpp?rev=
> 331905&r1=331904&r2=331905&view=diff
> 
> ==
> --- clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
> (original)
> +++ clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp Wed
> May  9 11:27:37 2018
> @@ -28,7 +28,8 @@ public:
>StringRef FileName, bool IsAngled,
>CharSourceRange FilenameRange, const FileEntry
> *File,
>StringRef SearchPath, StringRef RelativePath,
> -  const Module *Imported) override;
> +  const Module *Imported,
> +  SrcMgr::CharacteristicKind FileType) override;
>void EndOfMainFile() override;
>
>  private:
> @@ -76,7 +77,8 @@ static int getPriority(StringRef Filenam
>  void IncludeOrderPPCallbacks::InclusionDirective(
>  SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
>  bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
> -StringRef SearchPath, StringRef RelativePath, const Module *Imported)
> {
> +StringRef SearchPath, StringRef RelativePath, const Module *Imported,
> +SrcMgr::CharacteristicKind FileType) {
>// We recognize the first include as a special main module header and
> want
>// to leave it in the top position.
>IncludeDirective ID = {HashLoc, FilenameRange, FileName, IsAngled,
> false};
>
> Modified: clang-tools-extra/trunk/clang-tidy/modernize/
> DeprecatedHeadersCheck.cpp
> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp?
> rev=331905&r1=331904&r2=331905&view=diff
> 
> ==
> --- clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
> (original)
> +++ clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
> Wed May  9 11:27:37 2018
> @@ -30,7 +30,8 @@ public:
>StringRef FileName, bool IsAngled,
>CharSourceRange FilenameRange, const FileEntry
> *File,

r331928 - Update pragma-attribute-supported-attributes-list.test.

2018-05-09 Thread Manoj Gupta via cfe-commits
Author: manojgupta
Date: Wed May  9 15:05:53 2018
New Revision: 331928

URL: http://llvm.org/viewvc/llvm-project?rev=331928&view=rev
Log:
Update pragma-attribute-supported-attributes-list.test.

Update the test to include the new attribute NoStackProtector
to fix the build fails.

Modified:
cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test

Modified: cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test?rev=331928&r1=331927&r2=331928&view=diff
==
--- cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test 
(original)
+++ cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test Wed May 
 9 15:05:53 2018
@@ -2,7 +2,7 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 68 attributes:
+// CHECK: #pragma clang attribute supports 69 attributes:
 // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function)
@@ -41,6 +41,7 @@
 // CHECK-NEXT: NoSanitize (SubjectMatchRule_function, 
SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: NoSanitizeSpecific (SubjectMatchRule_function, 
SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: NoSplitStack (SubjectMatchRule_function)
+// CHECK-NEXT: NoStackProtector (SubjectMatchRule_function)
 // CHECK-NEXT: NoThrow (SubjectMatchRule_function)
 // CHECK-NEXT: NotTailCalled (SubjectMatchRule_function)
 // CHECK-NEXT: ObjCBoxable (SubjectMatchRule_record)


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


[PATCH] D46496: [Tooling] Pull #include manipulation code from clangFormat into libToolingCore.

2018-05-09 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 146012.
ioeric added a comment.

- Merged with origin/master


Repository:
  rC Clang

https://reviews.llvm.org/D46496

Files:
  include/clang/Format/Format.h
  include/clang/Tooling/Core/HeaderIncludes.h
  lib/Format/Format.cpp
  lib/Tooling/Core/CMakeLists.txt
  lib/Tooling/Core/HeaderIncludes.cpp
  unittests/Format/CleanupTest.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/SortIncludesTest.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/HeaderIncludesTest.cpp

Index: unittests/Tooling/HeaderIncludesTest.cpp
===
--- /dev/null
+++ unittests/Tooling/HeaderIncludesTest.cpp
@@ -0,0 +1,527 @@
+//===- unittest/Tooling/CleanupTest.cpp - Include insertion/deletion tests ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Tooling/Core/HeaderIncludes.h"
+#include "../Tooling/ReplacementTest.h"
+#include "../Tooling/RewriterTestContext.h"
+#include "clang/Format/Format.h"
+#include "clang/Tooling/Core/Replacement.h"
+
+#include "gtest/gtest.h"
+
+using clang::tooling::ReplacementTest;
+using clang::tooling::toReplacements;
+
+namespace clang {
+namespace tooling {
+namespace {
+
+class HeaderIncludesTest : public ::testing::Test {
+protected:
+  std::string insert(llvm::StringRef Code, llvm::StringRef Header) {
+HeaderIncludes Includes(FileName, Code, Style);
+assert(Header.startswith("\"") || Header.startswith("<"));
+auto R = Includes.insert(Header.trim("\"<>"), Header.startswith("<"));
+if (!R)
+  return Code;
+auto Result = applyAllReplacements(Code, Replacements(*R));
+EXPECT_TRUE(static_cast(Result));
+return *Result;
+  }
+
+  std::string remove(llvm::StringRef Code, llvm::StringRef Header) {
+HeaderIncludes Includes(FileName, Code, Style);
+assert(Header.startswith("\"") || Header.startswith("<"));
+auto Replaces = Includes.remove(Header.trim("\"<>"), Header.startswith("<"));
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+return *Result;
+  }
+
+  const std::string FileName = "fix.cpp";
+  IncludeStyle Style = format::getLLVMStyle().IncludeStyle;
+};
+
+TEST_F(HeaderIncludesTest, NoExistingIncludeWithoutDefine) {
+  std::string Code = "int main() {}";
+  std::string Expected = "#include \"a.h\"\n"
+ "int main() {}";
+  EXPECT_EQ(Expected, insert(Code, "\"a.h\""));
+}
+
+TEST_F(HeaderIncludesTest, NoExistingIncludeWithDefine) {
+  std::string Code = "#ifndef A_H\n"
+ "#define A_H\n"
+ "class A {};\n"
+ "#define MMM 123\n"
+ "#endif";
+  std::string Expected = "#ifndef A_H\n"
+ "#define A_H\n"
+ "#include \"b.h\"\n"
+ "class A {};\n"
+ "#define MMM 123\n"
+ "#endif";
+
+  EXPECT_EQ(Expected, insert(Code, "\"b.h\""));
+}
+
+TEST_F(HeaderIncludesTest, InsertBeforeCategoryWithLowerPriority) {
+  std::string Code = "#ifndef A_H\n"
+ "#define A_H\n"
+ "\n"
+ "\n"
+ "\n"
+ "#include \n"
+ "class A {};\n"
+ "#define MMM 123\n"
+ "#endif";
+  std::string Expected = "#ifndef A_H\n"
+ "#define A_H\n"
+ "\n"
+ "\n"
+ "\n"
+ "#include \"a.h\"\n"
+ "#include \n"
+ "class A {};\n"
+ "#define MMM 123\n"
+ "#endif";
+
+  EXPECT_EQ(Expected, insert(Code, "\"a.h\""));
+}
+
+TEST_F(HeaderIncludesTest, InsertAfterMainHeader) {
+  std::string Code = "#include \"fix.h\"\n"
+ "\n"
+ "int main() {}";
+  std::string Expected = "#include \"fix.h\"\n"
+ "#include \n"
+ "\n"
+ "int main() {}";
+  Style = format::getGoogleStyle(format::FormatStyle::LanguageKind::LK_Cpp)
+  .IncludeStyle;
+  EXPECT_EQ(Expected, insert(Code, ""));
+}
+
+TEST_F(HeaderIncludesTest, InsertBeforeSystemHeaderLLVM) {
+  std::string Code = "#include \n"
+ "\n"
+ "int main() {}";
+  std::string Expected = "#include \"z.h\"\n"
+ "#include \n"
+ "\n"
+ "int main() {}";
+  EXPECT_EQ(Expected, insert(Code, "\"z.h\""));
+}
+
+TEST_F(HeaderIncludesTest, InsertAfterSystemHeaderGoogle) {
+  std::strin

[PATCH] D46300: [Clang] Implement function attribute no_stack_protector.

2018-05-09 Thread Manoj Gupta via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC331925: [Clang] Implement function attribute 
no_stack_protector. (authored by manojgupta, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46300?vs=145988&id=146008#toc

Repository:
  rC Clang

https://reviews.llvm.org/D46300

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/stack-protector.c
  test/Sema/no_stack_protector.c

Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -2740,6 +2740,28 @@
   }];
 }
 
+def NoStackProtectorDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the ``__attribute__((no_stack_protector))`` attribute which disables
+the stack protector on the specified function. This attribute is useful for
+selectively disabling the stack protector on some functions when building with
+``-fstack-protector`` compiler option.
+
+For example, it disables the stack protector for the function ``foo`` but function
+``bar`` will still be built with the stack protector with the ``-fstack-protector``
+option.
+
+.. code-block:: c
+
+int __attribute__((no_stack_protector))
+foo (int x); // stack protection will be disabled for foo.
+
+int bar(int y); // bar can be built with the stack protector.
+
+}];
+}
+
 def NotTailCalledDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -1495,6 +1495,12 @@
   let Documentation = [NotTailCalledDocs];
 }
 
+def NoStackProtector : InheritableAttr {
+  let Spellings = [Clang<"no_stack_protector">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [NoStackProtectorDocs];
+}
+
 def NoThrow : InheritableAttr {
   let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
   let Subjects = SubjectList<[Function]>;
Index: test/Sema/no_stack_protector.c
===
--- test/Sema/no_stack_protector.c
+++ test/Sema/no_stack_protector.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void __attribute__((no_stack_protector)) foo() {}
+int __attribute__((no_stack_protector)) var; // expected-warning {{'no_stack_protector' attribute only applies to functions}}
+void  __attribute__((no_stack_protector(2))) bar() {} // expected-error {{'no_stack_protector' attribute takes no arguments}}
Index: test/CodeGen/stack-protector.c
===
--- test/CodeGen/stack-protector.c
+++ test/CodeGen/stack-protector.c
@@ -22,6 +22,14 @@
   printf("%s\n", a);
 }
 
+// DEF: define {{.*}}void @test2(i8* %msg) #[[B:.*]] {
+__attribute__((no_stack_protector))
+void test2(const char *msg) {
+  char a[strlen(msg) + 1];
+  strcpy(a, msg);
+  printf("%s\n", a);
+}
+
 // NOSSP-NOT: attributes #[[A]] = {{.*}} ssp
 // SSP: attributes #[[A]] = {{.*}} ssp{{ }}
 // SSPSTRONG: attributes #[[A]] = {{.*}} sspstrong
@@ -33,3 +41,15 @@
 // SAFESTACK-SSP: attributes #[[A]] = {{.*}} safestack ssp{{ }}
 // SAFESTACK-SSPSTRONG: attributes #[[A]] = {{.*}} safestack sspstrong
 // SAFESTACK-SSPREQ: attributes #[[A]] = {{.*}} safestack sspreq
+
+// NOSSP-NOT: attributes #[[B]] = {{.*}} ssp
+// SSP-NOT: attributes #[[B]] = {{.*}} ssp{{ }}
+// SSPSTRONG-NOT: attributes #[[B]] = {{.*}} sspstrong
+// SSPREQ-NOT: attributes #[[B]] = {{.*}} sspreq
+
+// SAFESTACK-SSP: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSP-NOT: attributes #[[B]] = {{.*}} safestack ssp{{ }}
+// SAFESTACK-SSPSTRONG: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSPSTRONG-NOT: attributes #[[B]] = {{.*}} safestack sspstrong
+// SAFESTACK-SSPREQ: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSPREQ-NOT: attributes #[[B]] = {{.*}} safestack sspreq
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1142,12 +1142,14 @@
   if (!hasUnwindExceptions(LangOpts))
 B.addAttribute(llvm::Attribute::NoUnwind);
 
-  if (LangOpts.getStackProtector() == LangOptions::SSPOn)
-B.addAttribute(llvm::Attribute::StackProtect);
-  else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
-B.addAttribute(llvm::Attribute::StackProtectStrong);
-  else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
-B.addAttribute(llvm::Attribute::StackProtectReq);
+  if (!D || !D->hasAttr()) {
+if (LangOpts.getStackProtector() == LangOptions::SSPOn)
+  B.addAttribute(llvm::Attribute::StackProtect);
+else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
+  B.addAttribute(llvm::A

r331925 - [Clang] Implement function attribute no_stack_protector.

2018-05-09 Thread Manoj Gupta via cfe-commits
Author: manojgupta
Date: Wed May  9 14:41:18 2018
New Revision: 331925

URL: http://llvm.org/viewvc/llvm-project?rev=331925&view=rev
Log:
[Clang] Implement function attribute no_stack_protector.

Summary:
This attribute tells clang to skip this function from stack protector
when -stack-protector option is passed.
GCC option for this is:
__attribute__((__optimize__("no-stack-protector"))) and the
equivalent clang syntax would be: __attribute__((no_stack_protector))

This is used in Linux kernel to selectively disable stack protector
in certain functions.

Reviewers: aaron.ballman, rsmith, rnk, probinson

Reviewed By: aaron.ballman

Subscribers: probinson, srhines, cfe-commits

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

Added:
cfe/trunk/test/Sema/no_stack_protector.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/CodeGen/stack-protector.c

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=331925&r1=331924&r2=331925&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed May  9 14:41:18 2018
@@ -1495,6 +1495,12 @@ def NotTailCalled : InheritableAttr {
   let Documentation = [NotTailCalledDocs];
 }
 
+def NoStackProtector : InheritableAttr {
+  let Spellings = [Clang<"no_stack_protector">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [NoStackProtectorDocs];
+}
+
 def NoThrow : InheritableAttr {
   let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
   let Subjects = SubjectList<[Function]>;

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=331925&r1=331924&r2=331925&view=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Wed May  9 14:41:18 2018
@@ -2740,6 +2740,28 @@ The syntax of the declare target directi
   }];
 }
 
+def NoStackProtectorDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the ``__attribute__((no_stack_protector))`` attribute which 
disables
+the stack protector on the specified function. This attribute is useful for
+selectively disabling the stack protector on some functions when building with
+``-fstack-protector`` compiler option.
+
+For example, it disables the stack protector for the function ``foo`` but 
function
+``bar`` will still be built with the stack protector with the 
``-fstack-protector``
+option.
+
+.. code-block:: c
+
+int __attribute__((no_stack_protector))
+foo (int x); // stack protection will be disabled for foo.
+
+int bar(int y); // bar can be built with the stack protector.
+
+}];
+}
+
 def NotTailCalledDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=331925&r1=331924&r2=331925&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed May  9 14:41:18 2018
@@ -1142,12 +1142,14 @@ void CodeGenModule::SetLLVMFunctionAttri
   if (!hasUnwindExceptions(LangOpts))
 B.addAttribute(llvm::Attribute::NoUnwind);
 
-  if (LangOpts.getStackProtector() == LangOptions::SSPOn)
-B.addAttribute(llvm::Attribute::StackProtect);
-  else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
-B.addAttribute(llvm::Attribute::StackProtectStrong);
-  else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
-B.addAttribute(llvm::Attribute::StackProtectReq);
+  if (!D || !D->hasAttr()) {
+if (LangOpts.getStackProtector() == LangOptions::SSPOn)
+  B.addAttribute(llvm::Attribute::StackProtect);
+else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
+  B.addAttribute(llvm::Attribute::StackProtectStrong);
+else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
+  B.addAttribute(llvm::Attribute::StackProtectReq);
+  }
 
   if (!D) {
 // If we don't have a declaration to control inlining, the function isn't

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=331925&r1=331924&r2=331925&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed May  9 14:41:18 2018
@@ -6230,6 +6230,10 @@ static void ProcessDeclAttribute(Sema &S
   case AttributeList::AT_NoInst

[PATCH] D46176: Add SourceManagerForFile helper which sets up SourceManager and dependencies for a single file with code snippet

2018-05-09 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331923: Add SourceManagerForFile helper which sets up 
SourceManager and dependencies… (authored by ioeric, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D46176

Files:
  cfe/trunk/include/clang/Basic/SourceManager.h
  cfe/trunk/lib/Basic/SourceManager.cpp
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/lib/Format/SortJavaScriptImports.cpp
  cfe/trunk/lib/Format/TokenAnalyzer.cpp
  cfe/trunk/lib/Format/TokenAnalyzer.h

Index: cfe/trunk/lib/Format/SortJavaScriptImports.cpp
===
--- cfe/trunk/lib/Format/SortJavaScriptImports.cpp
+++ cfe/trunk/lib/Format/SortJavaScriptImports.cpp
@@ -445,10 +445,9 @@
 ArrayRef Ranges,
 StringRef FileName) {
   // FIXME: Cursor support.
-  std::unique_ptr Env =
-  Environment::CreateVirtualEnvironment(Code, FileName, Ranges);
-  JavaScriptImportSorter Sorter(*Env, Style);
-  return Sorter.process().first;
+  return JavaScriptImportSorter(Environment(Code, FileName, Ranges), Style)
+  .process()
+  .first;
 }
 
 } // end namespace format
Index: cfe/trunk/lib/Format/TokenAnalyzer.h
===
--- cfe/trunk/lib/Format/TokenAnalyzer.h
+++ cfe/trunk/lib/Format/TokenAnalyzer.h
@@ -37,44 +37,24 @@
 class Environment {
 public:
   Environment(SourceManager &SM, FileID ID, ArrayRef Ranges)
-  : ID(ID), CharRanges(Ranges.begin(), Ranges.end()), SM(SM),
-  FirstStartColumn(0),
-  NextStartColumn(0),
-  LastStartColumn(0) {}
-
-  Environment(FileID ID, std::unique_ptr FileMgr,
-  std::unique_ptr VirtualSM,
-  std::unique_ptr Diagnostics,
-  const std::vector &CharRanges,
-  unsigned FirstStartColumn,
-  unsigned NextStartColumn,
-  unsigned LastStartColumn)
-  : ID(ID), CharRanges(CharRanges.begin(), CharRanges.end()),
-SM(*VirtualSM), 
-FirstStartColumn(FirstStartColumn),
-NextStartColumn(NextStartColumn),
-LastStartColumn(LastStartColumn),
-FileMgr(std::move(FileMgr)),
-VirtualSM(std::move(VirtualSM)), Diagnostics(std::move(Diagnostics)) {}
+  : SM(SM), ID(ID), CharRanges(Ranges.begin(), Ranges.end()),
+FirstStartColumn(0), NextStartColumn(0), LastStartColumn(0) {}
 
   // This sets up an virtual file system with file \p FileName containing the
   // fragment \p Code. Assumes that \p Code starts at \p FirstStartColumn,
   // that the next lines of \p Code should start at \p NextStartColumn, and
   // that \p Code should end at \p LastStartColumn if it ends in newline.
   // See also the documentation of clang::format::internal::reformat.
-  static std::unique_ptr
-  CreateVirtualEnvironment(StringRef Code, StringRef FileName,
-   ArrayRef Ranges,
-   unsigned FirstStartColumn = 0,
-   unsigned NextStartColumn = 0,
-   unsigned LastStartColumn = 0);
+  Environment(StringRef Code, StringRef FileName,
+  ArrayRef Ranges, unsigned FirstStartColumn = 0,
+  unsigned NextStartColumn = 0, unsigned LastStartColumn = 0);
 
   FileID getFileID() const { return ID; }
 
-  ArrayRef getCharRanges() const { return CharRanges; }
-
   const SourceManager &getSourceManager() const { return SM; }
 
+  ArrayRef getCharRanges() const { return CharRanges; }
+
   // Returns the column at which the fragment of code managed by this
   // environment starts.
   unsigned getFirstStartColumn() const { return FirstStartColumn; }
@@ -88,19 +68,18 @@
   unsigned getLastStartColumn() const { return LastStartColumn; }
 
 private:
+  // This is only set if constructed from string.
+  std::unique_ptr VirtualSM;
+
+  // This refers to either a SourceManager provided by users or VirtualSM
+  // created for a single file.
+  SourceManager &SM;
   FileID ID;
+
   SmallVector CharRanges;
-  SourceManager &SM;
   unsigned FirstStartColumn;
   unsigned NextStartColumn;
   unsigned LastStartColumn;
-
-  // The order of these fields are important - they should be in the same order
-  // as they are created in `CreateVirtualEnvironment` so that they can be
-  // deleted in the reverse order as they are created.
-  std::unique_ptr FileMgr;
-  std::unique_ptr VirtualSM;
-  std::unique_ptr Diagnostics;
 };
 
 class TokenAnalyzer : public UnwrappedLineConsumer {
Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -1905,10 +1905,9 @@
 StringRef FileName, StringRef Code, const FormatStyle &Style,
 llvm::function_ref
 GetOffsetAfterSequence) {
-  std::unique_ptr E

r331923 - Add SourceManagerForFile helper which sets up SourceManager and dependencies for a single file with code snippet

2018-05-09 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Wed May  9 14:35:52 2018
New Revision: 331923

URL: http://llvm.org/viewvc/llvm-project?rev=331923&view=rev
Log:
Add SourceManagerForFile helper which sets up SourceManager and dependencies 
for a single file with code snippet

Summary: This can be used to create a virtual environment (incl. VFS, source 
manager) for code snippets.

Reviewers: sammccall, klimek

Reviewed By: sammccall

Subscribers: klimek, mgorny, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/SourceManager.h
cfe/trunk/lib/Basic/SourceManager.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/SortJavaScriptImports.cpp
cfe/trunk/lib/Format/TokenAnalyzer.cpp
cfe/trunk/lib/Format/TokenAnalyzer.h

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=331923&r1=331922&r2=331923&view=diff
==
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Wed May  9 14:35:52 2018
@@ -35,6 +35,7 @@
 #ifndef LLVM_CLANG_BASIC_SOURCEMANAGER_H
 #define LLVM_CLANG_BASIC_SOURCEMANAGER_H
 
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -60,7 +61,6 @@ namespace clang {
 
 class ASTReader;
 class ASTWriter;
-class DiagnosticsEngine;
 class LineTableInfo;
 class SourceManager;
 
@@ -1815,6 +1815,28 @@ public:
   }
 };
 
+/// SourceManager and necessary depdencies (e.g. VFS, FileManager) for a single
+/// in-memorty file.
+class SourceManagerForFile {
+public:
+  /// Creates SourceManager and necessary depdencies (e.g. VFS, FileManager).
+  /// The main file in the SourceManager will be \p FileName with \p Content.
+  SourceManagerForFile(StringRef FileName, StringRef Content);
+
+  SourceManager &get() {
+assert(SourceMgr);
+return *SourceMgr;
+  }
+
+private:
+  // The order of these fields are important - they should be in the same order
+  // as they are created in `createSourceManagerForFile` so that they can be
+  // deleted in the reverse order as they are created.
+  std::unique_ptr FileMgr;
+  std::unique_ptr Diagnostics;
+  std::unique_ptr SourceMgr;
+};
+
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_SOURCEMANAGER_H

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=331923&r1=331922&r2=331923&view=diff
==
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Wed May  9 14:35:52 2018
@@ -2258,3 +2258,29 @@ size_t SourceManager::getDataStructureSi
 
   return size;
 }
+
+SourceManagerForFile::SourceManagerForFile(StringRef FileName,
+   StringRef Content) {
+  // This is referenced by `FileMgr` and will be released by `FileMgr` when it
+  // is deleted.
+  IntrusiveRefCntPtr InMemoryFileSystem(
+  new vfs::InMemoryFileSystem);
+  InMemoryFileSystem->addFile(
+  FileName, 0,
+  llvm::MemoryBuffer::getMemBuffer(Content, FileName,
+   /*RequiresNullTerminator=*/false));
+  // This is passed to `SM` as reference, so the pointer has to be referenced
+  // in `Environment` so that `FileMgr` can out-live this function scope.
+  FileMgr =
+  llvm::make_unique(FileSystemOptions(), InMemoryFileSystem);
+  // This is passed to `SM` as reference, so the pointer has to be referenced
+  // by `Environment` due to the same reason above.
+  Diagnostics = llvm::make_unique(
+  IntrusiveRefCntPtr(new DiagnosticIDs),
+  new DiagnosticOptions);
+  SourceMgr = llvm::make_unique(*Diagnostics, *FileMgr);
+  FileID ID = SourceMgr->createFileID(FileMgr->getFile(FileName),
+  SourceLocation(), clang::SrcMgr::C_User);
+  assert(ID.isValid());
+  SourceMgr->setMainFileID(ID);
+}

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=331923&r1=331922&r2=331923&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed May  9 14:35:52 2018
@@ -1905,10 +1905,9 @@ unsigned getOffsetAfterTokenSequence(
 StringRef FileName, StringRef Code, const FormatStyle &Style,
 llvm::function_ref
 GetOffsetAfterSequence) {
-  std::unique_ptr Env =
-  Environment::CreateVirtualEnvironment(Code, FileName, /*Ranges=*/{});
-  const SourceManager &SourceMgr = Env->getSourceManager();
-  Lexer Lex(Env->getFileID(), SourceMgr.getBuffer(Env->getFileID()), SourceMgr,
+  Environment Env(Code, FileName, /*Ranges=*/{});
+  const SourceMana

[PATCH] D46176: Add SourceManagerForFile helper which sets up SourceManager and dependencies for a single file with code snippet

2018-05-09 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 146004.
ioeric marked 4 inline comments as done.
ioeric added a comment.

- address review comments.


Repository:
  rC Clang

https://reviews.llvm.org/D46176

Files:
  include/clang/Basic/SourceManager.h
  lib/Basic/SourceManager.cpp
  lib/Format/Format.cpp
  lib/Format/SortJavaScriptImports.cpp
  lib/Format/TokenAnalyzer.cpp
  lib/Format/TokenAnalyzer.h

Index: lib/Format/TokenAnalyzer.h
===
--- lib/Format/TokenAnalyzer.h
+++ lib/Format/TokenAnalyzer.h
@@ -37,44 +37,24 @@
 class Environment {
 public:
   Environment(SourceManager &SM, FileID ID, ArrayRef Ranges)
-  : ID(ID), CharRanges(Ranges.begin(), Ranges.end()), SM(SM),
-  FirstStartColumn(0),
-  NextStartColumn(0),
-  LastStartColumn(0) {}
-
-  Environment(FileID ID, std::unique_ptr FileMgr,
-  std::unique_ptr VirtualSM,
-  std::unique_ptr Diagnostics,
-  const std::vector &CharRanges,
-  unsigned FirstStartColumn,
-  unsigned NextStartColumn,
-  unsigned LastStartColumn)
-  : ID(ID), CharRanges(CharRanges.begin(), CharRanges.end()),
-SM(*VirtualSM), 
-FirstStartColumn(FirstStartColumn),
-NextStartColumn(NextStartColumn),
-LastStartColumn(LastStartColumn),
-FileMgr(std::move(FileMgr)),
-VirtualSM(std::move(VirtualSM)), Diagnostics(std::move(Diagnostics)) {}
+  : SM(SM), ID(ID), CharRanges(Ranges.begin(), Ranges.end()),
+FirstStartColumn(0), NextStartColumn(0), LastStartColumn(0) {}
 
   // This sets up an virtual file system with file \p FileName containing the
   // fragment \p Code. Assumes that \p Code starts at \p FirstStartColumn,
   // that the next lines of \p Code should start at \p NextStartColumn, and
   // that \p Code should end at \p LastStartColumn if it ends in newline.
   // See also the documentation of clang::format::internal::reformat.
-  static std::unique_ptr
-  CreateVirtualEnvironment(StringRef Code, StringRef FileName,
-   ArrayRef Ranges,
-   unsigned FirstStartColumn = 0,
-   unsigned NextStartColumn = 0,
-   unsigned LastStartColumn = 0);
+  Environment(StringRef Code, StringRef FileName,
+  ArrayRef Ranges, unsigned FirstStartColumn = 0,
+  unsigned NextStartColumn = 0, unsigned LastStartColumn = 0);
 
   FileID getFileID() const { return ID; }
 
-  ArrayRef getCharRanges() const { return CharRanges; }
-
   const SourceManager &getSourceManager() const { return SM; }
 
+  ArrayRef getCharRanges() const { return CharRanges; }
+
   // Returns the column at which the fragment of code managed by this
   // environment starts.
   unsigned getFirstStartColumn() const { return FirstStartColumn; }
@@ -88,19 +68,18 @@
   unsigned getLastStartColumn() const { return LastStartColumn; }
 
 private:
+  // This is only set if constructed from string.
+  std::unique_ptr VirtualSM;
+
+  // This refers to either a SourceManager provided by users or VirtualSM
+  // created for a single file.
+  SourceManager &SM;
   FileID ID;
+
   SmallVector CharRanges;
-  SourceManager &SM;
   unsigned FirstStartColumn;
   unsigned NextStartColumn;
   unsigned LastStartColumn;
-
-  // The order of these fields are important - they should be in the same order
-  // as they are created in `CreateVirtualEnvironment` so that they can be
-  // deleted in the reverse order as they are created.
-  std::unique_ptr FileMgr;
-  std::unique_ptr VirtualSM;
-  std::unique_ptr Diagnostics;
 };
 
 class TokenAnalyzer : public UnwrappedLineConsumer {
Index: lib/Format/TokenAnalyzer.cpp
===
--- lib/Format/TokenAnalyzer.cpp
+++ lib/Format/TokenAnalyzer.cpp
@@ -34,48 +34,19 @@
 namespace clang {
 namespace format {
 
-// This sets up an virtual file system with file \p FileName containing \p
-// Code.
-std::unique_ptr
-Environment::CreateVirtualEnvironment(StringRef Code, StringRef FileName,
-  ArrayRef Ranges,
-  unsigned FirstStartColumn,
-  unsigned NextStartColumn,
-  unsigned LastStartColumn) {
-  // This is referenced by `FileMgr` and will be released by `FileMgr` when it
-  // is deleted.
-  IntrusiveRefCntPtr InMemoryFileSystem(
-  new vfs::InMemoryFileSystem);
-  // This is passed to `SM` as reference, so the pointer has to be referenced
-  // in `Environment` so that `FileMgr` can out-live this function scope.
-  std::unique_ptr FileMgr(
-  new FileManager(FileSystemOptions(), InMemoryFileSystem));
-  // This is passed to `SM` as reference, so the pointer has to be referenced
-  // by `Environment` due to the same reason above.
-  std::unique_ptr Diagnostics(new DiagnosticsEngine(
-  

[PATCH] D46593: Allow copy elision in path concatenation

2018-05-09 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Ping @jwakely


Repository:
  rCXX libc++

https://reviews.llvm.org/D46593



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


[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.

2018-05-09 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Thanks for adding the tests!




Comment at: include/clang/AST/RawCommentList.h:138
+  /// the overload with ASTContext in the rest of the code.
+  std::string getFormattedText(const SourceManager &SourceMgr,
+   DiagnosticsEngine &Diags) const;

I think we can get rid of the interface that takes `ASTContext`? If 
`SourceManager` and `Diags` are sufficient, I don't see why we would want 
another interface for ASTContext.



Comment at: lib/AST/RawCommentList.cpp:352
+  // comments::Lexer. Therefore, we just use default-constructed options.
+  CommentOptions DefOpts;
+  comments::CommandTraits EmptyTraits(Allocator, DefOpts);

I'm not quite sure about this. Could we just require a `CommandTraits` in the 
interface? And only make this assumption in tests?



Comment at: unittests/AST/CommentTextTest.cpp:32
+  std::string formatComment(llvm::StringRef CommentText) {
+llvm::IntrusiveRefCntPtr EmptyFS(
+new vfs::InMemoryFileSystem);

`SourceManagerForFile` added in D46176 should save you a few lines here. (I'm 
landing it right now...)


Repository:
  rC Clang

https://reviews.llvm.org/D46000



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


[PATCH] D46593: Allow copy elision in path concatenation

2018-05-09 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc added a comment.

Sorry folks, but you can't just take patches to libstdc++ and apply them to 
libc++.

These libraries have different licenses, and so the author of the patch 
(Jonathan Wakely in this case) need's to *explicitly* contribute that patch to 
libc++ under libc++'s license. (Or potentially an employer who owns the rights 
to it.)

So this needs to be reverted, or Jonathan needs to hop on this thread and very 
explicitly give permission to relicense this and contribute it to LLVM. 
Generally, I would strongly encourage the original authors making contributions 
as it simplifies everything.


Repository:
  rCXX libc++

https://reviews.llvm.org/D46593



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


[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst:32
+   A string containing a semi-colon separated list of allowed include 
filenames.
+   The default is an empty string, which allows all includes.

juliehockett wrote:
> aaron.ballman wrote:
> > This default seems a bit odd to me, but perhaps it's fine. What's novel is 
> > that the check is a no-op by default, so how do Fuchsia developers get the 
> > correct list? Or is there no canonical list and developers are expected to 
> > populate their own manually?
> The idea is that it's a case-by-case basis -- this may change at some point 
> in the future if we decide there's a standard whitelist of system includes 
> across the board, but at the moment the thought is to allow everything in 
> some places, and use this check to limit them in others. It'll need to be 
> populated on a case-by-case basis, since different directories will have 
> different requirements.
So there's never a case where you need to prohibit use of all system includes? 
Right now, an empty string means "allow all includes" while a non-empty string 
means "allow only these includes", so there's no way to prohibit all includes 
except by listing them manually. I'm wondering whether you want to use a glob 
for allowed file names, which gives you extra flexibility. e.g., `*` allows all 
includes (default value), `foo.h` allows only , `experimental/*` allows 
all headers in the experimental directory, `cstd*` allows  while 
prohibiting , and the empty string will disallow all system headers.

Perhaps you don't need that level of flexibility, but for the use cases I'm 
imagining it seems more user friendly to be able to write `cstd*` rather than 
manually listing out all the C++ headers explicitly.


https://reviews.llvm.org/D43778



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


[PATCH] D46300: [Clang] Implement function attribute no_stack_protector.

2018-05-09 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D46300



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


[PATCH] D46300: [Clang] Implement function attribute no_stack_protector.

2018-05-09 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!


Repository:
  rC Clang

https://reviews.llvm.org/D46300



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


[PATCH] D45616: [X86] Lower _mm[256|512]_cmp[.]_mask intrinsics to native llvm IR

2018-05-09 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

There is no difference between "signalling" and "non-signalling" unless you're 
using "#pragma STDC FENV_ACCESS", which is currently not supported.  Presumably 
the work to implement that will include some LLVM IR intrinsic which can encode 
the difference, but for now we can ignore it.


Repository:
  rC Clang

https://reviews.llvm.org/D45616



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


Re: [PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers

2018-05-09 Thread JF Bastien via cfe-commits


> On May 9, 2018, at 1:25 PM, Shoaib Meenai via Phabricator 
>  wrote:
> 
> smeenai added a comment.
> 
> Yeah, I think we all agree now that a portability warning isn't really 
> tractable. Note that even for the warnings that motivated this diff, they 
> should have only fired if `size_t` and NSInteger had separate types, so it 
> wasn't a portability warning in that sense to begin with (as in, it would 
> only warn if there was a mismatch for your current target, not if there was a 
> potential mismatch for any target).
> 
> We still have two options:
> 
> 1. Special-case NSInteger/NSUInteger on Apple platforms so that they can 
> always be printed using `%z` without any issues.
> 2. Relax the format specifier warnings (either under a new warning option, 
> e.g. `-Wformat-relaxed`, or by relaxing `-Wformat` itself and adding 
> something like `-Wformat-pedantic`) so that you don't warn when the specifier 
> and the actual type have the same size and alignment, even when the actual 
> type is different (which would also cover the case in 1).
> 
> I'm personally in favor of 2, and I can start a discussion on cfe-dev if you 
> think we should try to achieve a broader consensus. Whichever option we went 
> with, we would also have to ensure that the optimizer didn't do anything bad 
> (as @aaron.ballman pointed out), both now and in the future

2 sounds better overall. However I don’t like a relaxed flag because it’s weird 
when you have relaxed/normal/pedantic. How do they mix? What if I want format 
warnings, but not “portability” ones. I think we either want to move this to 
pedantic and (as you propose) only warm on -Wformat if size or alignment don’t 
match. We can also have a separate -Wformat-portability warning where we try 
(and fail) to be helpful. 

Please do start a thread on cfe-dev, much appreciated!


> Repository:
>  rC Clang
> 
> https://reviews.llvm.org/D42933
> 
> 
> 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers

2018-05-09 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Yeah, I think we all agree now that a portability warning isn't really 
tractable. Note that even for the warnings that motivated this diff, they 
should have only fired if `size_t` and NSInteger had separate types, so it 
wasn't a portability warning in that sense to begin with (as in, it would only 
warn if there was a mismatch for your current target, not if there was a 
potential mismatch for any target).

We still have two options:

1. Special-case NSInteger/NSUInteger on Apple platforms so that they can always 
be printed using `%z` without any issues.
2. Relax the format specifier warnings (either under a new warning option, e.g. 
`-Wformat-relaxed`, or by relaxing `-Wformat` itself and adding something like 
`-Wformat-pedantic`) so that you don't warn when the specifier and the actual 
type have the same size and alignment, even when the actual type is different 
(which would also cover the case in 1).

I'm personally in favor of 2, and I can start a discussion on cfe-dev if you 
think we should try to achieve a broader consensus. Whichever option we went 
with, we would also have to ensure that the optimizer didn't do anything bad 
(as @aaron.ballman pointed out), both now and in the future.


Repository:
  rC Clang

https://reviews.llvm.org/D42933



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


[PATCH] D46602: [clang-tidy] Store checks profiling info as YAML files

2018-05-09 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 145995.
lebedev.ri edited the summary of this revision.
lebedev.ri added a comment.

- Make json less flat, store source filename in it.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46602

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/ClangTidy.h
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tidy/ClangTidyProfiling.cpp
  clang-tidy/ClangTidyProfiling.h
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/clang-tidy-enable-check-profile-one-tu.cpp
  test/clang-tidy/clang-tidy-enable-check-profile-two-tu.cpp
  test/clang-tidy/clang-tidy-store-check-profile-one-tu.cpp

Index: test/clang-tidy/clang-tidy-store-check-profile-one-tu.cpp
===
--- /dev/null
+++ test/clang-tidy/clang-tidy-store-check-profile-one-tu.cpp
@@ -0,0 +1,33 @@
+// RUN: clang-tidy -enable-check-profile -checks='-*,readability-function-size' -store-check-profile=%T -store-check-profile-elide-prefix=%s %s 2>&1 | FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK-CONSOLE %s
+// RUN: FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' -input-file=%T/.yaml -check-prefix=CHECK-FILE %s
+// RUN: clang-tidy -enable-check-profile -checks='-*,readability-function-size' -store-check-profile=%T/out -store-check-profile-elide-prefix=%s %s 2>&1 | FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK-CONSOLE %s
+// RUN: FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' -input-file=%T/out/.yaml -check-prefix=CHECK-FILE %s
+
+// CHECK-CONSOLE-NOT: ===-===
+// CHECK-CONSOLE-NOT: {{.*}}  --- Name ---
+// CHECK-CONSOLE-NOT: {{.*}}  readability-function-size
+// CHECK-CONSOLE-NOT: {{.*}}  Total
+// CHECK-CONSOLE-NOT: ===-===
+
+// CHECK-FILE: {
+// CHECK-FILE-NEXT:"file": "{{.*}}clang-tidy-store-check-profile-one-tu.cpp",
+// CHECK-FILE-NEXT:"profile": {
+// CHECK-FILE-NEXT:	"time.clang-tidy.readability-function-size.wall": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}},
+// CHECK-FILE-NEXT:	"time.clang-tidy.readability-function-size.user": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}},
+// CHECK-FILE-NEXT:	"time.clang-tidy.readability-function-size.sys": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}}
+// CHECK-FILE-NEXT: }
+// CHECK-FILE-NEXT: }
+
+// CHECK-FILE-NOT: {
+// CHECK-FILE-NOT: "file": {{.*}}clang-tidy-store-check-profile-one-tu.cpp{{.*}},
+// CHECK-FILE-NOT: "profile": {
+// CHECK-FILE-NOT:	"time.clang-tidy.readability-function-size.wall": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}},
+// CHECK-FILE-NOT:	"time.clang-tidy.readability-function-size.user": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}},
+// CHECK-FILE-NOT:	"time.clang-tidy.readability-function-size.sys": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}}
+// CHECK-FILE-NOT: }
+// CHECK-FILE-NOT: }
+
+class A {
+  A() {}
+  ~A() {}
+};
Index: test/clang-tidy/clang-tidy-enable-check-profile-two-tu.cpp
===
--- test/clang-tidy/clang-tidy-enable-check-profile-two-tu.cpp
+++ test/clang-tidy/clang-tidy-enable-check-profile-two-tu.cpp
@@ -1,22 +1,31 @@
 // RUN: clang-tidy -enable-check-profile -checks='-*,readability-function-size' %s %s 2>&1 | FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' %s
 
 // CHECK: ===-===
-// CHECK-NEXT: {{.*}}  --- Name ---
+// CHECK-NEXT:  clang-tidy checks profiling
+// CHECK-NEXT: ===-===
+// CHECK-NEXT: Total Execution Time: {{.*}} seconds ({{.*}} wall clock)
+
+// CHECK: {{.*}}  --- Name ---
 // CHECK-NEXT: {{.*}}  readability-function-size
 // CHECK-NEXT: {{.*}}  Total
-// CHECK-NEXT: ===-===
 
 // CHECK: ===-===
-// CHECK-NEXT: {{.*}}  --- Name ---
+// CHECK-NEXT:  clang-tidy checks profiling
+// CHECK-NEXT: ===-===
+// CHECK-NEXT: Total Execution Time: {{.*}} seconds ({{.*}} wall clock)
+
+// CHECK: {{.*}}  --- Name ---
 // CHECK-NEXT: {{.*}}  readability-function-size
 // CHECK-NEXT: {{.*}}  Total
-// CHECK-NEXT: ===-===
 
 // CHECK-NOT: ===-===
+// CHECK-NOT:  clang-tidy checks profilin

[PATCH] D46603: [Support] TimerGroup changes

2018-05-09 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 145994.
lebedev.ri added a comment.

- Use sane (not the same as the one right before..) suffix for when 
json-printing mem usage. Admittedly, i haven't tried it, but it just does not 
make sense otherwise.


Repository:
  rL LLVM

https://reviews.llvm.org/D46603

Files:
  include/llvm/Support/Timer.h
  lib/Support/Timer.cpp


Index: lib/Support/Timer.cpp
===
--- lib/Support/Timer.cpp
+++ lib/Support/Timer.cpp
@@ -22,6 +22,8 @@
 #include "llvm/Support/Process.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
+
 using namespace llvm;
 
 // This ugly hack is brought to you courtesy of constructor/destructor ordering
@@ -234,6 +236,15 @@
   TimerGroupList = this;
 }
 
+TimerGroup::TimerGroup(StringRef Name, StringRef Description,
+   const StringMap &Records)
+: TimerGroup(Name, Description) {
+  TimersToPrint.reserve(Records.size());
+  for (const auto &P : Records)
+TimersToPrint.emplace_back(P.getValue(), P.getKey(), P.getKey());
+  assert(TimersToPrint.size() == Records.size() && "Size mismatch");
+}
+
 TimerGroup::~TimerGroup() {
   // If the timer group is destroyed before the timers it owns, accumulate and
   // print the timing data.
@@ -367,13 +378,17 @@
 void TimerGroup::printJSONValue(raw_ostream &OS, const PrintRecord &R,
 const char *suffix, double Value) {
   assert(yaml::needsQuotes(Name) == yaml::QuotingType::None &&
- "TimerGroup name needs no quotes");
+ "TimerGroup name should not need quotes");
   assert(yaml::needsQuotes(R.Name) == yaml::QuotingType::None &&
- "Timer name needs no quotes");
-  OS << "\t\"time." << Name << '.' << R.Name << suffix << "\": " << Value;
+ "Timer name should not need quotes");
+  constexpr auto max_digits10 = std::numeric_limits::max_digits10;
+  OS << "\t\"time." << Name << '.' << R.Name << suffix
+ << "\": " << format("%.*e", max_digits10 - 1, Value);
 }
 
 const char *TimerGroup::printJSONValues(raw_ostream &OS, const char *delim) {
+  sys::SmartScopedLock L(*TimerLock);
+
   prepareToPrintList();
   for (const PrintRecord &R : TimersToPrint) {
 OS << delim;
@@ -387,7 +402,7 @@
 printJSONValue(OS, R, ".sys", T.getSystemTime());
 if (T.getMemUsed()) {
   OS << delim;
-  printJSONValue(OS, R, ".sys", T.getMemUsed());
+  printJSONValue(OS, R, ".mem", T.getMemUsed());
 }
   }
   TimersToPrint.clear();
Index: include/llvm/Support/Timer.h
===
--- include/llvm/Support/Timer.h
+++ include/llvm/Support/Timer.h
@@ -10,6 +10,7 @@
 #ifndef LLVM_SUPPORT_TIMER_H
 #define LLVM_SUPPORT_TIMER_H
 
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/DataTypes.h"
 #include 
@@ -194,6 +195,10 @@
 
 public:
   explicit TimerGroup(StringRef Name, StringRef Description);
+
+  explicit TimerGroup(StringRef Name, StringRef Description,
+  const StringMap &Records);
+
   ~TimerGroup();
 
   void setName(StringRef NewName, StringRef NewDescription) {
@@ -207,6 +212,8 @@
   /// This static method prints all timers and clears them all out.
   static void printAll(raw_ostream &OS);
 
+  const char *printJSONValues(raw_ostream &OS, const char *delim);
+
   /// Prints all timers as JSON key/value pairs, and clears them all out.
   static const char *printAllJSONValues(raw_ostream &OS, const char *delim);
 
@@ -223,7 +230,6 @@
   void PrintQueuedTimers(raw_ostream &OS);
   void printJSONValue(raw_ostream &OS, const PrintRecord &R,
   const char *suffix, double Value);
-  const char *printJSONValues(raw_ostream &OS, const char *delim);
 };
 
 } // end namespace llvm


Index: lib/Support/Timer.cpp
===
--- lib/Support/Timer.cpp
+++ lib/Support/Timer.cpp
@@ -22,6 +22,8 @@
 #include "llvm/Support/Process.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
+
 using namespace llvm;
 
 // This ugly hack is brought to you courtesy of constructor/destructor ordering
@@ -234,6 +236,15 @@
   TimerGroupList = this;
 }
 
+TimerGroup::TimerGroup(StringRef Name, StringRef Description,
+   const StringMap &Records)
+: TimerGroup(Name, Description) {
+  TimersToPrint.reserve(Records.size());
+  for (const auto &P : Records)
+TimersToPrint.emplace_back(P.getValue(), P.getKey(), P.getKey());
+  assert(TimersToPrint.size() == Records.size() && "Size mismatch");
+}
+
 TimerGroup::~TimerGroup() {
   // If the timer group is destroyed before the timers it owns, accumulate and
   // print the timing data.
@@ -367,13 +378,17 @@
 void TimerGroup::printJSONValue(raw_ostream &OS, const PrintRecord &R,
 const char *suffix, double Value) {
   assert(yaml::ne

[PATCH] D46084: Addition of the Fixed Point _Accum type

2018-05-09 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 145993.
leonardchan added a comment.

- Restrict usage of fixed point types only to C


https://reviews.llvm.org/D46084

Files:
  include/clang-c/Index.h
  include/clang/AST/ASTContext.h
  include/clang/AST/BuiltinTypes.def
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/DeclSpec.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/NSAPI.cpp
  lib/AST/Type.cpp
  lib/AST/TypeLoc.cpp
  lib/Analysis/PrintfFormatString.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/Index/USRGeneration.cpp
  lib/Parse/ParseDecl.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaTemplateVariadic.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTCommon.cpp
  lib/Serialization/ASTReader.cpp
  test/Frontend/accum.c
  test/Frontend/accum_errors.c
  test/Frontend/accum_errors.cpp
  tools/libclang/CXType.cpp

Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -53,6 +53,12 @@
 BTCASE(Float);
 BTCASE(Double);
 BTCASE(LongDouble);
+BTCASE(ShortAccum);
+BTCASE(Accum);
+BTCASE(LongAccum);
+BTCASE(UShortAccum);
+BTCASE(UAccum);
+BTCASE(ULongAccum);
 BTCASE(Float16);
 BTCASE(Float128);
 BTCASE(NullPtr);
@@ -542,6 +548,12 @@
 TKIND(Float);
 TKIND(Double);
 TKIND(LongDouble);
+TKIND(ShortAccum);
+TKIND(Accum);
+TKIND(LongAccum);
+TKIND(UShortAccum);
+TKIND(UAccum);
+TKIND(ULongAccum);
 TKIND(Float16);
 TKIND(Float128);
 TKIND(NullPtr);
Index: test/Frontend/accum_errors.cpp
===
--- /dev/null
+++ test/Frontend/accum_errors.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -x c++ %s -verify
+
+// Name namgling is not provided for fixed point types in c++
+
+signed short _Accum s_short_accum;  // expected-error{{Fixed point types are only allowed in C}}
+signed _Accum s_accum;  // expected-error{{Fixed point types are only allowed in C}}
+signed long _Accum s_long_accum;// expected-error{{Fixed point types are only allowed in C}}
+unsigned short _Accum u_short_accum;// expected-error{{Fixed point types are only allowed in C}}
+unsigned _Accum u_accum;// expected-error{{Fixed point types are only allowed in C}}
+unsigned long _Accum u_long_accum;  // expected-error{{Fixed point types are only allowed in C}}
+
+short _Accum short_accum;   // expected-error{{Fixed point types are only allowed in C}}
+_Accum accum;   // expected-error{{Fixed point types are only allowed in C}}
+long _Accum long_accum; // expected-error{{Fixed point types are only allowed in C}}
Index: test/Frontend/accum_errors.c
===
--- /dev/null
+++ test/Frontend/accum_errors.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -pedantic %s
+
+long long _Accum longlong_accum;  // expected-error{{'long long _Accum' is invalid}}
+unsigned long long _Accum u_longlong_accum;  // expected-error{{'long long _Accum' is invalid}}
Index: test/Frontend/accum.c
===
--- /dev/null
+++ test/Frontend/accum.c
@@ -0,0 +1,26 @@
+// RUN: %clang -cc1 -x c -ast-dump %s | FileCheck %s --strict-whitespace
+
+/*  Various contexts where type _Accum can appear. */
+
+// Primary fixed point types
+signed short _Accum s_short_accum;
+signed _Accum s_accum;
+signed long _Accum s_long_accum;
+unsigned short _Accum u_short_accum;
+unsigned _Accum u_accum;
+unsigned long _Accum u_long_accum;
+
+// Aliased fixed point types
+short _Accum short_accum;
+_Accum accum;
+long _Accum long_accum;
+
+//CHECK:  |-VarDecl {{.*}} s_short_accum 'short _Accum'
+//CHECK-NEXT: |-VarDecl {{.*}} s_accum '_Accum'
+//CHECK-NEXT: |-VarDecl {{.*}} s_long_accum 'long _Accum'
+//CHECK-NEXT: |-VarDecl {{.*}} u_short_accum 'unsigned short _Accum'
+//CHECK-NEXT: |-VarDecl {{.*}} u_accum 'unsigned _Accum'
+//CHECK-NEXT: |-VarDecl {{.*}} u_long_accum 'unsigned long _Accum'
+//CHECK-NEXT: |-VarDecl {{.*}} short_accum 'short _Accum'
+//CHECK-NEXT: |-VarDecl {{.*}} accum '_Accum'
+//CHECK-NEXT: `-VarDecl {{.*}} long_accum 'long _Accum'
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -6816,6 +6816,24 @@
 case PREDEF_TYPE_LONGDOUBLE_ID:
   T = Context.LongDoubleTy;
   break;
+case PREDEF_TYPE_SHORT_ACCUM_ID:
+  T = Context.ShortAccumTy;
+  break;
+case PREDEF_TYPE_ACCUM_ID:
+  T = Context.Acc

[PATCH] D46659: [clang-tidy/google-readability-casting] Allow C-style casts to/from Objective-C object types

2018-05-09 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added a comment.

An alternative implementation would be to allow C-style casts (either always or 
only for ObjC objects) within Objective-C methods inside Objective-C++ files, 
but that may get messy with things like shared macros.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46659



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


[PATCH] D46300: [Clang] Implement function attribute no_stack_protector.

2018-05-09 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 145988.
manojgupta added a comment.

Updated test case for error msg with arguments.
Updated the documentation.


Repository:
  rC Clang

https://reviews.llvm.org/D46300

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/stack-protector.c
  test/Sema/no_stack_protector.c

Index: test/Sema/no_stack_protector.c
===
--- /dev/null
+++ test/Sema/no_stack_protector.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void __attribute__((no_stack_protector)) foo() {}
+int __attribute__((no_stack_protector)) var; // expected-warning {{'no_stack_protector' attribute only applies to functions}}
+void  __attribute__((no_stack_protector(2))) bar() {} // expected-error {{'no_stack_protector' attribute takes no arguments}}
Index: test/CodeGen/stack-protector.c
===
--- test/CodeGen/stack-protector.c
+++ test/CodeGen/stack-protector.c
@@ -22,6 +22,14 @@
   printf("%s\n", a);
 }
 
+// DEF: define {{.*}}void @test2(i8* %msg) #[[B:.*]] {
+__attribute__((no_stack_protector))
+void test2(const char *msg) {
+  char a[strlen(msg) + 1];
+  strcpy(a, msg);
+  printf("%s\n", a);
+}
+
 // NOSSP-NOT: attributes #[[A]] = {{.*}} ssp
 // SSP: attributes #[[A]] = {{.*}} ssp{{ }}
 // SSPSTRONG: attributes #[[A]] = {{.*}} sspstrong
@@ -33,3 +41,15 @@
 // SAFESTACK-SSP: attributes #[[A]] = {{.*}} safestack ssp{{ }}
 // SAFESTACK-SSPSTRONG: attributes #[[A]] = {{.*}} safestack sspstrong
 // SAFESTACK-SSPREQ: attributes #[[A]] = {{.*}} safestack sspreq
+
+// NOSSP-NOT: attributes #[[B]] = {{.*}} ssp
+// SSP-NOT: attributes #[[B]] = {{.*}} ssp{{ }}
+// SSPSTRONG-NOT: attributes #[[B]] = {{.*}} sspstrong
+// SSPREQ-NOT: attributes #[[B]] = {{.*}} sspreq
+
+// SAFESTACK-SSP: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSP-NOT: attributes #[[B]] = {{.*}} safestack ssp{{ }}
+// SAFESTACK-SSPSTRONG: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSPSTRONG-NOT: attributes #[[B]] = {{.*}} safestack sspstrong
+// SAFESTACK-SSPREQ: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSPREQ-NOT: attributes #[[B]] = {{.*}} safestack sspreq
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -6230,6 +6230,10 @@
   case AttributeList::AT_NoInstrumentFunction: // Interacts with -pg.
 handleSimpleAttribute(S, D, AL);
 break;
+  case AttributeList::AT_NoStackProtector:
+// Interacts with -fstack-protector options.
+handleSimpleAttribute(S, D, AL);
+break;
   case AttributeList::AT_StdCall:
   case AttributeList::AT_CDecl:
   case AttributeList::AT_FastCall:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1142,12 +1142,14 @@
   if (!hasUnwindExceptions(LangOpts))
 B.addAttribute(llvm::Attribute::NoUnwind);
 
-  if (LangOpts.getStackProtector() == LangOptions::SSPOn)
-B.addAttribute(llvm::Attribute::StackProtect);
-  else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
-B.addAttribute(llvm::Attribute::StackProtectStrong);
-  else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
-B.addAttribute(llvm::Attribute::StackProtectReq);
+  if (!D || !D->hasAttr()) {
+if (LangOpts.getStackProtector() == LangOptions::SSPOn)
+  B.addAttribute(llvm::Attribute::StackProtect);
+else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
+  B.addAttribute(llvm::Attribute::StackProtectStrong);
+else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
+  B.addAttribute(llvm::Attribute::StackProtectReq);
+  }
 
   if (!D) {
 // If we don't have a declaration to control inlining, the function isn't
Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -2740,6 +2740,28 @@
   }];
 }
 
+def NoStackProtectorDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the ``__attribute__((no_stack_protector))`` attribute which disables
+the stack protector on the specified function. This attribute is useful for
+selectively disabling the stack protector on some functions when building with
+``-fstack-protector`` compiler option.
+
+For example, it disables the stack protector for the function ``foo`` but function
+``bar`` will still be built with the stack protector with the ``-fstack-protector``
+option.
+
+.. code-block:: c
+
+int __attribute__((no_stack_protector))
+foo (int x); // stack protection will be disabled for foo.
+
+int bar(int y); // bar can be built with the stack protector.
+
+}];
+}
+

[PATCH] D46656: [Builtins] Improve the IR emitted for MSVC compatible rotr/rotl builtins to match what the middle and backends understand

2018-05-09 Thread Sanjay Patel via Phabricator via cfe-commits
spatel accepted this revision.
spatel added a comment.
This revision is now accepted and ready to land.

LGTM - thanks!


https://reviews.llvm.org/D46656



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


[PATCH] D46659: [clang-tidy/google-readability-casting] Allow C-style casts to/from Objective-C object types

2018-05-09 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: alexfh, Wizard, hokein.
Herald added a subscriber: cfe-commits.

Previously, `google-readability-casting` would trigger for
Objective-C++ code using C-style casts to or from Objective-C object
types.

The official Google Objective-C standard says Objective-C++ allows
authors to mix the Objective-C style (which uses C-style casts) and
C++ (which disallows it):

http://google.github.io/styleguide/objcguide.html#style-matches-the-language

So, to resolve this conflict, this diff updates
`google-readability-casting` to ignore C-style casts to or from
Objective-C object types.

Test Plan: New tests added. Ran tests with:

  % make -j16 check-clang-tools
  Before diff, confirmed tests failed:
  https://reviews.llvm.org/P8081
  After diff, confirrmed tests passed.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46659

Files:
  clang-tidy/google/AvoidCStyleCastsCheck.cpp
  test/clang-tidy/google-readability-casting.mm


Index: test/clang-tidy/google-readability-casting.mm
===
--- /dev/null
+++ test/clang-tidy/google-readability-casting.mm
@@ -0,0 +1,42 @@
+// RUN: clang-tidy %s -checks=-*,google-readability-casting -- \
+// RUN:   -xobjective-c++ -fobjc-abi-version=2 -fobjc-arc | count 0
+
+// Note: this test expects no diagnostics, but FileCheck cannot handle that,
+// hence the use of | count 0.
+
+#define nil 0
+
+@interface Foo
+@end
+
+@protocol Proto
+@end
+
+@interface Bar : Foo 
+@end
+
+@interface Baz : Foo 
+@end
+
+void foo() {
+  id nilObj = nil;
+  Foo *foo = (Foo *)nilObj;
+  Bar *bar = (Bar *)nilObj;
+  id ego = (id)foo;
+  foo = (Foo *)bar;
+  foo = (id)bar;
+  id nilProto = (id)bar;
+  ego = (id)nilProto;
+  bar = (Bar *)nilProto;
+  Foo *fooProto = (Foo *)bar;
+  Baz *baz = (Baz *)bar;
+  Class klass = (Class)nilObj;
+  ego = (id)klass;
+  void *voidStar = nullptr;
+  foo = (__bridge Foo *)voidStar;
+  nilProto = (__bridge id)voidStar;
+  klass = (__bridge Class)voidStar;
+  voidStar = (__bridge void *)foo;
+  voidStar = (__bridge void *)nilProto;
+  voidStar = (__bridge void *)klass;
+}
Index: clang-tidy/google/AvoidCStyleCastsCheck.cpp
===
--- clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -110,6 +110,10 @@
   // compiled as C++.
   if (getCurrentMainFile().endswith(".c"))
 return;
+  // Ignore casts between Objective-C types.
+  if (SourceType->isObjCObjectPointerType() ||
+  DestType->isObjCObjectPointerType())
+return;
 
   SourceManager &SM = *Result.SourceManager;
 


Index: test/clang-tidy/google-readability-casting.mm
===
--- /dev/null
+++ test/clang-tidy/google-readability-casting.mm
@@ -0,0 +1,42 @@
+// RUN: clang-tidy %s -checks=-*,google-readability-casting -- \
+// RUN:   -xobjective-c++ -fobjc-abi-version=2 -fobjc-arc | count 0
+
+// Note: this test expects no diagnostics, but FileCheck cannot handle that,
+// hence the use of | count 0.
+
+#define nil 0
+
+@interface Foo
+@end
+
+@protocol Proto
+@end
+
+@interface Bar : Foo 
+@end
+
+@interface Baz : Foo 
+@end
+
+void foo() {
+  id nilObj = nil;
+  Foo *foo = (Foo *)nilObj;
+  Bar *bar = (Bar *)nilObj;
+  id ego = (id)foo;
+  foo = (Foo *)bar;
+  foo = (id)bar;
+  id nilProto = (id)bar;
+  ego = (id)nilProto;
+  bar = (Bar *)nilProto;
+  Foo *fooProto = (Foo *)bar;
+  Baz *baz = (Baz *)bar;
+  Class klass = (Class)nilObj;
+  ego = (id)klass;
+  void *voidStar = nullptr;
+  foo = (__bridge Foo *)voidStar;
+  nilProto = (__bridge id)voidStar;
+  klass = (__bridge Class)voidStar;
+  voidStar = (__bridge void *)foo;
+  voidStar = (__bridge void *)nilProto;
+  voidStar = (__bridge void *)klass;
+}
Index: clang-tidy/google/AvoidCStyleCastsCheck.cpp
===
--- clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -110,6 +110,10 @@
   // compiled as C++.
   if (getCurrentMainFile().endswith(".c"))
 return;
+  // Ignore casts between Objective-C types.
+  if (SourceType->isObjCObjectPointerType() ||
+  DestType->isObjCObjectPointerType())
+return;
 
   SourceManager &SM = *Result.SourceManager;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46643: CodeGen: Emit string literal in constant address space

2018-05-09 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1375
+Loc = Address(EmitCastToVoidPtrInAllocaAddrSpace(Loc.getPointer()),
+  Loc.getAlignment());
 

rjmccall wrote:
> I don't understand why a patch about string literals is changing auto 
> variable emission.
It is a bug about alloca revealed by the lit test


```
char l_array[] = "l_array";

```
Loc contains the alloca casted to default address space, therefore it needs to 
be casted back to alloca address space here, otherwise CreateBitCast returns 
invalid bitcast. Unlike lifetime.start, memcpy does not require alloca address 
space, so an alternative fix is to let BP take address space of Loc.


https://reviews.llvm.org/D46643



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


[PATCH] D46656: [Builtins] Improve the IR emitted for MSVC compatible rotr/rotl builtins to match what the middle and backends understand

2018-05-09 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added a reviewer: spatel.

Currently we emit something like

rotl(x, n) {
n &= bitwidth -1;
return n != 0 ? ((x << n) | (x >> (bitwidth - n)) : x;
}

We use a select to avoid the undefined behavior on the (bitwidth - n) shift.

The middle and backend don't really recognize this as a rotate and end up 
emitting a cmov or control flow because of the select.

A better pattern is (x << (n & mask)) | (x << (-n & mask))  where mask is 
bitwidth - 1.

Fixes the main complaint in PR37387. There's still some work to be done if the 
user writes that sequence directly on a short or char where type promotion 
rules can prevent it from being recognized. The builtin is emitting direct IR 
with unpromoted types so that isn't a problem for it.


https://reviews.llvm.org/D46656

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/ms-intrinsics-rotations.c

Index: test/CodeGen/ms-intrinsics-rotations.c
===
--- test/CodeGen/ms-intrinsics-rotations.c
+++ test/CodeGen/ms-intrinsics-rotations.c
@@ -30,69 +30,64 @@
   return _rotl8(value, shift);
 }
 // CHECK: i8 @test_rotl8
-// CHECK:   [[SHIFT:%[0-9]+]] = and i8 %{{[0-9]+}}, 7
-// CHECK:   [[NEGSHIFT:%[0-9]+]] = sub i8 8, [[SHIFT]]
-// CHECK:   [[HIGH:%[0-9]+]] = shl i8 [[VALUE:%[0-9]+]], [[SHIFT]]
-// CHECK:   [[LOW:%[0-9]+]] = lshr i8 [[VALUE]], [[NEGSHIFT]]
-// CHECK:   [[ROTATED:%[0-9]+]] = or i8 [[HIGH]], [[LOW]]
-// CHECK:   [[ISZERO:%[0-9]+]] = icmp eq i8 [[SHIFT]], 0
-// CHECK:   [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i8 [[VALUE]], i8 [[ROTATED]]
+// CHECK:   [[LSHIFT:%[0-9]+]] = and i8 [[SHIFT:%[0-9]+]], 7
+// CHECK:   [[HIGH:%[0-9]+]] = shl i8 [[VALUE:%[0-9]+]], [[LSHIFT]]
+// CHECK:   [[NEGATE:%[0-9]+]] = sub i8 0, [[SHIFT]]
+// CHECK:   [[RSHIFT:%[0-9]+]] = and i8 [[NEGATE]], 7
+// CHECK:   [[LOW:%[0-9]+]] = lshr i8 [[VALUE]], [[RSHIFT]]
+// CHECK:   [[RESULT:%[0-9]+]] = or i8 [[HIGH]], [[LOW]]
 // CHECK:   ret i8 [[RESULT]]
 // CHECK  }
 
 unsigned short test_rotl16(unsigned short value, unsigned char shift) {
   return _rotl16(value, shift);
 }
 // CHECK: i16 @test_rotl16
-// CHECK:   [[SHIFT:%[0-9]+]] = and i16 %{{[0-9]+}}, 15
-// CHECK:   [[NEGSHIFT:%[0-9]+]] = sub i16 16, [[SHIFT]]
-// CHECK:   [[HIGH:%[0-9]+]] = shl i16 [[VALUE:%[0-9]+]], [[SHIFT]]
-// CHECK:   [[LOW:%[0-9]+]] = lshr i16 [[VALUE]], [[NEGSHIFT]]
-// CHECK:   [[ROTATED:%[0-9]+]] = or i16 [[HIGH]], [[LOW]]
-// CHECK:   [[ISZERO:%[0-9]+]] = icmp eq i16 [[SHIFT]], 0
-// CHECK:   [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i16 [[VALUE]], i16 [[ROTATED]]
+// CHECK:   [[LSHIFT:%[0-9]+]] = and i16 [[SHIFT:%[0-9]+]], 15
+// CHECK:   [[HIGH:%[0-9]+]] = shl i16 [[VALUE:%[0-9]+]], [[LSHIFT]]
+// CHECK:   [[NEGATE:%[0-9]+]] = sub i16 0, [[SHIFT]]
+// CHECK:   [[RSHIFT:%[0-9]+]] = and i16 [[NEGATE]], 15
+// CHECK:   [[LOW:%[0-9]+]] = lshr i16 [[VALUE]], [[RSHIFT]]
+// CHECK:   [[RESULT:%[0-9]+]] = or i16 [[HIGH]], [[LOW]]
 // CHECK:   ret i16 [[RESULT]]
 // CHECK  }
 
 unsigned int test_rotl(unsigned int value, int shift) {
   return _rotl(value, shift);
 }
 // CHECK: i32 @test_rotl
-// CHECK:   [[SHIFT:%[0-9]+]] = and i32 %{{[0-9]+}}, 31
-// CHECK:   [[NEGSHIFT:%[0-9]+]] = sub i32 32, [[SHIFT]]
-// CHECK:   [[HIGH:%[0-9]+]] = shl i32 [[VALUE:%[0-9]+]], [[SHIFT]]
-// CHECK:   [[LOW:%[0-9]+]] = lshr i32 [[VALUE]], [[NEGSHIFT]]
-// CHECK:   [[ROTATED:%[0-9]+]] = or i32 [[HIGH]], [[LOW]]
-// CHECK:   [[ISZERO:%[0-9]+]] = icmp eq i32 [[SHIFT]], 0
-// CHECK:   [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i32 [[VALUE]], i32 [[ROTATED]]
+// CHECK:   [[LSHIFT:%[0-9]+]] = and i32 [[SHIFT:%[0-9]+]], 31
+// CHECK:   [[HIGH:%[0-9]+]] = shl i32 [[VALUE:%[0-9]+]], [[LSHIFT]]
+// CHECK:   [[NEGATE:%[0-9]+]] = sub i32 0, [[SHIFT]]
+// CHECK:   [[RSHIFT:%[0-9]+]] = and i32 [[NEGATE]], 31
+// CHECK:   [[LOW:%[0-9]+]] = lshr i32 [[VALUE]], [[RSHIFT]]
+// CHECK:   [[RESULT:%[0-9]+]] = or i32 [[HIGH]], [[LOW]]
 // CHECK:   ret i32 [[RESULT]]
 // CHECK  }
 
 unsigned LONG test_lrotl(unsigned LONG value, int shift) {
   return _lrotl(value, shift);
 }
 // CHECK-32BIT-LONG: i32 @test_lrotl
-// CHECK-32BIT-LONG:   [[SHIFT:%[0-9]+]] = and i32 %{{[0-9]+}}, 31
-// CHECK-32BIT-LONG:   [[NEGSHIFT:%[0-9]+]] = sub i32 32, [[SHIFT]]
-// CHECK-32BIT-LONG:   [[HIGH:%[0-9]+]] = shl i32 [[VALUE:%[0-9]+]], [[SHIFT]]
-// CHECK-32BIT-LONG:   [[LOW:%[0-9]+]] = lshr i32 [[VALUE]], [[NEGSHIFT]]
-// CHECK-32BIT-LONG:   [[ROTATED:%[0-9]+]] = or i32 [[HIGH]], [[LOW]]
-// CHECK-32BIT-LONG:   [[ISZERO:%[0-9]+]] = icmp eq i32 [[SHIFT]], 0
-// CHECK-32BIT-LONG:   [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i32 [[VALUE]], i32 [[ROTATED]]
+// CHECK-32BIT-LONG:   [[LSHIFT:%[0-9]+]] = and i32 [[SHIFT:%[0-9]+]], 31
+// CHECK-32BIT-LONG:   [[HIGH:%[0-9]+]] = shl i32 [[VALUE:%[0-9]+]], [[LSHIFT]]
+// CHECK-32BIT-LONG:   [[NEGATE:%[0-9]+]] = sub i32 0, [[SHIFT]]
+// CHECK-32BIT-LONG:   [[RSHIFT:%[0-9]+]] = and i32 [[NEGATE]], 31
+// CHECK-32BIT-LONG:   [[

[PATCH] D46593: Allow copy elision in path concatenation

2018-05-09 Thread Dávid Bolvanský via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCXX331910: Allow copy elision in path concatenation (authored 
by xbolva00, committed by ).

Repository:
  rCXX libc++

https://reviews.llvm.org/D46593

Files:
  include/experimental/filesystem


Index: include/experimental/filesystem
===
--- include/experimental/filesystem
+++ include/experimental/filesystem
@@ -1140,7 +1140,9 @@
 
 inline _LIBCPP_INLINE_VISIBILITY
 path operator/(const path& __lhs, const path& __rhs) {
-return path(__lhs) /= __rhs;
+path __result(__lhs);
+__result /= __rhs;
+return __result;
 }
 
 template 


Index: include/experimental/filesystem
===
--- include/experimental/filesystem
+++ include/experimental/filesystem
@@ -1140,7 +1140,9 @@
 
 inline _LIBCPP_INLINE_VISIBILITY
 path operator/(const path& __lhs, const path& __rhs) {
-return path(__lhs) /= __rhs;
+path __result(__lhs);
+__result /= __rhs;
+return __result;
 }
 
 template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 145978.
juliehockett marked 3 inline comments as done.
juliehockett added a comment.

Updating the inclusiondirective to filter out non-system files


https://reviews.llvm.org/D43778

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
  clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/a.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/j.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/s.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/t.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
  test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
  test/clang-tidy/fuchsia-restrict-system-includes.cpp

Index: test/clang-tidy/fuchsia-restrict-system-includes.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-restrict-system-includes.cpp
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
+// RUN:		-- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 's.h'}]}" \
+// RUN:   -- -std=c++11 -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system
+
+#include "a.h"
+
+#include 
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
+// CHECK-FIXES-NOT: #include 
+
+#include "s.h"
+#include "t.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
+// CHECK-FIXES-NOT: #include "t.h"
+
+#define foo 
+
+#include foo
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed
+// CHECK-FIXES-NOT: #include foo
+
+#/* comment */ include /* comment */ foo
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed
+// CHECK-FIXES-NOT: # /* comment */ include /* comment */ foo
Index: test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
@@ -0,0 +1,20 @@
+// RUN: cp -r %S/Inputs/fuchsia-restrict-system-includes %T/Inputs
+// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
+// RUN:		-- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'transitive.h;s.h'}]}" \
+// RUN:   -system-headers -header-filter=.* \
+// RUN:   -- -std=c++11 -I %T/Inputs/fuchsia-restrict-system-includes -isystem %T/Inputs/fuchsia-restrict-system-includes/system
+// RUN: FileCheck -input-file=%T/Inputs/transitive2.h %s -check-prefix=CHECK-HEADER-FIXES
+
+// transitive.h includes  and 
+#include 
+// CHECK-MESSAGES: :1:1: warning: system include r.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/system/transitive.h
+// CHECK-MESSAGES: :2:1: warning: system include t.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/system/transitive.h
+
+// transitive.h includes  and 
+#include "transitive2.h"
+// CHECK-MESSAGES: :2:1: warning: system include t.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/transitive2.h
+// CHECK-HEADER-FIXES-NOT: #include 
+
+int main() {
+  // f() is declared in r.h
+}
Index: test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
@@ -0,0 +1,2 @@
+#include 
+#include 
Index: test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
@@ -0,0 +1,3 @@
+#include 
+#include 
+#include 
Index: test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
@@ -0,0 +1 @@
+void f() {}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -95,6 +95,7 @@
fuchsia-default-arguments
fuchsia-multiple-inheritance
fuchsia-overloaded-operator
+   fuchsia-restrict-system-includes
fuchsia-statically-constructed-objects
fuchsia-trailing-return
fuchsia-virtual-inheritance
Index: docs/clang-tidy/checks

[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: docs/ReleaseNotes.rst:116
+
+  Checks for allowed system includes and suggests removal of any others. If no
+  includes are specified, the check will exit without issuing any warnings.

Eugene.Zelenko wrote:
> Is it necessary to highlight that warnings will not be emitted in case of 
> disallowed headers are not found? Same in documentation.
I'm not sure I understand what you're saying...are you saying if the 
documentation should not include anything about  what happens in the case of no 
headers?



Comment at: docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst:32
+   A string containing a semi-colon separated list of allowed include 
filenames.
+   The default is an empty string, which allows all includes.

aaron.ballman wrote:
> This default seems a bit odd to me, but perhaps it's fine. What's novel is 
> that the check is a no-op by default, so how do Fuchsia developers get the 
> correct list? Or is there no canonical list and developers are expected to 
> populate their own manually?
The idea is that it's a case-by-case basis -- this may change at some point in 
the future if we decide there's a standard whitelist of system includes across 
the board, but at the moment the thought is to allow everything in some places, 
and use this check to limit them in others. It'll need to be populated on a 
case-by-case basis, since different directories will have different 
requirements.


https://reviews.llvm.org/D43778



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


[PATCH] D45470: Emit an error when include after

2018-05-09 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

In https://reviews.llvm.org/D45470#1092260, @jfb wrote:

> In https://reviews.llvm.org/D45470#1092212, @vsapsai wrote:
>
> > Here is another approach that should emit an error only when mixing headers
> >  causes compilation problems.
> >
> > Have no ideas how to test the change. `-verify` doesn't work with fatal 
> > errors
> >  and libcxx doesn't use FileCheck. Performed only manual testing.
>
>
> This worked with `` before `` as well as with the order 
> reversed?




  #include 
  #include 

> fatal error: too many errors emitted, stopping now [-ferror-limit=]



  #include 
  #include 

> no errors

So when `` is //after// ``, I add one more error to 
existing. When `` is //before// ``, there are no errors 
and I don't add anything.


https://reviews.llvm.org/D45470



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


[PATCH] D46651: [OpenCL] Support placement new/delete in Sema

2018-05-09 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaExprCXX.cpp:2030
+  }
+}
 

I think a better interpretation of this rule would be to just error on attempts 
to use the standard non-placement operator new/delete instead of trying to 
outlaw the operator declarations.  For example, I don't know why a user-defined 
non-global operator new would be problematic.


Repository:
  rC Clang

https://reviews.llvm.org/D46651



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


[PATCH] D46615: [tools] Updating PPCallbacks::InclusionDirective calls

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
juliehockett marked an inline comment as done.
Closed by commit rL331905: [tools] Updating PPCallbacks::InclusionDirective 
calls (authored by juliehockett, committed by ).
Herald added subscribers: llvm-commits, ilya-biryukov, klimek.

Changed prior to commit:
  https://reviews.llvm.org/D46615?vs=145823&id=145972#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46615

Files:
  clang-tools-extra/trunk/clang-move/ClangMove.cpp
  clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
  clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
  clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
  clang-tools-extra/trunk/clangd/ClangdUnit.cpp
  clang-tools-extra/trunk/clangd/Headers.cpp
  clang-tools-extra/trunk/modularize/CoverageChecker.cpp
  clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
  clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp
  clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.h

Index: clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
@@ -28,7 +28,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override;
   void EndOfMainFile() override;
 
 private:
@@ -76,7 +77,8 @@
 void IncludeOrderPPCallbacks::InclusionDirective(
 SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
 bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
-StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+StringRef SearchPath, StringRef RelativePath, const Module *Imported,
+SrcMgr::CharacteristicKind FileType) {
   // We recognize the first include as a special main module header and want
   // to leave it in the top position.
   IncludeDirective ID = {HashLoc, FilenameRange, FileName, IsAngled, false};
Index: clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
===
--- clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
+++ clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
@@ -25,7 +25,8 @@
   bool IsAngled, CharSourceRange FileNameRange,
   const FileEntry * /*IncludedFile*/,
   StringRef /*SearchPath*/, StringRef /*RelativePath*/,
-  const Module * /*ImportedModule*/) override {
+  const Module * /*ImportedModule*/,
+  SrcMgr::CharacteristicKind /*FileType*/) override {
 Inserter->AddInclude(FileNameRef, IsAngled, HashLocation,
  IncludeToken.getEndLoc());
   }
Index: clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -30,7 +30,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override;
 
 private:
   ClangTidyCheck &Check;
@@ -94,7 +95,8 @@
 void IncludeModernizePPCallbacks::InclusionDirective(
 SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
 bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
-StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+StringRef SearchPath, StringRef RelativePath, const Module *Imported,
+SrcMgr::CharacteristicKind FileType) {
   // FIXME: Take care of library symbols from the global namespace.
   //
   // Reasonable options for the check:
Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp
@@ -93,7 +93,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module 

[PATCH] D46614: [clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331904: [clang] Adding CharacteristicKind to 
PPCallbacks::InclusionDirective (authored by juliehockett, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46614?vs=145941&id=145971#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46614

Files:
  cfe/trunk/include/clang/Lex/PPCallbacks.h
  cfe/trunk/include/clang/Lex/PreprocessingRecord.h
  cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp
  cfe/trunk/lib/CodeGen/MacroPPCallbacks.h
  cfe/trunk/lib/Frontend/DependencyFile.cpp
  cfe/trunk/lib/Frontend/DependencyGraph.cpp
  cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
  cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
  cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
  cfe/trunk/lib/Lex/PPDirectives.cpp
  cfe/trunk/lib/Lex/PreprocessingRecord.cpp
  cfe/trunk/tools/libclang/Indexing.cpp
  cfe/trunk/unittests/Lex/PPCallbacksTest.cpp

Index: cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
===
--- cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
+++ cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
@@ -50,7 +50,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
 if (!File)
   return;
 Collector.addFile(File->getName());
Index: cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
===
--- cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
+++ cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
@@ -77,7 +77,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override;
   void WriteLineInfo(StringRef Filename, int Line,
  SrcMgr::CharacteristicKind FileType,
  StringRef Extra = StringRef());
@@ -192,7 +193,8 @@
const FileEntry * /*File*/,
StringRef /*SearchPath*/,
StringRef /*RelativePath*/,
-   const Module *Imported) {
+   const Module *Imported,
+   SrcMgr::CharacteristicKind FileType){
   if (Imported) {
 auto P = ModuleIncludes.insert(
 std::make_pair(HashLoc.getRawEncoding(), Imported));
Index: cfe/trunk/lib/Frontend/DependencyGraph.cpp
===
--- cfe/trunk/lib/Frontend/DependencyGraph.cpp
+++ cfe/trunk/lib/Frontend/DependencyGraph.cpp
@@ -50,7 +50,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override;
 
   void EndOfMainFile() override {
 OutputGraphFile();
@@ -65,15 +66,17 @@
SysRoot));
 }
 
-void DependencyGraphCallback::InclusionDirective(SourceLocation HashLoc,
- const Token &IncludeTok,
- StringRef FileName,
- bool IsAngled,
- CharSourceRange FilenameRange,
- const FileEntry *File,
- StringRef SearchPath,
- StringRef RelativePath,
- const Module *Imported) {
+void DependencyGraphCallback::InclusionDirective(
+SourceLocation HashLoc,
+const Token &IncludeTok,
+StringRef FileName,
+bool IsAngled,
+CharSourceRange FilenameRange,
+const FileEntry *File,
+StringRef SearchPath,
+StringRef RelativePath,
+const Module *Imported, 
+SrcMgr::CharacteristicKind FileType) {
   if (!File)
 return;
   
Index: cfe/trunk/lib/Fro

[clang-tools-extra] r331905 - [tools] Updating PPCallbacks::InclusionDirective calls

2018-05-09 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Wed May  9 11:27:37 2018
New Revision: 331905

URL: http://llvm.org/viewvc/llvm-project?rev=331905&view=rev
Log:
[tools] Updating PPCallbacks::InclusionDirective calls

[revision] added SrcMgr::CharacteristicKind to the InclusionDirective
callback, this revision updates instances of it in clang-tools-extra.

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

Modified:
clang-tools-extra/trunk/clang-move/ClangMove.cpp
clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/Headers.cpp
clang-tools-extra/trunk/modularize/CoverageChecker.cpp
clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp
clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.h

Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=331905&r1=331904&r2=331905&view=diff
==
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Wed May  9 11:27:37 2018
@@ -131,7 +131,8 @@ public:
   clang::CharSourceRange FilenameRange,
   const clang::FileEntry * /*File*/,
   StringRef SearchPath, StringRef /*RelativePath*/,
-  const clang::Module * /*Imported*/) override {
+  const clang::Module * /*Imported*/,
+  SrcMgr::CharacteristicKind /*FileType*/) override {
 if (const auto *FileEntry = SM.getFileEntryForID(SM.getFileID(HashLoc)))
   MoveTool->addIncludes(FileName, IsAngled, SearchPath,
 FileEntry->getName(), FilenameRange, SM);

Modified: clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp?rev=331905&r1=331904&r2=331905&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp Wed May  9 
11:27:37 2018
@@ -28,7 +28,8 @@ public:
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override;
   void EndOfMainFile() override;
 
 private:
@@ -76,7 +77,8 @@ static int getPriority(StringRef Filenam
 void IncludeOrderPPCallbacks::InclusionDirective(
 SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
 bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
-StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+StringRef SearchPath, StringRef RelativePath, const Module *Imported,
+SrcMgr::CharacteristicKind FileType) {
   // We recognize the first include as a special main module header and want
   // to leave it in the top position.
   IncludeDirective ID = {HashLoc, FilenameRange, FileName, IsAngled, false};

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp?rev=331905&r1=331904&r2=331905&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp Wed 
May  9 11:27:37 2018
@@ -30,7 +30,8 @@ public:
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override;
 
 private:
   ClangTidyCheck &Check;
@@ -94,7 +95,8 @@ IncludeModernizePPCallbacks::IncludeMode
 void IncludeModernizePPCallbacks::InclusionDirective(
 SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
 bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
-StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+StringRef SearchPath,

r331904 - [clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective

2018-05-09 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Wed May  9 11:27:33 2018
New Revision: 331904

URL: http://llvm.org/viewvc/llvm-project?rev=331904&view=rev
Log:
[clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective

Adding a SrcMgr::CharacteristicKind parameter to the InclusionDirective
in PPCallbacks, and updating calls to that function. This will be useful
in https://reviews.llvm.org/D43778 to determine which includes are system
headers.

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

Modified:
cfe/trunk/include/clang/Lex/PPCallbacks.h
cfe/trunk/include/clang/Lex/PreprocessingRecord.h
cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp
cfe/trunk/lib/CodeGen/MacroPPCallbacks.h
cfe/trunk/lib/Frontend/DependencyFile.cpp
cfe/trunk/lib/Frontend/DependencyGraph.cpp
cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PreprocessingRecord.cpp
cfe/trunk/tools/libclang/Indexing.cpp
cfe/trunk/unittests/Lex/PPCallbacksTest.cpp

Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=331904&r1=331903&r2=331904&view=diff
==
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Wed May  9 11:27:33 2018
@@ -117,6 +117,10 @@ public:
   /// \param Imported The module, whenever an inclusion directive was
   /// automatically turned into a module import or null otherwise.
   ///
+  /// \param FileType The characteristic kind, indicates whether a file or
+  /// directory holds normal user code, system code, or system code which is
+  /// implicitly 'extern "C"' in C++ mode.
+  ///
   virtual void InclusionDirective(SourceLocation HashLoc,
   const Token &IncludeTok,
   StringRef FileName,
@@ -125,7 +129,8 @@ public:
   const FileEntry *File,
   StringRef SearchPath,
   StringRef RelativePath,
-  const Module *Imported) {
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) {
   }
 
   /// Callback invoked whenever there was an explicit module-import
@@ -367,13 +372,14 @@ public:
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
 First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
   FilenameRange, File, SearchPath, RelativePath,
-  Imported);
+  Imported, FileType);
 Second->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
FilenameRange, File, SearchPath, RelativePath,
-   Imported);
+   Imported, FileType);
   }
 
   void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path,

Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=331904&r1=331903&r2=331904&view=diff
==
--- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Wed May  9 11:27:33 2018
@@ -532,8 +532,8 @@ class Token;
 StringRef FileName, bool IsAngled,
 CharSourceRange FilenameRange,
 const FileEntry *File, StringRef SearchPath,
-StringRef RelativePath,
-const Module *Imported) override;
+StringRef RelativePath, const Module *Imported,
+SrcMgr::CharacteristicKind FileType) override;
 void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDefinition &MD) override;
 void Ifndef(SourceLocation Loc, const Token &MacroNameTok,

Modified: cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp?rev=331904&r1=331903&r2=331904&view=diff
==
--- cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp (original)
+++ cfe/trunk/lib/CodeGen/MacroPPCallback

[PATCH] D46643: CodeGen: Emit string literal in constant address space

2018-05-09 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

The part about string literals looks fine, but:




Comment at: lib/CodeGen/CGDecl.cpp:1375
+Loc = Address(EmitCastToVoidPtrInAllocaAddrSpace(Loc.getPointer()),
+  Loc.getAlignment());
 

I don't understand why a patch about string literals is changing auto variable 
emission.


https://reviews.llvm.org/D46643



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


[PATCH] D46633: [analyzer] add range check for InitList lookup

2018-05-09 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

Looks good, thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D46633



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


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-05-09 Thread Mike Rice via Phabricator via cfe-commits
mikerice created this revision.
mikerice added reviewers: rnk, thakis, erichkeane, cfe-commits.

Implement support for MS-style PCH through headers.

This enables support for /Yc and /Yu where the through header is either
on the command line or included in the source.  It replaces the current
support the requires the header also be specified with /FI.

This change adds a -cc1 option -pch-through-header that is used to either
start or stop compilation during PCH create or use.

When creating a PCH, the compilation ends after compilation of the through
header.

When using a PCH, tokens are skipped until after the through header is seen.


Repository:
  rC Clang

https://reviews.llvm.org/D46652

Files:
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/FrontendOptions.h
  include/clang/Lex/Preprocessor.h
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/Driver.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInstance.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PPLexerChange.cpp
  lib/Lex/Preprocessor.cpp
  lib/Parse/ParseAST.cpp
  lib/Serialization/ASTReader.cpp
  test/Driver/cl-pch-search.cpp
  test/Driver/cl-pch.cpp
  test/PCH/Inputs/pch-through-use0.cpp
  test/PCH/Inputs/pch-through-use1.cpp
  test/PCH/Inputs/pch-through-use2.cpp
  test/PCH/Inputs/pch-through1.h
  test/PCH/Inputs/pch-through2.h
  test/PCH/Inputs/pch-through3.h
  test/PCH/Inputs/pch-through4.h
  test/PCH/pch-through.cpp

Index: test/PCH/pch-through.cpp
===
--- /dev/null
+++ test/PCH/pch-through.cpp
@@ -0,0 +1,72 @@
+// Through header not found (anywhere)
+// RUN: not %clang_cc1 -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-does-not-exist.h -o %t %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST0A %s
+// CHECK-TEST0A: fatal error:{{.*}} 'Inputs/pch-does-not-exist.h'
+// CHECK-TEST0A-SAME: required for precompiled header not found
+
+// Through header not found in search path
+// RUN: not %clang_cc1 -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through2.h -o %t \
+// RUN:   %S/Inputs/pch-through-use0.cpp 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST0B %s
+// CHECK-TEST0B: fatal error:{{.*}}'Inputs/pch-through2.h'
+// CHECK-TEST0B-SAME: required for precompiled header not found
+
+// No #include of through header during pch create
+// RUN: not %clang_cc1 -DSOURCE1 -I %S -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through2.h -o %t %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST1A %s
+// CHECK-TEST1A: fatal error:{{.*}} #include of
+// CHECK-TEST1A-SAME: 'Inputs/pch-through2.h' not seen while attempting to
+// CHECK-TEST1A-SAME: create precompiled header
+
+#ifdef SOURCE1
+#endif
+
+// Create
+// RUN: %clang_cc1 -DSOURCE2 -I %S -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through2.h -o %t.s2t2 %s
+
+// Use
+// RUN: %clang_cc1 -DSOURCE2 -I %S -include-pch %t.s2t2 \
+// RUN:   -pch-through-header=Inputs/pch-through2.h %s
+
+#ifdef SOURCE2
+#include "Inputs/pch-through1.h"
+#include "Inputs/pch-through2.h"
+#endif
+
+// No #include of through header during pch use
+// RUN: not %clang_cc1 -I %S -include-pch %t.s2t2 \
+// RUN:   -pch-through-header=Inputs/pch-through2.h \
+// RUN:   %S/Inputs/pch-through-use1.cpp 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST2A %s
+// CHECK-TEST2A: fatal error:{{.*}} #include of
+// CHECK-TEST2A-SAME: 'Inputs/pch-through2.h' not seen while attempting to
+// CHECK-TEST2A-SAME: use precompiled header
+
+// check that pch only contains code before the through header.
+// RUN: %clang_cc1 -DSOURCE2 -I %S -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through1.h -o %t.s2t1 %s
+// RUN: not %clang_cc1 -I %S -include-pch %t.s2t1 \
+// RUN:   -pch-through-header=Inputs/pch-through1.h \
+// RUN:   %S/Inputs/pch-through-use1.cpp 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST3 %s
+// CHECK-TEST3: error: use of undeclared identifier 'through2'
+
+#ifdef SOURCE3
+#endif
+
+// checks for through headers that are also -includes
+// RUN: %clang_cc1 -DSOURCE3 -I %S -include Inputs/pch-through1.h \
+// RUN:   -pch-through-header=Inputs/pch-through1.h -emit-pch -o %t.s3t1 %s
+// RUN: %clang_cc1 -DSOURCE3 -I %S -include Inputs/pch-through1.h \
+// RUN:   -include Inputs/pch-through2.h -include Inputs/pch-through3.h \
+// RUN:   -pch-through-header=Inputs/pch-through2.h -emit-pch -o %t.s3t2 %s
+// Use through header from -includes
+// RUN: %clang_cc1 -DSOURCE3 -I %S -include Inputs/pch-through1.h \
+// RUN:   -include Inputs/pch-through2.h -include Inputs/pch-through4.h \
+// RUN:   -pch-through-header=Inputs/pch-through2.h -include-pch %t.s3t2 \
+// RUN:   %S/Inputs/pch-through-use2.cpp -o %t.out
+
Index: test/PCH/Inputs/pch-through4.h
===
--- /dev/null
+++ test/PCH/Inputs/pch-through4.h
@@ -0,0 +1,2 @@
+#define THROUGH4
+in

r331899 - [OPENMP] Generate unique names for offloading regions id.

2018-05-09 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed May  9 11:02:37 2018
New Revision: 331899

URL: http://llvm.org/viewvc/llvm-project?rev=331899&view=rev
Log:
[OPENMP] Generate unique names for offloading regions id.

It is required to emit unique names for offloading regions ids. Required
to support compilation and linking of several compilation units.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/target_is_device_ptr_codegen.cpp
cfe/trunk/test/OpenMP/target_map_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=331899&r1=331898&r2=331899&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed May  9 11:02:37 2018
@@ -6286,7 +6286,7 @@ void CGOpenMPRuntime::emitTargetOutlined
 OutlinedFn->setLinkage(llvm::GlobalValue::WeakAnyLinkage);
 OutlinedFn->setDSOLocal(false);
   } else {
-std::string Name = getName({"omp_offload", "region_id"});
+std::string Name = getName({EntryFnName, "region_id"});
 OutlinedFnID = new llvm::GlobalVariable(
 CGM.getModule(), CGM.Int8Ty, /*isConstant=*/true,
 llvm::GlobalValue::WeakAnyLinkage,

Modified: cfe/trunk/test/OpenMP/target_is_device_ptr_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_is_device_ptr_codegen.cpp?rev=331899&r1=331898&r2=331899&view=diff
==
--- cfe/trunk/test/OpenMP/target_is_device_ptr_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_is_device_ptr_codegen.cpp Wed May  9 11:02:37 
2018
@@ -206,12 +206,18 @@ void bar(float *&a, int *&b) {
 
 // CK2: [[ST:%.+]] = type { double*, double** }
 
+// CK2-LABEL: @.__omp_offloading_{{.*}}foo{{.*}}_l245.region_id = weak 
constant i8 0
+
 // CK2: [[SIZE00:@.+]] = {{.+}}constant [1 x i[[sz:64|32]]] [i{{64|32}} 
{{8|4}}]
 // CK2: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 33]
 
+// CK2-LABEL: @.__omp_offloading_{{.*}}foo{{.*}}_l269.region_id = weak 
constant i8 0
+
 // CK2: [[SIZE01:@.+]] = {{.+}}constant [2 x i[[sz]]] [i[[sz]] {{8|4}}, 
i[[sz]] {{8|4}}]
 // CK2: [[MTYPE01:@.+]] = {{.+}}constant [2 x i64] [i64 32, i64 17]
 
+// CK2-LABEL: @.__omp_offloading_{{.*}}foo{{.*}}_l301.region_id = weak 
constant i8 0
+
 // CK2: [[SIZE02:@.+]] = {{.+}}constant [3 x i[[sz]]] [i[[sz]] {{8|4}}, 
i[[sz]] {{8|4}}, i[[sz]] {{8|4}}]
 // CK2: [[MTYPE02:@.+]] = {{.+}}constant [3 x i64] [i64 33, i64 0, i64 17]
 

Modified: cfe/trunk/test/OpenMP/target_map_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_map_codegen.cpp?rev=331899&r1=331898&r2=331899&view=diff
==
--- cfe/trunk/test/OpenMP/target_map_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_map_codegen.cpp Wed May  9 11:02:37 2018
@@ -39,6 +39,8 @@ public:
 };
 double B::VAR = 1.0;
 
+// CK1-LABEL: 
@.__omp_offloading_{{.*}}implicit_maps_integer{{.*}}_l68.region_id = weak 
constant i8 0
+
 // CK1-DAG: [[SIZES:@.+]] = {{.+}}constant [1 x i[[sz:64|32]]] [i{{64|32}} 4]
 // Map types: OMP_MAP_PRIVATE_VAL | OMP_MAP_IS_FIRST = 288
 // CK1-DAG: [[TYPES:@.+]] = {{.+}}constant [1 x i64] [i64 288]
@@ -94,9 +96,14 @@ void implicit_maps_integer (int a){
 // SIMD-ONLY1-NOT: {{__kmpc|__tgt}}
 #ifdef CK2
 
+// CK2-LABEL: 
@.__omp_offloading_{{.*}}implicit_maps_reference{{.*}}_l128.region_id = weak 
constant i8 0
+
 // CK2: [[SIZES:@.+]] = {{.+}}constant [1 x i[[sz:64|32]]] [i{{64|32}} 4]
 // Map types: OMP_MAP_PRIVATE_VAL | OMP_MAP_IS_FIRST = 288
 // CK2: [[TYPES:@.+]] = {{.+}}constant [1 x i64] [i64 288]
+
+// CK2-LABEL: 
@.__omp_offloading_{{.*}}implicit_maps_reference{{.*}}_l147.region_id = weak 
constant i8 0
+
 // CK2: [[SIZES2:@.+]] = {{.+}}constant [1 x i[[sz]]] zeroinitializer
 // Map types: OMP_MAP_IS_PTR = 32
 // CK2: [[TYPES2:@.+]] = {{.+}}constant [1 x i64] [i64 32]
@@ -181,6 +188,8 @@ void implicit_maps_reference (int a, int
 // SIMD-ONLY2-NOT: {{__kmpc|__tgt}}
 #ifdef CK3
 
+// CK3-LABEL: 
@.__omp_offloading_{{.*}}implicit_maps_parameter{{.*}}_l214.region_id = weak 
constant i8 0
+
 // CK3-DAG: [[SIZES:@.+]] = {{.+}}constant [1 x i[[sz:64|32]]] [i{{64|32}} 4]
 // Map types: OMP_MAP_PRIVATE_VAL | OMP_MAP_IS_FIRST = 288
 // CK3-DAG: [[TYPES:@.+]] = {{.+}}constant [1 x i64] [i64 288]
@@ -233,6 +242,8 @@ void implicit_maps_parameter (int a){
 // SIMD-ONLY3-NOT: {{__kmpc|__tgt}}
 #ifdef CK4
 
+// CK4-LABEL: 
@.__omp_offloading_{{.*}}implicit_maps_nested_integer{{.*}}_l276.region_id = 
weak constant i8 0
+
 // CK4-DAG: [[SIZES:@.+]] = {{.+}}constant [1 x i[[sz:64|32]]] [i{{64|32}} 4]
 // Map types: OMP_MAP_PRIVATE_VAL | OMP_MAP_IS_FIRST = 288
 // CK4-DAG: [[TYPES:@.+]] = {{.+}}constant [1 x i64] [i64 288]
@@ -297,6 +308,8 @@ void implicit_maps_nested_integer (int a

[PATCH] D46615: [tools] Updating PPCallbacks::InclusionDirective calls

2018-05-09 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.

Aside from a minor nit, LGTM (no need for more review, you can fix the nit and 
commit).




Comment at: clang-move/ClangMove.cpp:135
+  const clang::Module * /*Imported*/,
+  SrcMgr::CharacteristicKind FileType) override {
 if (const auto *FileEntry = SM.getFileEntryForID(SM.getFileID(HashLoc)))

Put `FileType` into comments so the parameter is unnamed like the other unused 
ones.


https://reviews.llvm.org/D46615



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


[PATCH] D46651: [OpenCL] Support placement new/delete in Sema

2018-05-09 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added reviewers: yaxunl, Anastasia.
Herald added a subscriber: cfe-commits.

Stop crashing on placement new/delete in OpenCL C++ mode, and reject
non-placement new/delete with a diagnostic instead of a crash.


Repository:
  rC Clang

https://reviews.llvm.org/D46651

Files:
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaType.cpp
  test/SemaOpenCLCXX/newdelete.cl

Index: test/SemaOpenCLCXX/newdelete.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/newdelete.cl
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
+
+class A {
+  public:
+  A() : x(21) {}
+  int x;
+};
+
+typedef __SIZE_TYPE__ size_t;
+void *operator new(size_t _s, void *ptr) noexcept {
+  return ptr;
+}
+
+void *operator new[](size_t _s, void *ptr) noexcept {
+  return ptr;
+}
+
+// Test that only placement new and delete are available.
+void test_new_delete(void *buffer, A **a) {
+  *a = new A; // expected-error {{'non-placement new/delete' is not supported in OpenCL C++}}
+  delete a;   // expected-error {{'delete' is not supported in OpenCL C++}}
+
+  a = new A[20]; // expected-error {{'non-placement new/delete' is not supported in OpenCL C++}}
+  delete[] a;// expected-error {{'delete' is not supported in OpenCL C++}}
+
+  // Placement new is supported.
+  *a = new (buffer) A;
+
+  // Placement new is supported.
+  *a = new (buffer) A[30];
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7137,8 +7137,9 @@
   // The default address space name for arguments to a function in a
   // program, or local variables of a function is __private. All function
   // arguments shall be in the __private address space.
-  if (State.getSema().getLangOpts().OpenCLVersion <= 120) {
-  ImpAddr = LangAS::opencl_private;
+  if (State.getSema().getLangOpts().OpenCLVersion <= 120 &&
+  !State.getSema().getLangOpts().OpenCLCPlusPlus) {
+ImpAddr = LangAS::opencl_private;
   } else {
 // If address space is not set, OpenCL 2.0 defines non private default
 // address spaces for some cases:
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2019,6 +2019,15 @@
 
 if (!AllPlaceArgs.empty())
   PlacementArgs = AllPlaceArgs;
+else {
+  // OpenCL C++ 1.0 s2.9: non-placement new and delete operators are
+  // not supported.
+  if (getLangOpts().OpenCLCPlusPlus) {
+Diag(StartLoc, diag::err_openclcxx_not_supported)
+<< "non-placement new/delete";
+return ExprError();
+  }
+}
 
 // FIXME: This is wrong: PlacementArgs misses out the first (size) argument.
 DiagnoseSentinelCalls(OperatorNew, PlacementLParen, PlacementArgs);
@@ -2146,7 +2155,8 @@
   else if (AllocType->isVariablyModifiedType())
 return Diag(Loc, diag::err_variably_modified_new_type)
  << AllocType;
-  else if (AllocType.getAddressSpace() != LangAS::Default)
+  else if (AllocType.getAddressSpace() != LangAS::Default &&
+  !getLangOpts().OpenCLCPlusPlus)
 return Diag(Loc, diag::err_address_space_qualified_new)
   << AllocType.getUnqualifiedType()
   << AllocType.getQualifiers().getAddressSpaceAttributePrintValue();
@@ -3157,6 +3167,11 @@
   bool ArrayFormAsWritten = ArrayForm;
   bool UsualArrayDeleteWantsSize = false;
 
+  if (getLangOpts().OpenCLCPlusPlus) {
+Diag(StartLoc, diag::err_openclcxx_not_supported) << "delete";
+return ExprError();
+  }
+
   if (!Ex.get()->isTypeDependent()) {
 // Perform lvalue-to-rvalue cast, if needed.
 Ex = DefaultLvalueConversion(Ex.get());
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -12981,6 +12981,18 @@
 diag::err_operator_new_delete_dependent_result_type)
 << FnDecl->getDeclName() << ExpectedResultType;
 
+  // OpenCL C++: ignore the address space as the operator is valid on any
+  // address space.
+  if (SemaRef.getLangOpts().OpenCLCPlusPlus) {
+if (auto *PtrTy = ResultType.getTypePtr()->getAs()) {
+  QualType PteeTy = PtrTy->getPointeeType();
+  Qualifiers Quals = PteeTy.getQualifiers();
+  Quals.removeAddressSpace();
+  ResultType = SemaRef.Context.getQualifiedType(PteeTy.getUnqualifiedType(), Quals);
+  ResultType = SemaRef.Context.getPointerType(ResultType);
+}
+  }
+
   // Check that the result type is what we expect.
   if (SemaRef.Context.getCanonicalType(ResultType) != ExpectedResultType)
 return SemaRef.Diag(FnDecl->getLocation(),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/

[PATCH] D46485: Add python tool to dump and construct header maps

2018-05-09 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Ping!


Repository:
  rC Clang

https://reviews.llvm.org/D46485



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


[PATCH] D46614: [clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

This will break things in clang-tools-extra without 
https://reviews.llvm.org/D46615, so I'm going to hold off landing this until 
that goes through


https://reviews.llvm.org/D46614



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


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

In https://reviews.llvm.org/D43341#1093117, @juliehockett wrote:

> This will break things in clang-tools-extra without 
> https://reviews.llvm.org/D46615, so I'm going to hold off landing this until 
> that goes through


Oops wrong patch disregard


https://reviews.llvm.org/D43341



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


[PATCH] D42966: Fix USR generation in the presence of #line directives or linemarkes

2018-05-09 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In https://reviews.llvm.org/D42966#1085303, @mikhail.ramalho wrote:

> Hi,
>
> > Where do virtual files come from in the first place?
>
> From the linemarker:


I tried dumping locations in presence of line markers.
They have non-null `FileEntry` and a reasonable offset, so the original code 
should work just fine in presence of line markers.
I don't see why changing to presumed locations fixes the issue with not 
generating the USRs.

Could you provide a minimal example where USRs are not generated? It might be 
the case that there are other ways to fix it.


Repository:
  rC Clang

https://reviews.llvm.org/D42966



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


[PATCH] D46601: [OpenCL] Fix typos in emitted enqueue kernel function names

2018-05-09 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331895: [OpenCL] Fix typos in emitted enqueue kernel 
function names (authored by yaxunl, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46601?vs=145773&id=145948#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46601

Files:
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Index: cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
===
--- cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -88,7 +88,7 @@
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, i32 0
   // B64: store i64 256, i64* %[[TMP1]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_vaargs(
+  // COMMON-LABEL: call i32 @__enqueue_kernel_varargs(
   // COMMON-SAME: %opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}},
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK1:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG1]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1,
@@ -109,7 +109,7 @@
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, i32 0
   // B64: store i64 %{{.*}}, i64* %[[TMP1]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_vaargs(
+  // COMMON-LABEL: call i32 @__enqueue_kernel_varargs(
   // COMMON-SAME: %opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}},
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK2:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG2]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1,
@@ -133,7 +133,7 @@
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, i32 0
   // B64: store i64 256, i64* %[[TMP1]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_events_vaargs
+  // COMMON-LABEL: call i32 @__enqueue_kernel_events_varargs
   // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]],  %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t{{.*}} [[WAIT_EVNT]], %opencl.clk_event_t{{.*}} [[EVNT]],
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK3:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG3]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1,
@@ -157,7 +157,7 @@
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, i32 0
   // B64: store i64 %{{.*}}, i64* %[[TMP1]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_events_vaargs
+  // COMMON-LABEL: call i32 @__enqueue_kernel_events_varargs
   // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]],  %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t{{.*}}* addrspace(4)* [[WAIT_EVNT]], %opencl.clk_event_t{{.*}}* addrspace(4)* [[EVNT]],
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK4:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG4]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1,
@@ -179,7 +179,7 @@
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, i32 0
   // B64: store i64 %{{.*}}, i64* %[[TMP1]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_vaargs
+  // COMMON-LABEL: call i32 @__enqueue_kernel_varargs
   // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}},
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK5:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG5]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1,
@@ -208,7 +208,7 @@
   // B64: store i64 2, i64* %[[TMP2]], align 8
   // B64: %[[TMP3:.*]] = getelementptr [3 x i64], [3 x i64]* %[[TMP]], i32 0, i32 2
   // B64: store i64 4, i64* %[[TMP3]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_vaargs
+  // COMMON-LABEL: call i32 @__enqueue_kernel_varargs
   // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}},
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK6:[^ ]+_kernel]] to i8*) to i

r331895 - [OpenCL] Fix typos in emitted enqueue kernel function names

2018-05-09 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Wed May  9 10:07:06 2018
New Revision: 331895

URL: http://llvm.org/viewvc/llvm-project?rev=331895&view=rev
Log:
[OpenCL] Fix typos in emitted enqueue kernel function names

Two typos: 
vaarg => vararg
get_kernel_preferred_work_group_multiple => 
get_kernel_preferred_work_group_size_multiple

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

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=331895&r1=331894&r2=331895&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed May  9 10:07:06 2018
@@ -3164,10 +3164,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   return Ptr;
 };
 
-// Could have events and/or vaargs.
+// Could have events and/or varargs.
 if (E->getArg(3)->getType()->isBlockPointerType()) {
   // No events passed, but has variadic arguments.
-  Name = "__enqueue_kernel_vaargs";
+  Name = "__enqueue_kernel_varargs";
   auto Info =
   CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(3));
   llvm::Value *Kernel =
@@ -3235,7 +3235,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   // Pass the number of variadics to the runtime function too.
   Args.push_back(ConstantInt::get(Int32Ty, NumArgs - 7));
   ArgTys.push_back(Int32Ty);
-  Name = "__enqueue_kernel_events_vaargs";
+  Name = "__enqueue_kernel_events_varargs";
 
   auto *PtrToSizeArray = CreateArrayForSizeVar(7);
   Args.push_back(PtrToSizeArray);
@@ -3276,7 +3276,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 CGM.CreateRuntimeFunction(
 llvm::FunctionType::get(IntTy, {GenericVoidPtrTy, 
GenericVoidPtrTy},
 false),
-"__get_kernel_preferred_work_group_multiple_impl"),
+"__get_kernel_preferred_work_group_size_multiple_impl"),
 {Kernel, Arg}));
   }
   case Builtin::BIget_kernel_max_sub_group_size_for_ndrange:

Modified: cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl?rev=331895&r1=331894&r2=331895&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl Wed May  9 
10:07:06 2018
@@ -88,7 +88,7 @@ kernel void device_side_enqueue(global i
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, 
i32 0
   // B64: store i64 256, i64* %[[TMP1]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_vaargs(
+  // COMMON-LABEL: call i32 @__enqueue_kernel_varargs(
   // COMMON-SAME: %opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], 
%struct.ndrange_t* [[NDR]]{{([0-9]+)?}},
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} 
[[INVGK1:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ 
i32, i32 } addrspace(1)* [[BLG1]] to i8 addrspace(1)*) to i8 addrspace(4)*), 
i32 1,
@@ -109,7 +109,7 @@ kernel void device_side_enqueue(global i
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, 
i32 0
   // B64: store i64 %{{.*}}, i64* %[[TMP1]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_vaargs(
+  // COMMON-LABEL: call i32 @__enqueue_kernel_varargs(
   // COMMON-SAME: %opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], 
%struct.ndrange_t* [[NDR]]{{([0-9]+)?}},
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} 
[[INVGK2:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ 
i32, i32 } addrspace(1)* [[BLG2]] to i8 addrspace(1)*) to i8 addrspace(4)*), 
i32 1,
@@ -133,7 +133,7 @@ kernel void device_side_enqueue(global i
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, 
i32 0
   // B64: store i64 256, i64* %[[TMP1]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_events_vaargs
+  // COMMON-LABEL: call i32 @__enqueue_kernel_events_varargs
   // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]],  
%struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t{{.*}} [[WAIT_EVNT]], 
%opencl.clk_event_t{{.*}} [[EVNT]],
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} 
[[INVGK3:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ 
i32, i32 } addrspace(1)* [[BLG3]] to i8 addrspace(1)*) to i8 addrspace(4)*),

[PATCH] D45900: CodeGen: Fix invalid bitcast for lifetime.start/end

2018-05-09 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D45900#1093154, @yaxunl wrote:

> In https://reviews.llvm.org/D45900#1083377, @rjmccall wrote:
>
> > Oh, I see, it's not that the lifetime intrinsics don't handle pointers in 
> > the alloca address space, it's that we might have already promoted them 
> > into `DefaultAS`.
> >
> > Do the LLVM uses of lifetime intrinsics actually look through these address 
> > space casts?  I'm wondering if we might need to change how we emit the 
> > intrinsics so that they're emitted directly on (bitcasts of) the underlying 
> > allocas.
>
>
> Some passes do not look through address space casts. Although there is 
> InferAddressSpace pass which can eliminate the redundant address space casts, 
> still it is desirable not to emit redundant address space in Clang.
>
> To avoid increasing complexity of alloca emitting API, I think we need a way 
> to track the original alloca and the alloca casted to default address space. 
> I can think of two ways:
>
> 1. add OriginalPointer member to Address, which is the originally emitted 
> LLVM value for the variable. Whenever we pass the address of a variable we 
> also pass the original LLVM value.
> 2. add a map to CodeGenFunction to map the casted alloca to the real alloca.
>
>   Any suggestion? Thanks.


Can we just call CreateLifetimeStart (and push the cleanup to call 
CreateLifetimeEnd) immediately after creating the alloca instead of waiting 
until later like we do now?

Modifying Address is not appropriate, and adding a map to CGF would be big 
waste.


https://reviews.llvm.org/D45900



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


[PATCH] D46332: [X86] Only enable the __ud2 and __int2c builtins if intrin.h has been included.

2018-05-09 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC331893: [X86] Only enable the __ud2 and __int2c builtins if 
intrin.h has been included. (authored by ctopper, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D46332

Files:
  include/clang/Basic/BuiltinsX86.def


Index: include/clang/Basic/BuiltinsX86.def
===
--- include/clang/Basic/BuiltinsX86.def
+++ include/clang/Basic/BuiltinsX86.def
@@ -1899,8 +1899,8 @@
 TARGET_HEADER_BUILTIN(_AddressOfReturnAddress, "v*", "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(__stosb, "vUc*Ucz", "nh", "intrin.h", ALL_MS_LANGUAGES, 
"")
-TARGET_HEADER_BUILTIN(__int2c, "v",   "nr", "intrin.h", ALL_MS_LANGUAGES, 
"")
-TARGET_HEADER_BUILTIN(__ud2,   "v",   "nr", "intrin.h", ALL_MS_LANGUAGES, 
"")
+TARGET_HEADER_BUILTIN(__int2c, "v",   "nhr", "intrin.h", ALL_MS_LANGUAGES, 
"")
+TARGET_HEADER_BUILTIN(__ud2,   "v",   "nhr", "intrin.h", ALL_MS_LANGUAGES, 
"")
 
 TARGET_HEADER_BUILTIN(__readfsbyte,  "UcUNi", "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__readfsword,  "UsUNi", "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")


Index: include/clang/Basic/BuiltinsX86.def
===
--- include/clang/Basic/BuiltinsX86.def
+++ include/clang/Basic/BuiltinsX86.def
@@ -1899,8 +1899,8 @@
 TARGET_HEADER_BUILTIN(_AddressOfReturnAddress, "v*", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(__stosb, "vUc*Ucz", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__int2c, "v",   "nr", "intrin.h", ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__ud2,   "v",   "nr", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__int2c, "v",   "nhr", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__ud2,   "v",   "nhr", "intrin.h", ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(__readfsbyte,  "UcUNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__readfsword,  "UsUNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r331893 - [X86] Only enable the __ud2 and __int2c builtins if intrin.h has been included.

2018-05-09 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Wed May  9 09:57:48 2018
New Revision: 331893

URL: http://llvm.org/viewvc/llvm-project?rev=331893&view=rev
Log:
[X86] Only enable the __ud2 and __int2c builtins if intrin.h has been included.

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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=331893&r1=331892&r2=331893&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Wed May  9 09:57:48 2018
@@ -1899,8 +1899,8 @@ TARGET_HEADER_BUILTIN(__emulu, "ULLiUiUi
 TARGET_HEADER_BUILTIN(_AddressOfReturnAddress, "v*", "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(__stosb, "vUc*Ucz", "nh", "intrin.h", ALL_MS_LANGUAGES, 
"")
-TARGET_HEADER_BUILTIN(__int2c, "v",   "nr", "intrin.h", ALL_MS_LANGUAGES, 
"")
-TARGET_HEADER_BUILTIN(__ud2,   "v",   "nr", "intrin.h", ALL_MS_LANGUAGES, 
"")
+TARGET_HEADER_BUILTIN(__int2c, "v",   "nhr", "intrin.h", ALL_MS_LANGUAGES, 
"")
+TARGET_HEADER_BUILTIN(__ud2,   "v",   "nhr", "intrin.h", ALL_MS_LANGUAGES, 
"")
 
 TARGET_HEADER_BUILTIN(__readfsbyte,  "UcUNi", "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__readfsword,  "UsUNi", "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")


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


  1   2   >