[PATCH] D56900: [Fixed Point Arithmetic] Fixed Point and Integer Conversions

2019-03-01 Thread Bjorn Pettersson via Phabricator via cfe-commits
bjope added inline comments.



Comment at: clang/test/Frontend/fixed_point_conversions.c:45
+
+short _Accum sa_const9 = 2u; // DEFAULT-DAG: @sa_const9 = {{.*}}global i16 
256, align 2
+unsigned short _Accum usa_const3 = 2;

Perhaps we should verify that we do not mess up signed values when using the 
-fpadding-on-unsigned-fixed-point option (having CHECK, DEFAULT and SAME as 
check prefixes)?

(nit: I also see that we now use different names for this check prefixes in 
different test files, which could be confusing. Why is it called SAME here?) 






Comment at: clang/test/Frontend/fixed_point_conversions.c:66
 
+_Sat short _Accum sat_sa_const3 = 256;  // DEFAULT-DAG: @sat_sa_const3 = 
{{.*}}global i16 32767, align 2
+_Sat short _Accum sat_sa_const4 = -257; // DEFAULT-DAG: @sat_sa_const4 = 
{{.*}}global i16 -32768, align 2

A little bit confusing to be with this mix of having checks left-aligned (on 
separate lines) and some checks appended like this.
I can see that it already is like that before, so maybe it should be cleaned up 
in a separate commit (before this commit).

(I'm not so familiar with clang tests, so maybe it is common to have the 
FileCheck checks at the end of the line. But I've never seen that in llvm.)


Repository:
  rC Clang

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

https://reviews.llvm.org/D56900



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


[PATCH] D58807: [CodeGen] COMDAT-fold block descriptors

2019-03-01 Thread David Chisnall via Phabricator via cfe-commits
theraven accepted this revision.
theraven added a comment.
This revision is now accepted and ready to land.

Looks good to me.  On ELF and Mach-O, I think we get the equivalent behaviour 
automatically from the ODR linkage type.  I'd really like to see linkage type 
and COMDAT made orthogonal, but that's a bigger change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58807



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


[PATCH] D58807: [CodeGen] COMDAT-fold block descriptors

2019-03-01 Thread David Chisnall via Phabricator via cfe-commits
theraven added a comment.

It would probably benefit from a test so that we don't regress.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58807



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


[PATCH] D58811: [clang] Fix misuses of char width to char align

2019-03-01 Thread Aleksandr Malykh via Phabricator via cfe-commits
amalykh created this revision.
amalykh added reviewers: rsmith, momchil.velikov, stephenkelly.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch replaces getCharWidth with getCharAlign where it is used incorrectly


Repository:
  rC Clang

https://reviews.llvm.org/D58811

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaChecking.cpp


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -5831,9 +5831,9 @@
   return Diag(TheCall->getBeginLoc(), diag::err_alignment_not_power_of_two)
  << Arg->getSourceRange();
 
-if (Result < Context.getCharWidth())
+if (Result < Context.getCharAlign())
   return Diag(TheCall->getBeginLoc(), diag::err_alignment_too_small)
- << (unsigned)Context.getCharWidth() << Arg->getSourceRange();
+ << (unsigned)Context.getCharAlign() << Arg->getSourceRange();
 
 if (Result > std::numeric_limits::max())
   return Diag(TheCall->getBeginLoc(), diag::err_alignment_too_big)
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -1540,7 +1540,7 @@
 }
 
 CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const {
-  unsigned Align = Target->getCharWidth();
+  unsigned Align = Target->getCharAlign();
 
   bool UseAlignAttrOnly = false;
   if (unsigned AlignFromAttr = D->getMaxAlignment()) {
@@ -1594,7 +1594,7 @@
   }
   Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr()));
   if (BaseT.getQualifiers().hasUnaligned())
-Align = Target->getCharWidth();
+Align = Target->getCharAlign();
   if (const auto *VD = dyn_cast(D)) {
 if (VD->hasGlobalStorage() && !ForAlignof)
   Align = std::max(Align, getTargetInfo().getMinGlobalAlign());
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -2103,6 +2103,11 @@
   unsigned getTypeAlign(QualType T) const { return getTypeInfo(T).Align; }
   unsigned getTypeAlign(const Type *T) const { return getTypeInfo(T).Align; }
 
+  /// Return the alignment of the character type, in bits.
+  uint64_t getCharAlign() const {
+return getTypeAlign(CharTy);
+  }
+
   /// Return the ABI-specified natural alignment of a (complete) type \p T,
   /// before alignment adjustments, in bits.
   ///


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -5831,9 +5831,9 @@
   return Diag(TheCall->getBeginLoc(), diag::err_alignment_not_power_of_two)
  << Arg->getSourceRange();
 
-if (Result < Context.getCharWidth())
+if (Result < Context.getCharAlign())
   return Diag(TheCall->getBeginLoc(), diag::err_alignment_too_small)
- << (unsigned)Context.getCharWidth() << Arg->getSourceRange();
+ << (unsigned)Context.getCharAlign() << Arg->getSourceRange();
 
 if (Result > std::numeric_limits::max())
   return Diag(TheCall->getBeginLoc(), diag::err_alignment_too_big)
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -1540,7 +1540,7 @@
 }
 
 CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const {
-  unsigned Align = Target->getCharWidth();
+  unsigned Align = Target->getCharAlign();
 
   bool UseAlignAttrOnly = false;
   if (unsigned AlignFromAttr = D->getMaxAlignment()) {
@@ -1594,7 +1594,7 @@
   }
   Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr()));
   if (BaseT.getQualifiers().hasUnaligned())
-Align = Target->getCharWidth();
+Align = Target->getCharAlign();
   if (const auto *VD = dyn_cast(D)) {
 if (VD->hasGlobalStorage() && !ForAlignof)
   Align = std::max(Align, getTargetInfo().getMinGlobalAlign());
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -2103,6 +2103,11 @@
   unsigned getTypeAlign(QualType T) const { return getTypeInfo(T).Align; }
   unsigned getTypeAlign(const Type *T) const { return getTypeInfo(T).Align; }
 
+  /// Return the alignment of the character type, in bits.
+  uint64_t getCharAlign() const {
+return getTypeAlign(CharTy);
+  }
+
   /// Return the ABI-specified natural alignment of a (complete) type \p T,
   /// before alignment adjustments, in bits.
   ///
___
cfe-commits mailing list
cfe-commi

r355181 - CodeGen: Fix PR40605 by splitting constant struct initializers

2019-03-01 Thread Alexander Potapenko via cfe-commits
Author: glider
Date: Fri Mar  1 01:00:41 2019
New Revision: 355181

URL: http://llvm.org/viewvc/llvm-project?rev=355181&view=rev
Log:
CodeGen: Fix PR40605 by splitting constant struct initializers

When emitting initializers for local structures for code built with
-ftrivial-auto-var-init, replace constant structures with sequences of
stores.

This appears to greatly help removing dead initialization stores to those
locals that are later overwritten by other data.
This also removes a lot of .rodata constants (see PR40605), replacing most
of them with immediate values (for Linux kernel the .rodata size is
reduced by ~1.9%)

Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGenCXX/auto-var-init.cpp

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=355181&r1=355180&r2=355181&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Fri Mar  1 01:00:41 2019
@@ -969,6 +969,20 @@ static llvm::Value *shouldUseMemSetToIni
   return llvm::isBytewiseValue(Init);
 }
 
+/// Decide whether we want to split a constant structure store into a sequence
+/// of its fields' stores. This may cost us code size and compilation speed,
+/// but plays better with store optimizations.
+static bool shouldSplitStructStore(CodeGenModule &CGM,
+   uint64_t GlobalByteSize) {
+  // Don't break structures that occupy more than one cacheline.
+  uint64_t ByteSizeLimit = 64;
+  if (CGM.getCodeGenOpts().OptimizationLevel == 0)
+return false;
+  if (GlobalByteSize <= ByteSizeLimit)
+return true;
+  return false;
+}
+
 static llvm::Constant *patternFor(CodeGenModule &CGM, llvm::Type *Ty) {
   // The following value is a guaranteed unmappable pointer value and has a
   // repeated byte-pattern which makes it easier to synthesize. We use it for
@@ -1201,6 +1215,8 @@ static void emitStoresForConstant(CodeGe
   // If the initializer is all or mostly the same, codegen with bzero / memset
   // then do a few stores afterward.
   uint64_t ConstantSize = CGM.getDataLayout().getTypeAllocSize(Ty);
+  if (!ConstantSize)
+return;
   auto *SizeVal = llvm::ConstantInt::get(IntPtrTy, ConstantSize);
   if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
 Builder.CreateMemSet(Loc, llvm::ConstantInt::get(Int8Ty, 0), SizeVal,
@@ -1228,6 +1244,20 @@ static void emitStoresForConstant(CodeGe
 return;
   }
 
+  llvm::StructType *STy = dyn_cast(Ty);
+  // FIXME: handle the case when STy != Loc.getElementType().
+  // FIXME: handle non-struct aggregate types.
+  if (STy && (STy == Loc.getElementType()) &&
+  shouldSplitStructStore(CGM, ConstantSize)) {
+for (unsigned i = 0; i != constant->getNumOperands(); i++) {
+  Address EltPtr = Builder.CreateStructGEP(Loc, i);
+  emitStoresForConstant(
+  CGM, D, EltPtr, isVolatile, Builder,
+  cast(Builder.CreateExtractValue(constant, i)));
+}
+return;
+  }
+
   Builder.CreateMemCpy(
   Loc,
   createUnnamedGlobalFrom(CGM, D, Builder, constant, Loc.getAlignment()),

Modified: cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/auto-var-init.cpp?rev=355181&r1=355180&r2=355181&view=diff
==
--- cfe/trunk/test/CodeGenCXX/auto-var-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/auto-var-init.cpp Fri Mar  1 01:00:41 2019
@@ -1,6 +1,8 @@
-// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown -fblocks %s 
-emit-llvm -o - | FileCheck %s
-// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown -fblocks 
-ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s 
-check-prefix=PATTERN
-// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown -fblocks 
-ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s 
-check-prefix=ZERO
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown -fblocks %s 
-emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,CHECK-O0
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown -fblocks 
-ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s 
-check-prefixes=CHECK-O0,PATTERN,PATTERN-O0
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown -fblocks 
-ftrivial-auto-var-init=pattern %s -O1 -emit-llvm -o - | FileCheck %s 
-check-prefixes=CHECK-O1,PATTERN,PATTERN-O1
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown -fblocks 
-ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s 
-check-prefixes=CHECK-O0,ZERO,ZERO-O0
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown -fblocks 
-ftrivial-auto-var-init=zero %s -O1 -emit-llvm -o - | FileCheck %s 
-check-prefixes=CHECK-O1,ZERO,ZERO-O1
 
 template void used(T &) noexcept;
 
@@ -30,120 +32,192 @@ template void used(T &) noex

[PATCH] D57898: CodeGen: Fix PR40605 by splitting constant struct initializers

2019-03-01 Thread Alexander Potapenko via Phabricator via cfe-commits
glider closed this revision.
glider added a comment.

Landed r355181, thank you!


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

https://reviews.llvm.org/D57898



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


r355182 - [clang-format] [NFC] clang-format the Format library

2019-03-01 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Fri Mar  1 01:09:54 2019
New Revision: 355182

URL: http://llvm.org/viewvc/llvm-project?rev=355182&view=rev
Log:
[clang-format] [NFC] clang-format the Format library

Previously revisions commited non-clang-formatted changes to the Format 
library, this means submitting any revision e.g. {D55170} can cause additional 
whitespace changes to potentially be included in a revision.

Commit a non functional change using latest build Windows clang-format r351376 
with no other changes, to remove these differences

All FormatTests
pass [==] 652 tests from 20 test cases ran.

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/lib/Format/BreakableToken.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/FormatTokenLexer.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.h
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.h
cfe/trunk/lib/Format/WhitespaceManager.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=355182&r1=355181&r2=355182&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Fri Mar  1 01:09:54 2019
@@ -62,12 +62,10 @@ static StringRef getLineCommentIndentPre
   return LongestPrefix;
 }
 
-static BreakableToken::Split getCommentSplit(StringRef Text,
- unsigned ContentStartColumn,
- unsigned ColumnLimit,
- unsigned TabWidth,
- encoding::Encoding Encoding,
- const FormatStyle &Style) {
+static BreakableToken::Split
+getCommentSplit(StringRef Text, unsigned ContentStartColumn,
+unsigned ColumnLimit, unsigned TabWidth,
+encoding::Encoding Encoding, const FormatStyle &Style) {
   LLVM_DEBUG(llvm::dbgs() << "Comment split: \"" << Text
   << "\", Column limit: " << ColumnLimit
   << ", Content start: " << ContentStartColumn << 
"\n");
@@ -191,7 +189,7 @@ bool switchesFormatting(const FormatToke
 
 unsigned
 BreakableToken::getLengthAfterCompression(unsigned RemainingTokenColumns,
-  Split Split) const {
+  Split Split) const {
   // Example: consider the content
   // lala  lala
   // - RemainingTokenColumns is the original number of columns, 10;
@@ -870,23 +868,20 @@ void BreakableLineCommentSection::reflow
 // the next line.
 unsigned WhitespaceLength =
 Lines[LineIndex].data() - tokenAt(LineIndex).TokenText.data() - Offset;
-Whitespaces.replaceWhitespaceInToken(*Tokens[LineIndex],
- Offset,
+Whitespaces.replaceWhitespaceInToken(*Tokens[LineIndex], Offset,
  /*ReplaceChars=*/WhitespaceLength,
  /*PreviousPostfix=*/"",
  /*CurrentPrefix=*/"",
  /*InPPDirective=*/false,
  /*Newlines=*/0,
  /*Spaces=*/0);
-
   }
   // Replace the indent and prefix of the token with the reflow prefix.
   unsigned Offset =
   Lines[LineIndex].data() - tokenAt(LineIndex).TokenText.data();
   unsigned WhitespaceLength =
   Content[LineIndex].data() - Lines[LineIndex].data();
-  Whitespaces.replaceWhitespaceInToken(*Tokens[LineIndex],
-   Offset,
+  Whitespaces.replaceWhitespaceInToken(*Tokens[LineIndex], Offset,
/*ReplaceChars=*/WhitespaceLength,
/*PreviousPostfix=*/"",
/*CurrentPrefix=*/ReflowPrefix,

Modified: cfe/trunk/lib/Format/BreakableToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.h?rev=355182&r1=355181&r2=355182&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.h (original)
+++ cfe/trunk/lib/Format/BreakableToken.h Fri Mar  1 01:09:54 2019
@@ -146,9 +146,7 @@ public:
   //  * @param loong line
   //  * continuation
   //  */
-  virtual unsigned getContentIndent(unsigned LineIndex) const {
-return 0;
-  }
+  virtual unsigned getContentIndent(unsigned LineIndex) const { return 0; }
 
   /// Returns a range (offset, length) at which to break the l

[PATCH] D58811: [clang] Fix misuses of char width to char align

2019-03-01 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Can you be more specific?
Is there some bugreport this fixes?
Is there some test?


Repository:
  rC Clang

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

https://reviews.llvm.org/D58811



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


[PATCH] D58743: Handle built-in when importing SourceLocation and FileID

2019-03-01 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Looks good now.


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

https://reviews.llvm.org/D58743



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


[clang-tools-extra] r355188 - Fix file headers. NFC

2019-03-01 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Fri Mar  1 01:52:53 2019
New Revision: 355188

URL: http://llvm.org/viewvc/llvm-project?rev=355188&view=rev
Log:
Fix file headers. NFC

Modified:
clang-tools-extra/trunk/change-namespace/tool/ClangChangeNamespace.cpp
clang-tools-extra/trunk/clang-doc/Generators.cpp
clang-tools-extra/trunk/clang-doc/Serialize.cpp
clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
clang-tools-extra/trunk/clang-move/HelperDeclRefGraph.cpp
clang-tools-extra/trunk/clang-tidy/cert/CommandProcessorCheck.cpp
clang-tools-extra/trunk/clang-tidy/cert/StrToNumCheck.cpp
clang-tools-extra/trunk/clang-tidy/cert/VariadicFunctionDefCheck.cpp

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/performance/PerformanceTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/readability/FunctionSizeCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/StringCompareCheck.cpp
clang-tools-extra/trunk/clang-tidy/utils/OptionsUtils.cpp
clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp
clang-tools-extra/trunk/clangd/xpc/framework/ClangdXPC.cpp
clang-tools-extra/trunk/clangd/xpc/test-client/ClangdXPCTestClient.cpp
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
clang-tools-extra/trunk/unittests/clang-query/QueryEngineTest.cpp
clang-tools-extra/trunk/unittests/clangd/FunctionTests.cpp
clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
clang-tools-extra/trunk/unittests/clangd/TestIndex.cpp

Modified: clang-tools-extra/trunk/change-namespace/tool/ClangChangeNamespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/tool/ClangChangeNamespace.cpp?rev=355188&r1=355187&r2=355188&view=diff
==
--- clang-tools-extra/trunk/change-namespace/tool/ClangChangeNamespace.cpp 
(original)
+++ clang-tools-extra/trunk/change-namespace/tool/ClangChangeNamespace.cpp Fri 
Mar  1 01:52:53 2019
@@ -1,4 +1,4 @@
-//===-- ClangIncludeFixer.cpp - Standalone change namespace 
---===//
+//===-- ClangChangeNamespace.cpp - Standalone change namespace 
===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Modified: clang-tools-extra/trunk/clang-doc/Generators.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Generators.cpp?rev=355188&r1=355187&r2=355188&view=diff
==
--- clang-tools-extra/trunk/clang-doc/Generators.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/Generators.cpp Fri Mar  1 01:52:53 2019
@@ -1,4 +1,4 @@
-//=== Generator.cpp - Generator Registry -*- 
C++-*-===//
+//===-- Generators.cpp - Generator Registry --*- 
C++-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Modified: clang-tools-extra/trunk/clang-doc/Serialize.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Serialize.cpp?rev=355188&r1=355187&r2=355188&view=diff
==
--- clang-tools-extra/trunk/clang-doc/Serialize.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/Serialize.cpp Fri Mar  1 01:52:53 2019
@@ -1,4 +1,4 @@
-//===-- Serializer.cpp - ClangDoc Serializer *- C++ 
-*-===//
+//===-- Serialize.cpp - ClangDoc Serializer -*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Modified: clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp?rev=355188&r1=355187&r2=355188&view=diff
==
--- clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp Fri Mar  1 01:52:53 2019
@@ -1,4 +1,4 @@
-//===--  ClangDocYAML.cpp - ClangDoc YAML ---*- C++ 
-*-===//
+//===-- YAMLGenerator.cpp - ClangDoc YAML ---*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Modified: clang-tools-extra/trunk/clang-move/HelperDeclRefGraph.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/HelperDeclRefGraph.cpp?rev=355188&r1=355187&r2=355188&view=diff
=

[PATCH] D57914: [Driver] Allow enum SanitizerOrdinal to represent more than 64 different sanitizer checks, NFC.

2019-03-01 Thread pierre gousseau via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
pgousseau marked an inline comment as done.
Closed by commit rL355190: [Driver] Allow enum SanitizerOrdinal to represent 
more than 64 different… (authored by pgousseau, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D57914?vs=188748&id=188866#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D57914

Files:
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Basic/Sanitizers.def
  cfe/trunk/include/clang/Basic/Sanitizers.h
  cfe/trunk/include/clang/Driver/ToolChain.h
  cfe/trunk/lib/Basic/SanitizerSpecialCaseList.cpp
  cfe/trunk/lib/Basic/Sanitizers.cpp
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/Driver/SanitizerArgs.cpp
  cfe/trunk/lib/Driver/ToolChain.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp
@@ -6301,7 +6301,8 @@
 if (!S.checkStringLiteralArgumentAttr(AL, I, SanitizerName, &LiteralLoc))
   return;
 
-if (parseSanitizerValue(SanitizerName, /*AllowGroups=*/true) == 0)
+if (parseSanitizerValue(SanitizerName, /*AllowGroups=*/true) ==
+SanitizerMask())
   S.Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName;
 else if (isGlobalVar(D) && SanitizerName != "address")
   S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
Index: cfe/trunk/lib/Basic/SanitizerSpecialCaseList.cpp
===
--- cfe/trunk/lib/Basic/SanitizerSpecialCaseList.cpp
+++ cfe/trunk/lib/Basic/SanitizerSpecialCaseList.cpp
@@ -36,7 +36,7 @@
 
 void SanitizerSpecialCaseList::createSanitizerSections() {
   for (auto &S : Sections) {
-SanitizerMask Mask = 0;
+SanitizerMask Mask;
 
 #define SANITIZER(NAME, ID)\
   if (S.SectionMatcher->match(NAME))   \
Index: cfe/trunk/lib/Basic/Sanitizers.cpp
===
--- cfe/trunk/lib/Basic/Sanitizers.cpp
+++ cfe/trunk/lib/Basic/Sanitizers.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "clang/Basic/Sanitizers.h"
+#include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringSwitch.h"
 
 using namespace clang;
@@ -19,9 +20,9 @@
   SanitizerMask ParsedKind = llvm::StringSwitch(Value)
 #define SANITIZER(NAME, ID) .Case(NAME, SanitizerKind::ID)
 #define SANITIZER_GROUP(NAME, ID, ALIAS)   \
-  .Case(NAME, AllowGroups ? SanitizerKind::ID##Group : 0)
+  .Case(NAME, AllowGroups ? SanitizerKind::ID##Group : SanitizerMask())
 #include "clang/Basic/Sanitizers.def"
-.Default(0);
+.Default(SanitizerMask());
   return ParsedKind;
 }
 
@@ -33,3 +34,13 @@
 #include "clang/Basic/Sanitizers.def"
   return Kinds;
 }
+
+llvm::hash_code SanitizerMask::hash_value() const {
+  return llvm::hash_combine_range(&maskLoToHigh[0], &maskLoToHigh[kNumElem]);
+}
+
+namespace clang {
+llvm::hash_code hash_value(const clang::SanitizerMask &Arg) {
+  return Arg.hash_value();
+}
+} // namespace clang
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -551,7 +551,7 @@
 DiagnosticsEngine &Diags, SanitizerSet &S) {
   for (const auto &Sanitizer : Sanitizers) {
 SanitizerMask K = parseSanitizerValue(Sanitizer, /*AllowGroups=*/false);
-if (K == 0)
+if (K == SanitizerMask())
   Diags.Report(diag::err_drv_invalid_value) << FlagName << Sanitizer;
 else
   S.set(K, true);
Index: cfe/trunk/lib/CodeGen/CGExpr.cpp
===
--- cfe/trunk/lib/CodeGen/CGExpr.cpp
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp
@@ -2855,16 +2855,13 @@
 }
 
 static CheckRecoverableKind getRecoverableKind(SanitizerMask Kind) {
-  assert(llvm::countPopulation(Kind) == 1);
-  switch (Kind) {
-  case SanitizerKind::Vptr:
+  assert(Kind.countPopulation() == 1);
+  if (Kind == SanitizerKind::Vptr)
 return CheckRecoverableKind::AlwaysRecoverable;
-  case SanitizerKind::Return:
-  case SanitizerKind::Unreachable:
+  else if (Kind == SanitizerKind::Return || Kind == SanitizerKind::Unreachable)
 return CheckRecoverableKind::Unrecoverable;
-  default:
+  else
 return CheckRecoverableKind::Recoverable;
-  }
 }
 
 namespace {
Index: cfe/trunk/lib/Driver/SanitizerArgs.cpp
===
---

r355190 - [Driver] Allow enum SanitizerOrdinal to represent more than 64 different sanitizer checks, NFC.

2019-03-01 Thread Pierre Gousseau via cfe-commits
Author: pgousseau
Date: Fri Mar  1 02:05:15 2019
New Revision: 355190

URL: http://llvm.org/viewvc/llvm-project?rev=355190&view=rev
Log:
[Driver] Allow enum SanitizerOrdinal to represent more than 64 different 
sanitizer checks, NFC.

enum SanitizerOrdinal has reached maximum capacity, this change extends the 
capacity to 128 sanitizer checks.
This can eventually allow us to add gcc 8's options 
"-fsanitize=pointer-substract" and "-fsanitize=pointer-compare".

This is a recommit of r354873 but with a fix for unqualified lookup error in 
lldb cmake build bot.

Fixes: https://llvm.org/PR39425

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

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/Sanitizers.def
cfe/trunk/include/clang/Basic/Sanitizers.h
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Basic/SanitizerSpecialCaseList.cpp
cfe/trunk/lib/Basic/Sanitizers.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=355190&r1=355189&r2=355190&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Fri Mar  1 02:05:15 2019
@@ -2366,7 +2366,7 @@ def NoSanitize : InheritableAttr {
   let Documentation = [NoSanitizeDocs];
   let AdditionalMembers = [{
 SanitizerMask getMask() const {
-  SanitizerMask Mask = 0;
+  SanitizerMask Mask;
   for (auto SanitizerName : sanitizers()) {
 SanitizerMask ParsedMask =
 parseSanitizerValue(SanitizerName, /*AllowGroups=*/true);

Modified: cfe/trunk/include/clang/Basic/Sanitizers.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.def?rev=355190&r1=355189&r2=355190&view=diff
==
--- cfe/trunk/include/clang/Basic/Sanitizers.def (original)
+++ cfe/trunk/include/clang/Basic/Sanitizers.def Fri Mar  1 02:05:15 2019
@@ -177,7 +177,7 @@ SANITIZER("scudo", Scudo)
 
 // Magic group, containing all sanitizers. For example, "-fno-sanitize=all"
 // can be used to disable all the sanitizers.
-SANITIZER_GROUP("all", All, ~0ULL)
+SANITIZER_GROUP("all", All, ~SanitizerMask())
 
 #undef SANITIZER
 #undef SANITIZER_GROUP

Modified: cfe/trunk/include/clang/Basic/Sanitizers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.h?rev=355190&r1=355189&r2=355190&view=diff
==
--- cfe/trunk/include/clang/Basic/Sanitizers.h (original)
+++ cfe/trunk/include/clang/Basic/Sanitizers.h Fri Mar  1 02:05:15 2019
@@ -20,45 +20,166 @@
 #include 
 #include 
 
+namespace llvm {
+class hash_code;
+}
+
 namespace clang {
 
-using SanitizerMask = uint64_t;
+class SanitizerMask {
+  /// Number of array elements.
+  static constexpr unsigned kNumElem = 2;
+  /// Mask value initialized to 0.
+  uint64_t maskLoToHigh[kNumElem]{};
+  /// Number of bits in a mask.
+  static constexpr unsigned kNumBits = sizeof(decltype(maskLoToHigh)) * 8;
+  /// Number of bits in a mask element.
+  static constexpr unsigned kNumBitElem = sizeof(decltype(maskLoToHigh[0])) * 
8;
+
+public:
+  static constexpr bool checkBitPos(const unsigned Pos) {
+return Pos < kNumBits;
+  }
 
-namespace SanitizerKind {
+  /// Create a mask with a bit enabled at position Pos.
+  static SanitizerMask bitPosToMask(const unsigned Pos) {
+assert(Pos < kNumBits && "Bit position too big.");
+SanitizerMask mask;
+mask.maskLoToHigh[Pos / kNumBitElem] = 1ULL << Pos % kNumBitElem;
+return mask;
+  }
 
-// Assign ordinals to possible values of -fsanitize= flag, which we will use as
-// bit positions.
-enum SanitizerOrdinal : uint64_t {
-#define SANITIZER(NAME, ID) SO_##ID,
-#define SANITIZER_GROUP(NAME, ID, ALIAS) SO_##ID##Group,
-#include "clang/Basic/Sanitizers.def"
-  SO_Count
+  unsigned countPopulation() const {
+unsigned total = 0;
+for (const auto &Val : maskLoToHigh)
+  total += llvm::countPopulation(Val);
+return total;
+  }
+
+  void flipAllBits() {
+for (auto &Val : maskLoToHigh)
+  Val = ~Val;
+  }
+
+  bool isPowerOf2() const {
+return countPopulation() == 1;
+  }
+
+  llvm::hash_code hash_value() const;
+
+  explicit operator bool() const {
+for (const auto &Val : maskLoToHigh)
+  if (Val)
+return true;
+return false;
+  };
+
+  bool operator==(const SanitizerMask &V) const {
+for (unsigned k = 0; k < kNumElem; k++) {
+  if (maskLoToHigh[k] != V.maskLoToHigh[k])
+return false;
+}
+return true;
+  }
+
+  SanitizerMask &operator&=(const Sanitiz

[PATCH] D58811: [clang] Fix misuses of char width to char align

2019-03-01 Thread Aleksandr Malykh via Phabricator via cfe-commits
amalykh added a comment.

Currently getCharWidth and getCharAlign functions are hard coded to return 8 in 
clang with no way to change it for target.
This can be seen in TargetInfo.h file:

  unsigned getCharWidth() const { return 8; } // FIXME
  unsigned getCharAlign() const { return 8; } // FIXME

It means that these functions can be used interchangeably and there will be no 
test failures because of this, until custom alignment will be supported.
Nevertheless, it will not be possible to


Repository:
  rC Clang

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

https://reviews.llvm.org/D58811



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


[PATCH] D58814: [clang][Index] Constructors and Destructors do not reference class

2019-03-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: akyrtzi, gribozavr.
Herald added subscribers: cfe-commits, arphaman.
Herald added a project: clang.

In current indexing logic we get references to class itself when we see
a constructor/destructor which is not true. Eventough spelling is same with
class' name it does not refer to it. This patch deletes those calls.


Repository:
  rC Clang

https://reviews.llvm.org/D58814

Files:
  lib/Index/IndexDecl.cpp
  test/Index/Core/index-source.cpp
  unittests/Index/IndexTests.cpp

Index: unittests/Index/IndexTests.cpp
===
--- unittests/Index/IndexTests.cpp
+++ unittests/Index/IndexTests.cpp
@@ -257,6 +257,23 @@
   Contains(AllOf(QName("std::foo"), Kind(SymbolKind::Using;
 }
 
+TEST(IndexTest, Constructors) {
+  std::string Code = R"cpp(
+struct Foo {
+  Foo(int);
+  ~Foo();
+};
+  )cpp";
+  auto Index = std::make_shared();
+  IndexingOptions Opts;
+  tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols,
+  UnorderedElementsAre(
+  AllOf(QName("Foo"), Kind(SymbolKind::Struct)),
+  AllOf(QName("Foo::Foo"), Kind(SymbolKind::Constructor)),
+  AllOf(QName("Foo::~Foo"), Kind(SymbolKind::Destructor;
+}
+
 } // namespace
 } // namespace index
 } // namespace clang
Index: test/Index/Core/index-source.cpp
===
--- test/Index/Core/index-source.cpp
+++ test/Index/Core/index-source.cpp
@@ -5,17 +5,17 @@
 class Cls { public:
   // CHECK: [[@LINE+3]]:3 | constructor/C++ | Cls | c:@S@Cls@F@Cls#I# | __ZN3ClsC1Ei | Decl,RelChild | rel: 1
   // CHECK-NEXT: RelChild | Cls | c:@S@Cls
-  // CHECK: [[@LINE+1]]:3 | class/C++ | Cls | c:@S@Cls |  | Ref,RelCont | rel: 1
+
   Cls(int x);
   // CHECK: [[@LINE+2]]:3 | constructor/cxx-copy-ctor/C++ | Cls | c:@S@Cls@F@Cls#&1$@S@Cls# | __ZN3ClsC1ERKS_ | Decl,RelChild | rel: 1
-  // CHECK: [[@LINE+1]]:3 | class/C++ | Cls | c:@S@Cls |  | Ref,RelCont | rel: 1
+
   Cls(const Cls &);
   // CHECK: [[@LINE+2]]:3 | constructor/cxx-move-ctor/C++ | Cls | c:@S@Cls@F@Cls#&&$@S@Cls# | __ZN3ClsC1EOS_ | Decl,RelChild | rel: 1
-  // CHECK: [[@LINE+1]]:3 | class/C++ | Cls | c:@S@Cls |  | Ref,RelCont | rel: 1
+
   Cls(Cls &&);
 
   // CHECK: [[@LINE+2]]:3 | destructor/C++ | ~Cls | c:@S@Cls@F@~Cls# | __ZN3ClsD1Ev | Decl,RelChild | rel: 1
-  // CHECK: [[@LINE+1]]:4 | class/C++ | Cls | c:@S@Cls |  | Ref,RelCont | rel: 1
+
   ~Cls();
 };
 
@@ -35,12 +35,10 @@
 Cls::Cls(int x) {}
 // CHECK: [[@LINE-1]]:6 | constructor/C++ | Cls | c:@S@Cls@F@Cls#I# | __ZN3ClsC1Ei | Def,RelChild | rel: 1
 // CHECK: [[@LINE-2]]:1 | class/C++ | Cls | c:@S@Cls |  | Ref,RelCont | rel: 1
-// CHECK: [[@LINE-3]]:6 | class/C++ | Cls | c:@S@Cls |  | Ref,RelCont | rel: 1
 
 Cls::~/*a comment*/Cls() {}
 // CHECK: [[@LINE-1]]:6 | destructor/C++ | ~Cls | c:@S@Cls@F@~Cls# | __ZN3ClsD1Ev | Def,RelChild | rel: 1
 // CHECK: [[@LINE-2]]:1 | class/C++ | Cls | c:@S@Cls |  | Ref,RelCont | rel: 1
-// CHECK: [[@LINE-3]]:20 | class/C++ | Cls | c:@S@Cls |  | Ref,RelCont | rel: 1
 
 template 
 class TemplCls {
@@ -394,7 +392,6 @@
 // CHECK: [[@LINE-1]]:3 | constructor/cxx-copy-ctor/C++ | DeletedMethods | c:@S@DeletedMethods@F@DeletedMethods#&1$@S@DeletedMethods# | __ZN14DeletedMethodsC1ERKS_ | Def,RelChild | rel: 1
 // CHECK: RelChild | DeletedMethods | c:@S@DeletedMethods
 // CHECK: [[@LINE-3]]:24 | struct/C++ | DeletedMethods | c:@S@DeletedMethods |  | Ref,RelCont | rel: 1
-// CHECK: [[@LINE-4]]:3 | struct/C++ | DeletedMethods | c:@S@DeletedMethods |  | Ref,RelCont | rel: 1
 };
 
 namespace ns2 {
@@ -494,7 +491,7 @@
 // CHECK: [[@LINE-1]]:69 | variable/C++ | structuredBinding2 | c:@N@cpp17structuredBinding@structuredBinding2 |  | Ref,Read,RelCont | rel: 1
 // CHECK-NEXT: RelCont | localStructuredBindingAndRef | c:@N@cpp17structuredBinding@F@localStructuredBindingAndRef#
 // CHECK-NOT: localBinding
-// LOCAL: [[@LINE-4]]:9 | variable(local)/C++ | localBinding1 | c:index-source.cpp@25408@N@cpp17structuredBinding@F@localStructuredBindingAndRef#@localBinding1
+// LOCAL: [[@LINE-4]]:9 | variable(local)/C++ | localBinding1 | c:index-source.cpp@24750@N@cpp17structuredBinding@F@localStructuredBindingAndRef#@localBinding1
 }
 
 }
Index: lib/Index/IndexDecl.cpp
===
--- lib/Index/IndexDecl.cpp
+++ lib/Index/IndexDecl.cpp
@@ -246,9 +246,6 @@
 handleDeclarator(D);
 
 if (const CXXConstructorDecl *Ctor = dyn_cast(D)) {
-  IndexCtx.handleReference(Ctor->getParent(), Ctor->getLocation(),
-   Ctor->getParent(), Ctor->getDeclContext());
-
   // Constructor initializers.
   for (const auto *Init : Ctor->inits()) {
 if (Init->isWritten()) {
@@ -259,12 +256,6 @@
   IndexCtx.indexBody(Init->getInit(), D, D);
 }
   }
-} else if (

[PATCH] D58811: [clang] Fix misuses of char width to char align

2019-03-01 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D58811#1414784 , @amalykh wrote:

> Currently getCharWidth and getCharAlign functions are hard coded to return 8 
> in clang with no way to change it for target.
>  This can be seen in TargetInfo.h file:
>
>   unsigned getCharWidth() const { return 8; } // FIXME
>   unsigned getCharAlign() const { return 8; } // FIXME
>   
>
> It means that these functions can be used interchangeably and there will be 
> no test failures because of this, until custom alignment will be supported.
>  Nevertheless, it will not be possible to support custom alignment until all 
> incorrect usages of getCharWidth will be replaced with getCharAlign. This 
> patch fixes some of them


Likewise, LLVM hardcodes that byte is 8 bits and does not want to change that
since there is no official LLVM target with that characteristics,
and thus it is impossible to test it, and it would quickly regress.

Which target will be affected by this patch?
I suspect the situation is the same here.
If there is no way to test this upstream...


Repository:
  rC Clang

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

https://reviews.llvm.org/D58811



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


[PATCH] D58814: [clang][Index] Constructors and Destructors do not reference class

2019-03-01 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr accepted this revision.
gribozavr added a comment.
This revision is now accepted and ready to land.

Please also add a test for find references on a constructor.


Repository:
  rC Clang

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

https://reviews.llvm.org/D58814



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


[PATCH] D58815: [clangd] Make sure constructors do not reference class

2019-03-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: gribozavr.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, ioeric, 
ilya-biryukov.
Herald added a project: clang.
kadircet added a parent revision: D58814: [clang][Index] Constructors and 
Destructors do not reference class.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D58815

Files:
  unittests/clangd/XRefsTests.cpp


Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -1350,6 +1350,15 @@
 } // namespace ns
 int main() { [[^ns]]::Foo foo; }
   )cpp",
+
+  R"cpp(// Constructor
+struct Foo {
+  [[F^oo]](int);
+};
+void foo() {
+  Foo f = [[Foo]](42);
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);


Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -1350,6 +1350,15 @@
 } // namespace ns
 int main() { [[^ns]]::Foo foo; }
   )cpp",
+
+  R"cpp(// Constructor
+struct Foo {
+  [[F^oo]](int);
+};
+void foo() {
+  Foo f = [[Foo]](42);
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58815: [clangd] Make sure constructors do not reference class

2019-03-01 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr accepted this revision.
gribozavr added inline comments.
This revision is now accepted and ready to land.



Comment at: unittests/clangd/XRefsTests.cpp:1361
+}
+  )cpp",
   };

Add the new test right after the "Method call" test, to keep it grouped?  
Constructor calls are kinda like method calls.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58815



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


[PATCH] D57986: [ProfileData] Sort FuncData before iteration to remove non-determinism

2019-03-01 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

I think this patch is right in also sorting the function names: AFAICS 
`StringMap` doesn't provide that guarantee.




Comment at: lib/ProfileData/InstrProfWriter.cpp:393-403
+  llvm::sort(OrderedFuncData, [](const RecordType &A, const RecordType &B) {
+ auto nameA = A.first;
+ auto nameB = B.first;
+ int comp = nameA.compare(nameB);
+ if (comp)
+   return comp < 0;
+

Please run `clang-format`, the lambda should only be indented by two additional 
spaces. Also can you put the explicit types for `nameA` et al.? That should be 
`StringRef` and `uint64_t` for the hashes.


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

https://reviews.llvm.org/D57986



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


[PATCH] D58216: Support attribute used in member funcs of class templates II

2019-03-01 Thread Brian Gesiak via Phabricator via cfe-commits
modocache added a comment.

Friendly ping! @aaron.ballman it looks like you accepted D56928 
, could you take a look at this as well?


Repository:
  rC Clang

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

https://reviews.llvm.org/D58216



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


[PATCH] D58815: [clangd] Make sure constructors do not reference class

2019-03-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 188878.
kadircet marked an inline comment as done.
kadircet added a comment.

Re-arrange test location


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58815

Files:
  unittests/clangd/XRefsTests.cpp


Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -1337,6 +1337,15 @@
 }
   )cpp",
 
+  R"cpp(// Constructor
+struct Foo {
+  [[F^oo]](int);
+};
+void foo() {
+  Foo f = [[Foo]](42);
+}
+  )cpp",
+
   R"cpp(// Typedef
 typedef int [[Foo]];
 int main() {


Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -1337,6 +1337,15 @@
 }
   )cpp",
 
+  R"cpp(// Constructor
+struct Foo {
+  [[F^oo]](int);
+};
+void foo() {
+  Foo f = [[Foo]](42);
+}
+  )cpp",
+
   R"cpp(// Typedef
 typedef int [[Foo]];
 int main() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk created this revision.
lewmpk added reviewers: hokein, aaron.ballman, alexfh, JonasToth.
Herald added subscribers: cfe-commits, jdoerfert, kbarton, xazax.hun, mgorny, 
nemanjai.
Herald added a project: clang.
lewmpk added a subscriber: clang-tools-extra.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D58818

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp

Index: test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-use-raii-locks %t
+
+// Mock implementation of std::mutex
+namespace std {
+struct mutex {
+void lock();
+void unlock();
+};
+}
+
+void warn_me() {
+std::mutex m;
+m.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+m.unlock();
+}
+
+void ignore_me1() {
+std::mutex m;
+m.unlock();
+m.lock();
+// CHECK-MESSAGES-NOT: warning:
+}
+
+void ignore_me2() {
+std::mutex m1;
+std::mutex m2;
+m1.lock();
+m2.unlock();
+// CHECK-MESSAGES-NOT: warning:
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   cppcoreguidelines-use-raii-locks
fuchsia-default-arguments
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
fuchsia-multiple-inheritance
Index: docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
@@ -0,0 +1,8 @@
+.. title:: clang-tidy - cppcoreguidelines-use-raii-locks
+
+cppcoreguidelines-use-raii-locks
+
+
+The explicit use of std::mutex functions ``lock()`` and ``unlock()`` is error 
+prone and should be avoided. It's recommended to use RAII-style locking 
+mechanisms such as ``std::lock_guard`` or ``std::unique_lock``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -91,6 +91,11 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`cppcoreguidelines-use-raii-locks
+  ` check.
+
+  Checks for explicit usage of ``std::mutex`` functions ``lock()`` and ``unlock``.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   `
   check.
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
@@ -0,0 +1,34 @@
+//===--- UseRaiiLocksCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USERAIILOCKSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USERAIILOCKSCHECK_H
+
+#include "../ClangTidy.h"
+#include 
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+/// Check for instances of explicit std::mutex lock() and unlock() calls
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-use-raii-locks.html
+class UseRaiiLocksCheck : public ClangTidyCheck {
+public:
+  UseRaiiLocksCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USERAIILOCKSCHECK_H
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
@@ -0,0 +1,84 @@
+//===--- UseRaiiLocksCheck.cpp - clang-tidy ---===//
+//
+// Part of the LLVM Proj

[PATCH] D58819: [clang-format] clang-format off/on not respected when using C Style comments

2019-03-01 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: djasper, klimek, JonasToth, krasimir.
MyDeveloperDay added projects: clang, clang-tools-extra.

If the clang-format on/off is in a /* comment */ then the sorting of headers is 
not ignored

PR40901 - https://bugs.llvm.org/show_bug.cgi?id=40901


https://reviews.llvm.org/D58819

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/SortIncludesTest.cpp


Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -117,6 +117,25 @@
  "// clang-format on\n"));
 }
 
+TEST_F(SortIncludesTest, SupportClangFormatOffCStyle) {
+  EXPECT_EQ("#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format off */\n"
+"#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format on */\n",
+sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format off */\n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format on */\n"));
+}
+
 TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) {
   FmtStyle.SortIncludes = false;
   EXPECT_EQ("#include \"a.h\"\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1786,9 +1786,11 @@
 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
 
 StringRef Trimmed = Line.trim();
-if (Trimmed == "// clang-format off")
+if (Trimmed == "// clang-format off" ||
+Trimmed.startswith("/* clang-format off"))
   FormattingOff = true;
-else if (Trimmed == "// clang-format on")
+else if (Trimmed == "// clang-format on" ||
+ Trimmed.startswith("/* clang-format on"))
   FormattingOff = false;
 
 const bool EmptyLineSkipped =


Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -117,6 +117,25 @@
  "// clang-format on\n"));
 }
 
+TEST_F(SortIncludesTest, SupportClangFormatOffCStyle) {
+  EXPECT_EQ("#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format off */\n"
+"#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format on */\n",
+sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format off */\n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format on */\n"));
+}
+
 TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) {
   FmtStyle.SortIncludes = false;
   EXPECT_EQ("#include \"a.h\"\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1786,9 +1786,11 @@
 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
 
 StringRef Trimmed = Line.trim();
-if (Trimmed == "// clang-format off")
+if (Trimmed == "// clang-format off" ||
+Trimmed.startswith("/* clang-format off"))
   FormattingOff = true;
-else if (Trimmed == "// clang-format on")
+else if (Trimmed == "// clang-format on" ||
+ Trimmed.startswith("/* clang-format on"))
   FormattingOff = false;
 
 const bool EmptyLineSkipped =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58675: [clang] Adds `-ftime-trace` option to clang that produces Chrome `chrome://tracing` compatible JSON profiling output dumps

2019-03-01 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev updated this revision to Diff 11.

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

https://reviews.llvm.org/D58675

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParseAST.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Serialization/GlobalModuleIndex.cpp
  clang/tools/driver/cc1_main.cpp
  llvm/lib/IR/LegacyPassManager.cpp
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/TimeProfiler.cpp
  llvm/lib/Support/TimeProfiler.h

Index: llvm/lib/Support/TimeProfiler.h
===
--- /dev/null
+++ llvm/lib/Support/TimeProfiler.h
@@ -0,0 +1,71 @@
+//===- llvm/Support/TimeProfiler.h - Hierarchical Time Profiler -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_SUPPORT_TIME_PROFILER_H
+#define LLVM_SUPPORT_TIME_PROFILER_H
+
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvm {
+
+struct TimeTraceProfiler;
+extern TimeTraceProfiler *TimeTraceProfilerInstance;
+
+/// Initialize the time trace profiler.
+/// This sets up the global \p TimeTraceProfilerInstance
+/// variable to be the profiler instance.
+void TimeTraceProfilerInitialize();
+
+/// Cleanup the time trace profiler, if it was initialized.
+void TimeTraceProfilerCleanup();
+
+/// Is the time trace profiler enabled, i.e. initialized?
+inline bool TimeTraceProfilerEnabled() {
+  return TimeTraceProfilerInstance != nullptr;
+}
+
+/// Write profiling data to output file.
+/// Data produced is JSON, in Chrome "Trace Event" format, see
+/// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
+void TimeTraceProfilerWrite(std::unique_ptr &OS);
+
+/// Manually begin a time section, with the given \p name and \p detail.
+/// Profiler copies the string data, so the pointers can be given into
+/// temporaries. Time sections can be hierarchical; every Begin must have a
+/// matching End pair but they can nest.
+void TimeTraceProfilerBegin(const char *name, const char *detail);
+
+/// Manually end the last time section.
+void TimeTraceProfilerEnd();
+
+/// The TimeTraceScope is a helper class to call the begin and end functions.
+/// of the time trace profiler.  When the object is constructed, it
+/// begins the section; and wen it is destroyed, it stops
+/// it.  If the time profiler is not initialized, the overhead
+/// is a single branch.
+struct TimeTraceScope {
+  TimeTraceScope(const char *name, const char *detail) {
+if (TimeTraceProfilerInstance != nullptr)
+  TimeTraceProfilerBegin(name, detail);
+  }
+  ~TimeTraceScope() {
+if (TimeTraceProfilerInstance != nullptr)
+  TimeTraceProfilerEnd();
+  }
+};
+
+/// Evaluates expression if time trace profiler is enabled, or passed null when
+/// it is not. Useful to avoid possibly expensive work in creating a string for
+/// profiling, when profiler is not enabled at all.
+#define TIME_TRACE_OR_NULL(expr)   \
+  (llvm::TimeTraceProfilerInstance != nullptr ? (expr) : nullptr)
+
+} // end namespace llvm
+
+#endif
Index: llvm/lib/Support/TimeProfiler.cpp
===
--- /dev/null
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -0,0 +1,178 @@
+//===-- TimeProfiler.cpp - Hierarchical Time Profiler -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+/// \file Hierarchical time profiler implementation.
+//
+//===--===//
+
+#include "llvm/Support/TimeProfiler.h"
+#include "llvm/Support/FileSystem.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace std::chrono;
+
+namespace llvm {
+
+TimeTraceProfiler *TimeTraceProfilerInstance = nullptr;
+
+static std::string EscapeString(const char *src) {
+  std::string os;
+  while (*src) {
+char c = *src;
+switch (c) {
+case '"':
+case '\\':
+case '\b':
+case '\f':
+case '\n':
+case '\r':
+case '\t':
+  os += '\\';
+  os += c;
+  break;
+default:
+  if (c >= 32 && c < 126) {
+os

[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp:47
+"cppcoreguidelines-use-raii-locks");
 CheckFactories.registerCheck(
 "cppcoreguidelines-avoid-c-arrays");

Nit: by and large this list looks to be in alphabetical based on the checker 
name (except the last one), not sure if thats by accident or design


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818



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


[PATCH] D58724: [gnustep-objc] Make the GNUstep v2 ABI work for Windows DLLs.

2019-03-01 Thread David Chisnall via Phabricator via cfe-commits
theraven updated this revision to Diff 15.
theraven marked an inline comment as done.
theraven added a comment.

- Address Dustin's review comments.
- [objc-gnustep] Use $ in symbol names on Windows.
- Add fix from Dustin.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58724

Files:
  clang/lib/CodeGen/CGObjCGNU.cpp

Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -185,12 +185,16 @@
   (R.getVersion() >= VersionTuple(major, minor));
   }
 
+  Twine ManglePublicSymbol(StringRef Name) {
+return StringRef(CGM.getTriple().isOSBinFormatCOFF() ? "$_" : "._") + Name;
+  }
+
   std::string SymbolForProtocol(StringRef Name) {
-return (StringRef("._OBJC_PROTOCOL_") + Name).str();
+return (ManglePublicSymbol("OBJC_PROTOCOL_") + Name).str();
   }
 
   std::string SymbolForProtocolRef(StringRef Name) {
-return (StringRef("._OBJC_REF_PROTOCOL_") + Name).str();
+return (ManglePublicSymbol("OBJC_REF_PROTOCOL_") + Name).str();
   }
 
 
@@ -906,12 +910,15 @@
 ConstantStringSection
   };
   static const char *const SectionsBaseNames[8];
+  static const char *const PECOFFSectionsBaseNames[8];
   template
   std::string sectionName() {
-std::string name(SectionsBaseNames[K]);
-if (CGM.getTriple().isOSBinFormatCOFF())
+if (CGM.getTriple().isOSBinFormatCOFF()) {
+  std::string name(PECOFFSectionsBaseNames[K]);
   name += "$m";
-return name;
+  return name;
+}
+return SectionsBaseNames[K];
   }
   /// The GCC ABI superclass message lookup function.  Takes a pointer to a
   /// structure describing the receiver and the class, and a selector as
@@ -932,15 +939,19 @@
   bool EmittedClass = false;
   /// Generate the name of a symbol for a reference to a class.  Accesses to
   /// classes should be indirected via this.
+
+  typedef std::pair> EarlyInitPair;
+  std::vector EarlyInitList;
+
   std::string SymbolForClassRef(StringRef Name, bool isWeak) {
 if (isWeak)
-  return (StringRef("._OBJC_WEAK_REF_CLASS_") + Name).str();
+  return (ManglePublicSymbol("OBJC_WEAK_REF_CLASS_") + Name).str();
 else
-  return (StringRef("._OBJC_REF_CLASS_") + Name).str();
+  return (ManglePublicSymbol("OBJC_REF_CLASS_") + Name).str();
   }
   /// Generate the name of a class symbol.
   std::string SymbolForClass(StringRef Name) {
-return (StringRef("._OBJC_CLASS_") + Name).str();
+return (ManglePublicSymbol("OBJC_CLASS_") + Name).str();
   }
   void CallRuntimeFunction(CGBuilderTy &B, StringRef FunctionName,
   ArrayRef Args) {
@@ -994,10 +1005,13 @@
 
 llvm::Constant *isa = TheModule.getNamedGlobal(Sym);
 
-if (!isa)
+if (!isa) {
   isa = new llvm::GlobalVariable(TheModule, IdTy, /* isConstant */false,
   llvm::GlobalValue::ExternalLinkage, nullptr, Sym);
-else if (isa->getType() != PtrToIdTy)
+  if (CGM.getTriple().isOSBinFormatCOFF()) {
+cast(isa)->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+  }
+} else if (isa->getType() != PtrToIdTy)
   isa = llvm::ConstantExpr::getBitCast(isa, PtrToIdTy);
 
 //  struct
@@ -1012,7 +1026,11 @@
 
 ConstantInitBuilder Builder(CGM);
 auto Fields = Builder.beginStruct();
-Fields.add(isa);
+if (!CGM.getTriple().isOSBinFormatCOFF()) {
+  Fields.add(isa);
+} else {
+  Fields.addNullPointer(PtrTy);
+}
 // For now, all non-ASCII strings are represented as UTF-16.  As such, the
 // number of bytes is simply double the number of UTF-16 codepoints.  In
 // ASCII strings, the number of bytes is equal to the number of non-ASCII
@@ -1083,6 +1101,10 @@
   ObjCStrGV->setComdat(TheModule.getOrInsertComdat(StringName));
   ObjCStrGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
 }
+if (CGM.getTriple().isOSBinFormatCOFF()) {
+  std::pair v{ObjCStrGV, 0};
+  EarlyInitList.emplace_back(Sym, v);
+}
 llvm::Constant *ObjCStr = llvm::ConstantExpr::getBitCast(ObjCStrGV, IdTy);
 ObjCStrings[Str] = ObjCStr;
 ConstantStrings.push_back(ObjCStr);
@@ -1196,6 +1218,33 @@
   ClassSymbol->setInitializer(new llvm::GlobalVariable(TheModule,
   Int8Ty, false, llvm::GlobalValue::ExternalWeakLinkage,
   nullptr, SymbolForClass(Name)));
+else {
+  if (CGM.getTriple().isOSBinFormatCOFF()) {
+IdentifierInfo &II = CGM.getContext().Idents.get(Name);
+TranslationUnitDecl *TUDecl = CGM.getContext().getTranslationUnitDecl();
+DeclContext *DC = TranslationUnitDecl::castToDeclContext(TUDecl);
+
+const ObjCInterfaceDecl *OID = nullptr;
+for (const auto &Result : DC->lookup(&II))
+  if ((OID = dyn_cast(Result)))
+break;
+
+// The first Interface we find may be a @class,
+// which

[PATCH] D58821: Inline asm constraints: allow ICE-like pointers for the "n" constraint (PR40890)

2019-03-01 Thread Hans Wennborg via Phabricator via cfe-commits
hans created this revision.
hans added reviewers: efriedma, rnk, rsmith, void.
Herald added subscribers: jdoerfert, eraman.

Apparently GCC allows this, and there's code relying on it (see bug, which is a 
release blocker for llvm 8).

The idea is to allow expression that would have been allowed if they were cast 
to int. So I based the code on how such a cast would be done (the 
CK_PointerToIntegral case in IntExprEvaluator::VisitCastExpr()).

I'm unfamiliar with this code, especially the LValue variant of APValue, so 
please take a careful look.


https://reviews.llvm.org/D58821

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/test/CodeGen/x86-64-inline-asm.c
  clang/test/Sema/inline-asm-validate-x86.c

Index: clang/test/Sema/inline-asm-validate-x86.c
===
--- clang/test/Sema/inline-asm-validate-x86.c
+++ clang/test/Sema/inline-asm-validate-x86.c
@@ -137,3 +137,15 @@
   : "0"(i), "O"(64)); // expected-no-error
 }
 
+void pr40890(void) {
+  struct s {
+int a, b;
+  };
+  static struct s s;
+  // This null pointer can be used as an integer constant expression.
+  __asm__ __volatile__("\n#define S_A abcd%0\n" : : "n"(&((struct s*)0)->a));
+  // This offset-from-null pointer can be used as an integer constant expression.
+  __asm__ __volatile__("\n#define S_B abcd%0\n" : : "n"(&((struct s*)0)->b));
+  // This pointer cannot be used as an integer constant expression.
+  __asm__ __volatile__("\n#define GLOBAL_A abcd%0\n" : : "n"(&s.a)); // expected-error{{constraint 'n' expects an integer constant expression}}
+}
Index: clang/test/CodeGen/x86-64-inline-asm.c
===
--- clang/test/CodeGen/x86-64-inline-asm.c
+++ clang/test/CodeGen/x86-64-inline-asm.c
@@ -1,6 +1,7 @@
 // REQUIRES: x86-registered-target
 // RUN: %clang_cc1 -triple x86_64 %s -S -o /dev/null -DWARN -verify
 // RUN: %clang_cc1 -triple x86_64 %s -S -o /dev/null -Werror -verify
+// RUN: %clang_cc1 -triple x86_64-linux-gnu %s -S -o - | FileCheck %s
 void f() {
   asm("movaps %xmm3, (%esi, 2)");
 // expected-note@1 {{instantiated into assembly here}}
@@ -15,3 +16,15 @@
 void g(void) { asm volatile("movd %%xmm0, %0"
 :
 : "m"(var)); }
+
+void pr40890(void) {
+  struct s {
+int a, b;
+  } s;
+  __asm__ __volatile__("\n#define S_A abcd%0\n" : : "n"(&((struct s*)0)->a));
+  __asm__ __volatile__("\n#define S_B abcd%0\n" : : "n"(&((struct s*)0)->b));
+
+// CHECK-LABEL: pr40890
+// CHECK: #define S_A abcd$0
+// CHECK: #define S_B abcd$4
+}
Index: clang/lib/Sema/SemaStmtAsm.cpp
===
--- clang/lib/Sema/SemaStmtAsm.cpp
+++ clang/lib/Sema/SemaStmtAsm.cpp
@@ -385,11 +385,27 @@
   return StmtError(
   Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
   << Info.getConstraintStr() << InputExpr->getSourceRange());
-llvm::APSInt Result = EVResult.Val.getInt();
-if (!Info.isValidAsmImmediate(Result))
+
+// For compatibility with GCC, we also allows pointers that would be
+// integral constant expressions if they were cast to int.
+llvm::APSInt IntResult;
+if (EVResult.Val.isInt())
+  IntResult = EVResult.Val.getInt();
+else if (EVResult.Val.isNullPointer())
+  IntResult = llvm::APSInt::get(
+  Context.getTargetNullPointerValue(InputExpr->getType()));
+else if (EVResult.Val.isLValue() && !EVResult.Val.getLValueBase())
+  IntResult =
+  llvm::APSInt::get(EVResult.Val.getLValueOffset().getQuantity());
+else
+  return StmtError(
+  Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
+  << Info.getConstraintStr() << InputExpr->getSourceRange());
+
+if (!Info.isValidAsmImmediate(IntResult))
   return StmtError(Diag(InputExpr->getBeginLoc(),
 diag::err_invalid_asm_value_for_constraint)
-   << Result.toString(10) << Info.getConstraintStr()
+   << IntResult.toString(10) << Info.getConstraintStr()
<< InputExpr->getSourceRange());
   }
 
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -1838,8 +1838,22 @@
   // (immediate or symbolic), try to emit it as such.
   if (!Info.allowsRegister() && !Info.allowsMemory()) {
 if (Info.requiresImmediateConstant()) {
-  llvm::APSInt AsmConst = InputExpr->EvaluateKnownConstInt(getContext());
-  return llvm::ConstantInt::get(getLLVMContext(), AsmConst);
+  Expr::EvalResult EVResult;
+  InputExpr->EvaluateAsRValue(EVResult, getContext(), true);
+
+  llvm::APSInt IntResult;
+  if

[PATCH] D58819: [clang-format] clang-format off/on not respected when using C Style comments

2019-03-01 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang/unittests/Format/SortIncludesTest.cpp:132
+ "#include \n"
+ "/* clang-format off */\n"
+ "#include \n"

Add a test with `/* clang-format officially supports C++ */` ;)

Seriously speaking, the `startswith()` condition in the code should be a bit 
stricter. Maybe just compare with `/* clang-format off */` and `/* clang-format 
on */`? If there's a motivating use case for just checking the prefix, could 
you add it to the test?


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

https://reviews.llvm.org/D58819



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


[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk updated this revision to Diff 188893.
lewmpk added a comment.

fixed ordering of cppcoreguidelines module checks


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp

Index: test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-use-raii-locks %t
+
+// Mock implementation of std::mutex
+namespace std {
+struct mutex {
+void lock();
+void unlock();
+};
+}
+
+void warn_me() {
+std::mutex m;
+m.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+m.unlock();
+}
+
+void ignore_me1() {
+std::mutex m;
+m.unlock();
+m.lock();
+// CHECK-MESSAGES-NOT: warning:
+}
+
+void ignore_me2() {
+std::mutex m1;
+std::mutex m2;
+m1.lock();
+m2.unlock();
+// CHECK-MESSAGES-NOT: warning:
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   cppcoreguidelines-use-raii-locks
fuchsia-default-arguments
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
fuchsia-multiple-inheritance
Index: docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
@@ -0,0 +1,8 @@
+.. title:: clang-tidy - cppcoreguidelines-use-raii-locks
+
+cppcoreguidelines-use-raii-locks
+
+
+The explicit use of std::mutex functions ``lock()`` and ``unlock()`` is error 
+prone and should be avoided. It's recommended to use RAII-style locking 
+mechanisms such as ``std::lock_guard`` or ``std::unique_lock``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -91,6 +91,11 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`cppcoreguidelines-use-raii-locks
+  ` check.
+
+  Checks for explicit usage of ``std::mutex`` functions ``lock()`` and ``unlock``.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   `
   check.
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
@@ -0,0 +1,34 @@
+//===--- UseRaiiLocksCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USERAIILOCKSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USERAIILOCKSCHECK_H
+
+#include "../ClangTidy.h"
+#include 
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+/// Check for instances of explicit std::mutex lock() and unlock() calls
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-use-raii-locks.html
+class UseRaiiLocksCheck : public ClangTidyCheck {
+public:
+  UseRaiiLocksCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USERAIILOCKSCHECK_H
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
@@ -0,0 +1,84 @@
+//===--- UseRaiiLocksCheck.cpp - clang-tidy ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://ll

[clang-tools-extra] r355200 - [clangd] Enable SuggestMissingIncludes by default.

2019-03-01 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Fri Mar  1 06:17:55 2019
New Revision: 355200

URL: http://llvm.org/viewvc/llvm-project?rev=355200&view=rev
Log:
[clangd] Enable SuggestMissingIncludes by default.

Summary: This seems to work stably now. Turn on by default.

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=355200&r1=355199&r2=355200&view=diff
==
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Fri Mar  1 06:17:55 2019
@@ -217,7 +217,7 @@ static llvm::cl::opt SuggestMissin
 "suggest-missing-includes",
 llvm::cl::desc("Attempts to fix diagnostic errors caused by missing "
"includes using index."),
-llvm::cl::init(false));
+llvm::cl::init(true));
 
 namespace {
 


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


[PATCH] D58772: [clangd] Enable SuggestMissingIncludes by default.

2019-03-01 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE355200: [clangd] Enable SuggestMissingIncludes by default. 
(authored by ioeric, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D58772?vs=188701&id=188894#toc

Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58772

Files:
  clangd/tool/ClangdMain.cpp


Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -217,7 +217,7 @@
 "suggest-missing-includes",
 llvm::cl::desc("Attempts to fix diagnostic errors caused by missing "
"includes using index."),
-llvm::cl::init(false));
+llvm::cl::init(true));
 
 namespace {
 


Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -217,7 +217,7 @@
 "suggest-missing-includes",
 llvm::cl::desc("Attempts to fix diagnostic errors caused by missing "
"includes using index."),
-llvm::cl::init(false));
+llvm::cl::init(true));
 
 namespace {
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

This looks good to me but I would wait for one of @JonasToth or @alexfh to 
perhaps take a look,

maybe you should add some nested scope example too using the same name, I know 
the compiler should warn about a shadow variable anyway but

  std::mutex m;
  m.lock();
  {
  std::mutex m;
  m.lock();
  m.unlock();
  }
  m_unlock();

and what about

  std::mutex m1;
  std::mutex m2;
  
  m1.lock();
  m1.unlock();
  m2.lock();
  m2.unlock();

and

  std::mutex m1;
  std::mutex m2;
  
  m1.lock();
  m2.lock();
  m2.unlock();
  m1.unlock();



  std::mutex m1;
  std::mutex m2;
  
  m1.lock();
  m1.unlock();
  m2.lock();
  m2.unlock();



  std::mutex m1;
  std::mutex m2;
  
  m1.lock();
  m2.lock();
  m1.unlock();
  m2.unlock();


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818



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


[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk added a comment.

I'll improve the tests :)


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818



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


[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

+1 i was just going to comment - this needs **much** more tests.
Also, it would be really great if you could supply the differential's 
description.T




Comment at: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp:25
+  const auto MutexDecl = type(hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(cxxRecordDecl(hasName("::std::mutex"));
+  // Match expressions of type mutex or mutex pointer

This should be a config param



Comment at: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp:26
+  recordType(hasDeclaration(cxxRecordDecl(hasName("::std::mutex"));
+  // Match expressions of type mutex or mutex pointer
+  const auto MutexExpr =

Terminology: *this* doesn't match anything.
It's a matcher, yes, but it's just a lambda.
The actual match happens at the end.



Comment at: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h:13-14
+#include "../ClangTidy.h"
+#include 
+namespace clang {
+namespace tidy {

Separate with newline


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818



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


[PATCH] D58827: [Sema][NFCI] Don't heap-allocate the various CorrectionCandidateCallback unless we are going to do some typo correction

2019-03-01 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno created this revision.
riccibruno added reviewers: aaron.ballman, rnk, erik.pilkington.
riccibruno added a project: clang.
Herald added a subscriber: cfe-commits.

The various `CorrectionCandidateCallback`s are currently heap-allocated 
unconditionally. This was needed because of delayed typo correction. However 
these allocations represent currently 15.4% of all allocations (number of 
allocations) when parsing all of Boost (!), mostly because of 
`ParseCastExpression`, `ParseStatementOrDeclarationAfterAttrtibutes` and 
`isCXXDeclarationSpecifier`. Note that all of these callback objects are small. 
Let's not do this.

Instead initially allocate the callback on the stack, and only do a heap 
allocation if we are going to do some typo correction. Do this by:

1. Adding a `clone` function to each callback, which will do a polymorphic 
clone of the callback. This clone function is required to be implemented by 
every callback (of which there is a fair amount). Make sure this is the case by 
making it pure virtual.
2. Use this `clone` function when we are going to try to correct a typo.

This additionally cut the time of `-fsyntax-only` on all of Boost by 0.5% (not 
that much, but still something). No functional changes intended.


Repository:
  rC Clang

https://reviews.llvm.org/D58827

Files:
  include/clang/Parse/Parser.h
  include/clang/Sema/Sema.h
  include/clang/Sema/TypoCorrection.h
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/ParseStmt.cpp
  lib/Parse/ParseTentative.cpp
  lib/Parse/Parser.cpp
  lib/Sema/SemaCXXScopeSpec.cpp
  lib/Sema/SemaCodeComplete.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaDeclObjC.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprMember.cpp
  lib/Sema/SemaExprObjC.cpp
  lib/Sema/SemaInit.cpp
  lib/Sema/SemaLambda.cpp
  lib/Sema/SemaLookup.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateVariadic.cpp
  lib/Sema/SemaType.cpp

Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -5908,7 +5908,8 @@
   id.setIdentifier(Attr.getArgAsIdent(0)->Ident, Attr.getLoc());
 
   ExprResult AddrSpace = S.ActOnIdExpression(
-  S.getCurScope(), SS, TemplateKWLoc, id, false, false);
+  S.getCurScope(), SS, TemplateKWLoc, id, /*HasTrailingLParen=*/false,
+  /*IsAddressOfOperand=*/false);
   if (AddrSpace.isInvalid())
 return;
 
@@ -7040,7 +7041,8 @@
 Id.setIdentifier(Attr.getArgAsIdent(0)->Ident, Attr.getLoc());
 
 ExprResult Size = S.ActOnIdExpression(S.getCurScope(), SS, TemplateKWLoc,
-  Id, false, false);
+  Id, /*HasTrailingLParen=*/false,
+  /*IsAddressOfOperand=*/false);
 
 if (Size.isInvalid())
   return;
@@ -7077,7 +7079,8 @@
 id.setIdentifier(Attr.getArgAsIdent(0)->Ident, Attr.getLoc());
 
 ExprResult Size = S.ActOnIdExpression(S.getCurScope(), SS, TemplateKWLoc,
-  id, false, false);
+  id, /*HasTrailingLParen=*/false,
+  /*IsAddressOfOperand=*/false);
 if (Size.isInvalid())
   return;
 
Index: lib/Sema/SemaTemplateVariadic.cpp
===
--- lib/Sema/SemaTemplateVariadic.cpp
+++ lib/Sema/SemaTemplateVariadic.cpp
@@ -924,12 +924,16 @@
 namespace {
 
 // Callback to only accept typo corrections that refer to parameter packs.
-class ParameterPackValidatorCCC : public CorrectionCandidateCallback {
+class ParameterPackValidatorCCC final : public CorrectionCandidateCallback {
  public:
   bool ValidateCandidate(const TypoCorrection &candidate) override {
 NamedDecl *ND = candidate.getCorrectionDecl();
 return ND && ND->isParameterPack();
   }
+
+  std::unique_ptr clone() override {
+return llvm::make_unique(*this);
+  }
 };
 
 }
@@ -965,18 +969,18 @@
 break;
 
   case LookupResult::NotFound:
-  case LookupResult::NotFoundInCurrentInstantiation:
+  case LookupResult::NotFoundInCurrentInstantiation: {
+ParameterPackValidatorCCC CCC{};
 if (TypoCorrection Corrected =
 CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, nullptr,
-llvm::make_unique(),
-CTK_ErrorRecovery)) {
+CCC, CTK_ErrorRecovery)) {
   diagnoseTypo(Corrected,
PDiag(diag::err_sizeof_pack_no_pack_name_suggest) << &Name,
PDiag(diag::note_parameter_pack_here));
   ParameterPack = Corrected.getCorrectionDecl();
 }
 break;
-
+  }
   case LookupResult::FoundOverloaded:
   case LookupResult::FoundUnresolvedValue:
 break;
Index: lib/Sema/SemaTemplate.cpp
===

[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk updated this revision to Diff 188901.
lewmpk added a comment.

removed unneccesary include


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp

Index: test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
@@ -0,0 +1,80 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-use-raii-locks %t
+
+// Mock implementation of std::mutex
+namespace std {
+struct mutex {
+  void lock();
+  void unlock();
+};
+} // namespace std
+
+void warn_me1() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m.unlock();
+}
+
+void warn_me2() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  {
+std::mutex m;
+m.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+m.unlock();
+  }
+  m.unlock();
+}
+
+void warn_me3() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me4() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me5() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.unlock();
+}
+
+void ignore_me1() {
+  std::mutex m;
+  m.unlock();
+  m.lock();
+  // CHECK-MESSAGES-NOT: warning:
+}
+
+void ignore_me2() {
+  std::mutex m1;
+  std::mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   cppcoreguidelines-use-raii-locks
fuchsia-default-arguments
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
fuchsia-multiple-inheritance
Index: docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
@@ -0,0 +1,8 @@
+.. title:: clang-tidy - cppcoreguidelines-use-raii-locks
+
+cppcoreguidelines-use-raii-locks
+
+
+The explicit use of std::mutex functions ``lock()`` and ``unlock()`` is error 
+prone and should be avoided. It's recommended to use RAII-style locking 
+mechanisms such as ``std::lock_guard`` or ``std::unique_lock``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -91,6 +91,11 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`cppcoreguidelines-use-raii-locks
+  ` check.
+
+  Checks for explicit usage of ``std::mutex`` functions ``lock()`` and ``unlock``.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   `
   check.
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
@@ -0,0 +1,34 @@
+//===--- UseRaiiLocksCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USERAIILOCKSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USERAIILOCKSCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+/// Check for instances of explicit std::mutex lock() and unlock() calls
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-use-raii-lock

[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk updated this revision to Diff 188900.
lewmpk added a comment.

fixed nested use case


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp

Index: test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
@@ -0,0 +1,80 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-use-raii-locks %t
+
+// Mock implementation of std::mutex
+namespace std {
+struct mutex {
+  void lock();
+  void unlock();
+};
+} // namespace std
+
+void warn_me1() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m.unlock();
+}
+
+void warn_me2() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  {
+std::mutex m;
+m.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+m.unlock();
+  }
+  m.unlock();
+}
+
+void warn_me3() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me4() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me5() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.unlock();
+}
+
+void ignore_me1() {
+  std::mutex m;
+  m.unlock();
+  m.lock();
+  // CHECK-MESSAGES-NOT: warning:
+}
+
+void ignore_me2() {
+  std::mutex m1;
+  std::mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   cppcoreguidelines-use-raii-locks
fuchsia-default-arguments
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
fuchsia-multiple-inheritance
Index: docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
@@ -0,0 +1,8 @@
+.. title:: clang-tidy - cppcoreguidelines-use-raii-locks
+
+cppcoreguidelines-use-raii-locks
+
+
+The explicit use of std::mutex functions ``lock()`` and ``unlock()`` is error 
+prone and should be avoided. It's recommended to use RAII-style locking 
+mechanisms such as ``std::lock_guard`` or ``std::unique_lock``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -91,6 +91,11 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`cppcoreguidelines-use-raii-locks
+  ` check.
+
+  Checks for explicit usage of ``std::mutex`` functions ``lock()`` and ``unlock``.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   `
   check.
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
@@ -0,0 +1,34 @@
+//===--- UseRaiiLocksCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USERAIILOCKSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USERAIILOCKSCHECK_H
+
+#include "../ClangTidy.h"
+#include 
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+/// Check for instances of explicit std::mutex lock() and unlock() calls
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-use-raii-l

[PATCH] D58819: [clang-format] clang-format off/on not respected when using C Style comments

2019-03-01 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay marked an inline comment as done.
MyDeveloperDay added inline comments.



Comment at: clang/unittests/Format/SortIncludesTest.cpp:132
+ "#include \n"
+ "/* clang-format off */\n"
+ "#include \n"

alexfh wrote:
> Add a test with `/* clang-format officially supports C++ */` ;)
> 
> Seriously speaking, the `startswith()` condition in the code should be a bit 
> stricter. Maybe just compare with `/* clang-format off */` and `/* 
> clang-format on */`? If there's a motivating use case for just checking the 
> prefix, could you add it to the test?
You know i thought I was being so clever by not having the space after ..off to 
avoid

```
/*clang-format off*/
```

That'll teach me!


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

https://reviews.llvm.org/D58819



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


[PATCH] D58828: [analyzer] Fix taint propagation in GenericTaintChecker

2019-03-01 Thread Borsik Gábor via Phabricator via cfe-commits
boga95 created this revision.
boga95 added reviewers: gerazo, xazax.hun, Szelethus, a_sidorin, dcoughlin, 
george.karpenkov, NoQ.
boga95 added a project: clang.
Herald added subscribers: cfe-commits, Charusso, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, whisperity.

The `gets` function has no SrcArgs. Because the default value for isTainted was 
false, it didn't mark its DstArgs as tainted.


Repository:
  rC Clang

https://reviews.llvm.org/D58828

Files:
  lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  test/Analysis/taint-generic.c


Index: test/Analysis/taint-generic.c
===
--- test/Analysis/taint-generic.c
+++ test/Analysis/taint-generic.c
@@ -2,6 +2,7 @@
 // RUN: %clang_analyze_cc1  -DFILE_IS_STRUCT 
-analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 
-Wno-format-security -verify %s
 
 int scanf(const char *restrict format, ...);
+char *gets(char *str);
 int getchar(void);
 
 typedef struct _FILE FILE;
@@ -142,6 +143,12 @@
   system(buffern2); // expected-warning {{Untrusted data is passed to a system 
call}}
 }
 
+void testGets() {
+  char str[50];
+  gets(str);
+  system(str); // expected-warning {{Untrusted data is passed to a system 
call}}
+}
+
 void testTaintedBufferSize() {
   size_t ts;
   scanf("%zd", &ts);
Index: lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -458,7 +458,7 @@
   ProgramStateRef State = C.getState();
 
   // Check for taint in arguments.
-  bool IsTainted = false;
+  bool IsTainted = true;
   for (unsigned ArgNum : SrcArgs) {
 if (ArgNum >= CE->getNumArgs())
   return State;


Index: test/Analysis/taint-generic.c
===
--- test/Analysis/taint-generic.c
+++ test/Analysis/taint-generic.c
@@ -2,6 +2,7 @@
 // RUN: %clang_analyze_cc1  -DFILE_IS_STRUCT -analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 -Wno-format-security -verify %s
 
 int scanf(const char *restrict format, ...);
+char *gets(char *str);
 int getchar(void);
 
 typedef struct _FILE FILE;
@@ -142,6 +143,12 @@
   system(buffern2); // expected-warning {{Untrusted data is passed to a system call}}
 }
 
+void testGets() {
+  char str[50];
+  gets(str);
+  system(str); // expected-warning {{Untrusted data is passed to a system call}}
+}
+
 void testTaintedBufferSize() {
   size_t ts;
   scanf("%zd", &ts);
Index: lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -458,7 +458,7 @@
   ProgramStateRef State = C.getState();
 
   // Check for taint in arguments.
-  bool IsTainted = false;
+  bool IsTainted = true;
   for (unsigned ArgNum : SrcArgs) {
 if (ArgNum >= CE->getNumArgs())
   return State;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk updated this revision to Diff 188908.
lewmpk added a comment.

handle other basiclockable types


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp

Index: test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
@@ -0,0 +1,90 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-use-raii-locks %t
+
+// Mock implementation of std::mutex
+namespace std {
+struct mutex {
+  void lock();
+  void unlock();
+};
+typedef mutex recursive_mutex;
+} // namespace std
+
+
+void warn_me1() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m.unlock();
+}
+
+void warn_me2() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  {
+std::mutex m;
+m.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+m.unlock();
+  }
+  m.unlock();
+}
+
+void warn_me3() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me4() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me5() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.unlock();
+}
+
+void ignore_me1() {
+  std::mutex m;
+  m.unlock();
+  m.lock();
+  // CHECK-MESSAGES-NOT: warning:
+}
+
+void ignore_me2() {
+  std::mutex m1;
+  std::mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
+
+void ignore_me3() {
+  std::recursive_mutex m1;
+  std::recursive_mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   cppcoreguidelines-use-raii-locks
fuchsia-default-arguments
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
fuchsia-multiple-inheritance
Index: docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
@@ -0,0 +1,8 @@
+.. title:: clang-tidy - cppcoreguidelines-use-raii-locks
+
+cppcoreguidelines-use-raii-locks
+
+
+The explicit use of std::mutex functions ``lock()`` and ``unlock()`` is error 
+prone and should be avoided. It's recommended to use RAII-style locking 
+mechanisms such as ``std::lock_guard`` or ``std::unique_lock``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -91,6 +91,11 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`cppcoreguidelines-use-raii-locks
+  ` check.
+
+  Checks for explicit usage of ``std::mutex`` functions ``lock()`` and ``unlock``.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   `
   check.
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
@@ -0,0 +1,42 @@
+//===--- UseRaiiLocksCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USERAIILOCKSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USERAIILOCKSCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+/// Check for inst

[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk updated this revision to Diff 188910.
lewmpk added a comment.

renamed option for cppcoreguidelines-use-raii-locks


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp

Index: test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
@@ -0,0 +1,90 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-use-raii-locks %t
+
+// Mock implementation of std::mutex
+namespace std {
+struct mutex {
+  void lock();
+  void unlock();
+};
+typedef mutex recursive_mutex;
+} // namespace std
+
+
+void warn_me1() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m.unlock();
+}
+
+void warn_me2() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  {
+std::mutex m;
+m.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+m.unlock();
+  }
+  m.unlock();
+}
+
+void warn_me3() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me4() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me5() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.unlock();
+}
+
+void ignore_me1() {
+  std::mutex m;
+  m.unlock();
+  m.lock();
+  // CHECK-MESSAGES-NOT: warning:
+}
+
+void ignore_me2() {
+  std::mutex m1;
+  std::mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
+
+void ignore_me3() {
+  std::recursive_mutex m1;
+  std::recursive_mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   cppcoreguidelines-use-raii-locks
fuchsia-default-arguments
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
fuchsia-multiple-inheritance
Index: docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - cppcoreguidelines-use-raii-locks
+
+cppcoreguidelines-use-raii-locks
+
+
+The explicit use of std::mutex functions ``lock()`` and ``unlock()`` is error 
+prone and should be avoided. It's recommended to use RAII-style locking 
+mechanisms such as ``std::lock_guard`` or ``std::unique_lock``.
+
+Options
+---
+
+.. option:: LockableTypes
+
+   Semicolon-separated list of fully qualified names of types that support 
+   locking and unlocking a mutex;
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -91,6 +91,11 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`cppcoreguidelines-use-raii-locks
+  ` check.
+
+  Checks for explicit usage of ``std::mutex`` functions ``lock()`` and ``unlock``.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   `
   check.
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
@@ -0,0 +1,42 @@
+//===--- UseRaiiLocksCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USERAIILOCKSCHECK_H
+#define LLVM_CLAN

[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk updated this revision to Diff 188911.
lewmpk added a comment.

fixed documentation


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp

Index: test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
@@ -0,0 +1,90 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-use-raii-locks %t
+
+// Mock implementation of std::mutex
+namespace std {
+struct mutex {
+  void lock();
+  void unlock();
+};
+typedef mutex recursive_mutex;
+} // namespace std
+
+
+void warn_me1() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m.unlock();
+}
+
+void warn_me2() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  {
+std::mutex m;
+m.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+m.unlock();
+  }
+  m.unlock();
+}
+
+void warn_me3() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me4() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me5() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.unlock();
+}
+
+void ignore_me1() {
+  std::mutex m;
+  m.unlock();
+  m.lock();
+  // CHECK-MESSAGES-NOT: warning:
+}
+
+void ignore_me2() {
+  std::mutex m1;
+  std::mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
+
+void ignore_me3() {
+  std::recursive_mutex m1;
+  std::recursive_mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   cppcoreguidelines-use-raii-locks
fuchsia-default-arguments
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
fuchsia-multiple-inheritance
Index: docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - cppcoreguidelines-use-raii-locks
+
+cppcoreguidelines-use-raii-locks
+
+
+The explicit use of std::mutex functions ``lock()`` and ``unlock()`` is error 
+prone and should be avoided. It's recommended to use RAII-style locking 
+mechanisms such as ``std::lock_guard`` or ``std::unique_lock``.
+
+Options
+---
+
+.. option:: LockableTypes
+
+   Semicolon-separated list of fully qualified names of types that support 
+   locking and unlocking a mutex.
+   Defaults to: ``::std::mutex;::std::recursive_mutex;::std::timed_mutex;
+   ::std::recursive_timed_mutex;::std::unique_lock``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -91,6 +91,11 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`cppcoreguidelines-use-raii-locks
+  ` check.
+
+  Checks for explicit usage of ``std::mutex`` functions ``lock()`` and ``unlock``.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   `
   check.
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
@@ -0,0 +1,42 @@
+//===--- UseRaiiLocksCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+

[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk updated this revision to Diff 188912.
lewmpk added a comment.

fixed documentation again


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp

Index: test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
@@ -0,0 +1,90 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-use-raii-locks %t
+
+// Mock implementation of std::mutex
+namespace std {
+struct mutex {
+  void lock();
+  void unlock();
+};
+typedef mutex recursive_mutex;
+} // namespace std
+
+
+void warn_me1() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m.unlock();
+}
+
+void warn_me2() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  {
+std::mutex m;
+m.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+m.unlock();
+  }
+  m.unlock();
+}
+
+void warn_me3() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me4() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me5() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.unlock();
+}
+
+void ignore_me1() {
+  std::mutex m;
+  m.unlock();
+  m.lock();
+  // CHECK-MESSAGES-NOT: warning:
+}
+
+void ignore_me2() {
+  std::mutex m1;
+  std::mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
+
+void ignore_me3() {
+  std::recursive_mutex m1;
+  std::recursive_mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   cppcoreguidelines-use-raii-locks
fuchsia-default-arguments
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
fuchsia-multiple-inheritance
Index: docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - cppcoreguidelines-use-raii-locks
+
+cppcoreguidelines-use-raii-locks
+
+
+The explicit use of ``std::mutex`` functions ``lock()``, ``try_lock()`` and ``unlock()`` is error 
+prone and should be avoided. It's recommended to use RAII-style locking 
+mechanisms such as ``std::lock_guard`` or ``std::unique_lock``.
+
+Options
+---
+
+.. option:: LockableTypes
+
+   Semicolon-separated list of fully qualified names of types that support 
+   locking and unlocking a mutex.
+   Defaults to: ``::std::mutex;::std::recursive_mutex;::std::timed_mutex;
+   ::std::recursive_timed_mutex;::std::unique_lock``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -91,6 +91,12 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`cppcoreguidelines-use-raii-locks
+  ` check.
+
+  Checks for explicit usage of``std::mutex`` functions ``lock()``, 
+  ``try_lock()`` and ``unlock()``.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   `
   check.
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
@@ -0,0 +1,42 @@
+//===--- UseRaiiLocksCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===

[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk updated this revision to Diff 188913.
lewmpk added a comment.

fixed documentation formatting


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp

Index: test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
@@ -0,0 +1,90 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-use-raii-locks %t
+
+// Mock implementation of std::mutex
+namespace std {
+struct mutex {
+  void lock();
+  void unlock();
+};
+typedef mutex recursive_mutex;
+} // namespace std
+
+
+void warn_me1() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m.unlock();
+}
+
+void warn_me2() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  {
+std::mutex m;
+m.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+m.unlock();
+  }
+  m.unlock();
+}
+
+void warn_me3() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me4() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me5() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.unlock();
+}
+
+void ignore_me1() {
+  std::mutex m;
+  m.unlock();
+  m.lock();
+  // CHECK-MESSAGES-NOT: warning:
+}
+
+void ignore_me2() {
+  std::mutex m1;
+  std::mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
+
+void ignore_me3() {
+  std::recursive_mutex m1;
+  std::recursive_mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   cppcoreguidelines-use-raii-locks
fuchsia-default-arguments
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
fuchsia-multiple-inheritance
Index: docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
@@ -0,0 +1,19 @@
+.. title:: clang-tidy - cppcoreguidelines-use-raii-locks
+
+cppcoreguidelines-use-raii-locks
+
+
+The explicit use of ``std::mutex`` functions ``lock()``, ``try_lock()`` and 
+``unlock()`` is error prone and should be avoided. 
+It's recommended to use RAII-style locking  mechanisms such as 
+``std::lock_guard`` or ``std::unique_lock``.
+
+Options
+---
+
+.. option:: LockableTypes
+
+   Semicolon-separated list of fully qualified names of types that support 
+   locking and unlocking a mutex.
+   Defaults to: ``::std::mutex;::std::recursive_mutex;::std::timed_mutex;
+   ::std::recursive_timed_mutex;::std::unique_lock``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -91,6 +91,12 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`cppcoreguidelines-use-raii-locks
+  ` check.
+
+  Checks for explicit usage of``std::mutex`` functions ``lock()``, 
+  ``try_lock()`` and ``unlock()``.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   `
   check.
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
@@ -0,0 +1,42 @@
+//===--- UseRaiiLocksCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===

[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk marked 3 inline comments as done.
lewmpk added inline comments.



Comment at: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp:26
+  recordType(hasDeclaration(cxxRecordDecl(hasName("::std::mutex"));
+  // Match expressions of type mutex or mutex pointer
+  const auto MutexExpr =

lebedev.ri wrote:
> Terminology: *this* doesn't match anything.
> It's a matcher, yes, but it's just a lambda.
> The actual match happens at the end.
I was trying to describe its intent, not its action. Does anyone have any 
suggestions for a clearer comment?



Comment at: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h:13-14
+#include "../ClangTidy.h"
+#include 
+namespace clang {
+namespace tidy {

lebedev.ri wrote:
> Separate with newline
it seems that most checks are this way. it was autogenerated by the 
``add_new_check.py`` script.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818



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


[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk updated this revision to Diff 188915.
lewmpk added a comment.

fixed documentation formatting


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp

Index: test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
@@ -0,0 +1,90 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-use-raii-locks %t
+
+// Mock implementation of std::mutex
+namespace std {
+struct mutex {
+  void lock();
+  void unlock();
+};
+typedef mutex recursive_mutex;
+} // namespace std
+
+
+void warn_me1() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m.unlock();
+}
+
+void warn_me2() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  {
+std::mutex m;
+m.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+m.unlock();
+  }
+  m.unlock();
+}
+
+void warn_me3() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me4() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me5() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.unlock();
+}
+
+void ignore_me1() {
+  std::mutex m;
+  m.unlock();
+  m.lock();
+  // CHECK-MESSAGES-NOT: warning:
+}
+
+void ignore_me2() {
+  std::mutex m1;
+  std::mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
+
+void ignore_me3() {
+  std::recursive_mutex m1;
+  std::recursive_mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   cppcoreguidelines-use-raii-locks
fuchsia-default-arguments
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
fuchsia-multiple-inheritance
Index: docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
@@ -0,0 +1,19 @@
+.. title:: clang-tidy - cppcoreguidelines-use-raii-locks
+
+cppcoreguidelines-use-raii-locks
+
+
+The explicit use of ``std::mutex`` functions ``lock()``, ``try_lock()`` and 
+``unlock()`` is error prone and should be avoided. 
+It's recommended to use RAII-style locking mechanisms such as 
+``std::lock_guard`` or ``std::unique_lock``.
+
+Options
+---
+
+.. option:: LockableTypes
+
+   Semicolon-separated list of fully qualified names of types that support 
+   locking and unlocking a mutex.
+   Defaults to: ``::std::mutex;::std::recursive_mutex;::std::timed_mutex;
+   ::std::recursive_timed_mutex;::std::unique_lock``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -91,6 +91,12 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`cppcoreguidelines-use-raii-locks
+  ` check.
+
+  Checks for explicit usage of``std::mutex`` functions ``lock()``, 
+  ``try_lock()`` and ``unlock()``.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   `
   check.
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
@@ -0,0 +1,42 @@
+//===--- UseRaiiLocksCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===-

[PATCH] D58830: [ASTImporter] Import member expr with explicit template args

2019-03-01 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: a_sidorin, shafik.
Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp, rnkovacs.
Herald added a reviewer: a.sidorin.
Herald added a project: clang.

Member expressions with explicit template arguments were not imported
correctly: the DeclRefExpr was missing. This patch fixes.


Repository:
  rC Clang

https://reviews.llvm.org/D58830

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


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -2604,6 +2604,56 @@
   EXPECT_TRUE(LambdaRec->getDestructor());
 }
 
+TEST_P(ImportFunctions,
+   CallExprOfMemberFunctionTemplateWithExplicitTemplateArgs) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  struct X {
+template 
+void foo(){}
+  };
+  void f() {
+X x;
+x.foo();
+  }
+  )",
+  Lang_CXX);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("f")));
+  auto *ToD = Import(FromD, Lang_CXX);
+  EXPECT_TRUE(ToD);
+  EXPECT_TRUE(MatchVerifier().match(
+  ToD, functionDecl(hasName("f"), hasDescendant(declRefExpr();
+}
+
+TEST_P(ImportFunctions,
+   DependentCallExprOfMemberFunctionTemplateWithExplicitTemplateArgs) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  struct X {
+template 
+void foo(){}
+  };
+  template 
+  void f() {
+X x;
+x.foo();
+  }
+  void g() {
+f();
+  }
+  )",
+  Lang_CXX);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("g")));
+  auto *ToD = Import(FromD, Lang_CXX);
+  EXPECT_TRUE(ToD);
+  Decl *ToTU = ToAST->getASTContext().getTranslationUnitDecl();
+  EXPECT_TRUE(MatchVerifier().match(
+  ToTU, translationUnitDecl(hasDescendant(
+functionDecl(hasName("f"), hasDescendant(declRefExpr()));
+}
+
 struct ImportFriendFunctions : ImportFunctions {};
 
 TEST_P(ImportFriendFunctions, ImportFriendFunctionRedeclChainProto) {
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -7135,15 +7135,19 @@
 
   DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
 
+  TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
   if (E->hasExplicitTemplateArgs()) {
-// FIXME: handle template arguments
-return make_error(ImportError::UnsupportedConstruct);
+if (Error Err =
+ImportTemplateArgumentListInfo(E->getLAngleLoc(), 
E->getRAngleLoc(),
+   E->template_arguments(), ToTAInfo))
+  return std::move(Err);
+ResInfo = &ToTAInfo;
   }
 
   return MemberExpr::Create(
   Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
   ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, ToFoundDecl,
-  ToMemberNameInfo, nullptr, ToType, E->getValueKind(), 
E->getObjectKind());
+  ToMemberNameInfo, ResInfo, ToType, E->getValueKind(), 
E->getObjectKind());
 }
 
 ExpectedStmt


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -2604,6 +2604,56 @@
   EXPECT_TRUE(LambdaRec->getDestructor());
 }
 
+TEST_P(ImportFunctions,
+   CallExprOfMemberFunctionTemplateWithExplicitTemplateArgs) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  struct X {
+template 
+void foo(){}
+  };
+  void f() {
+X x;
+x.foo();
+  }
+  )",
+  Lang_CXX);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("f")));
+  auto *ToD = Import(FromD, Lang_CXX);
+  EXPECT_TRUE(ToD);
+  EXPECT_TRUE(MatchVerifier().match(
+  ToD, functionDecl(hasName("f"), hasDescendant(declRefExpr();
+}
+
+TEST_P(ImportFunctions,
+   DependentCallExprOfMemberFunctionTemplateWithExplicitTemplateArgs) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  struct X {
+template 
+void foo(){}
+  };
+  template 
+  void f() {
+X x;
+x.foo();
+  }
+  void g() {
+f();
+  }
+  )",
+  Lang_CXX);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("g")));
+  auto *ToD = Import(FromD, Lang_CXX);
+  EXPECT_TRUE(ToD);
+  Decl *ToTU = ToAST->getASTContext().getTranslationUnitDecl();
+  EXPECT_TRUE(MatchVerifier().match(
+  ToTU, translationUnitDecl(hasDescendant(
+functionDecl(hasName("f"), hasDescendant(declRefExpr()));
+}
+
 struct ImportFriendFunctions : ImportFunctions {};
 
 TEST_P(ImportFriendFunctions, ImportFriendFunctionRedeclChainProto) {
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+

[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk updated this revision to Diff 188918.
lewmpk added a comment.

improved tests


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp

Index: test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
@@ -0,0 +1,92 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-use-raii-locks %t
+
+// Mock implementation of std::mutex
+namespace std {
+struct mutex {
+  void lock();
+  void unlock();
+};
+typedef mutex recursive_mutex;
+} // namespace std
+
+void warn_me1() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m.unlock();
+}
+
+void warn_me2() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  {
+std::mutex m;
+m.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+m.unlock();
+  }
+  m.unlock();
+}
+
+void warn_me3() {
+  std::mutex m1;
+  std::mutex m2;
+  {
+m1.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+{
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use RAII
+  m2.unlock();
+}
+m1.unlock();
+  }
+}
+
+void warn_me4() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me5() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.unlock();
+}
+
+void ignore_me1() {
+  std::mutex m;
+  m.unlock();
+  m.lock();
+  // CHECK-MESSAGES-NOT: warning:
+}
+
+void ignore_me2() {
+  std::mutex m1;
+  std::mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
+
+void ignore_me3() {
+  std::recursive_mutex m1;
+  std::recursive_mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   cppcoreguidelines-use-raii-locks
fuchsia-default-arguments
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
fuchsia-multiple-inheritance
Index: docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
@@ -0,0 +1,19 @@
+.. title:: clang-tidy - cppcoreguidelines-use-raii-locks
+
+cppcoreguidelines-use-raii-locks
+
+
+The explicit use of ``std::mutex`` functions ``lock()``, ``try_lock()`` and 
+``unlock()`` is error prone and should be avoided. 
+It's recommended to use RAII-style locking mechanisms such as 
+``std::lock_guard`` or ``std::unique_lock``.
+
+Options
+---
+
+.. option:: LockableTypes
+
+   Semicolon-separated list of fully qualified names of types that support 
+   locking and unlocking a mutex.
+   Defaults to: ``::std::mutex;::std::recursive_mutex;::std::timed_mutex;
+   ::std::recursive_timed_mutex;::std::unique_lock``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -91,6 +91,12 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`cppcoreguidelines-use-raii-locks
+  ` check.
+
+  Checks for explicit usage of``std::mutex`` functions ``lock()``, 
+  ``try_lock()`` and ``unlock()``.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   `
   check.
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
@@ -0,0 +1,42 @@
+//===--- UseRaiiLocksCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===---

[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk updated this revision to Diff 188919.
lewmpk added a comment.

support try_lock_for and try_lock_until


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp

Index: test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
@@ -0,0 +1,92 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-use-raii-locks %t
+
+// Mock implementation of std::mutex
+namespace std {
+struct mutex {
+  void lock();
+  void unlock();
+};
+typedef mutex recursive_mutex;
+} // namespace std
+
+void warn_me1() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m.unlock();
+}
+
+void warn_me2() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  {
+std::mutex m;
+m.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+m.unlock();
+  }
+  m.unlock();
+}
+
+void warn_me3() {
+  std::mutex m1;
+  std::mutex m2;
+  {
+m1.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+{
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use RAII
+  m2.unlock();
+}
+m1.unlock();
+  }
+}
+
+void warn_me4() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me5() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.unlock();
+}
+
+void ignore_me1() {
+  std::mutex m;
+  m.unlock();
+  m.lock();
+  // CHECK-MESSAGES-NOT: warning:
+}
+
+void ignore_me2() {
+  std::mutex m1;
+  std::mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
+
+void ignore_me3() {
+  std::recursive_mutex m1;
+  std::recursive_mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   cppcoreguidelines-use-raii-locks
fuchsia-default-arguments
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
fuchsia-multiple-inheritance
Index: docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
@@ -0,0 +1,19 @@
+.. title:: clang-tidy - cppcoreguidelines-use-raii-locks
+
+cppcoreguidelines-use-raii-locks
+
+
+The explicit use of ``std::mutex`` functions ``lock()``, ``try_lock()`` and 
+``unlock()`` is error prone and should be avoided. 
+It's recommended to use RAII-style locking mechanisms such as 
+``std::lock_guard`` or ``std::unique_lock``.
+
+Options
+---
+
+.. option:: LockableTypes
+
+   Semicolon-separated list of fully qualified names of types that support 
+   locking and unlocking a mutex.
+   Defaults to: ``::std::mutex;::std::recursive_mutex;::std::timed_mutex;
+   ::std::recursive_timed_mutex;::std::unique_lock``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -91,6 +91,12 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`cppcoreguidelines-use-raii-locks
+  ` check.
+
+  Checks for explicit usage of``std::mutex`` functions ``lock()``, 
+  ``try_lock()`` and ``unlock()``.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   `
   check.
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
@@ -0,0 +1,42 @@
+//===--- UseRaiiLocksCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLV

[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Lewis Clark via Phabricator via cfe-commits
lewmpk updated this revision to Diff 188920.
lewmpk added a comment.

remove support for try_lock_for and try_lock_until


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp
  clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp

Index: test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp
@@ -0,0 +1,92 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-use-raii-locks %t
+
+// Mock implementation of std::mutex
+namespace std {
+struct mutex {
+  void lock();
+  void unlock();
+};
+typedef mutex recursive_mutex;
+} // namespace std
+
+void warn_me1() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m.unlock();
+}
+
+void warn_me2() {
+  std::mutex m;
+  m.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  {
+std::mutex m;
+m.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+m.unlock();
+  }
+  m.unlock();
+}
+
+void warn_me3() {
+  std::mutex m1;
+  std::mutex m2;
+  {
+m1.lock();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use RAII
+{
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use RAII
+  m2.unlock();
+}
+m1.unlock();
+  }
+}
+
+void warn_me4() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.unlock();
+}
+
+void warn_me5() {
+  std::mutex m1;
+  std::mutex m2;
+
+  m1.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m2.lock();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use RAII
+  m1.unlock();
+  m2.unlock();
+}
+
+void ignore_me1() {
+  std::mutex m;
+  m.unlock();
+  m.lock();
+  // CHECK-MESSAGES-NOT: warning:
+}
+
+void ignore_me2() {
+  std::mutex m1;
+  std::mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
+
+void ignore_me3() {
+  std::recursive_mutex m1;
+  std::recursive_mutex m2;
+  m1.lock();
+  // CHECK-MESSAGES-NOT: warning:
+  m2.unlock();
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   cppcoreguidelines-use-raii-locks
fuchsia-default-arguments
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
fuchsia-multiple-inheritance
Index: docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-use-raii-locks.rst
@@ -0,0 +1,19 @@
+.. title:: clang-tidy - cppcoreguidelines-use-raii-locks
+
+cppcoreguidelines-use-raii-locks
+
+
+The explicit use of ``std::mutex`` functions ``lock()``, ``try_lock()`` and 
+``unlock()`` is error prone and should be avoided. 
+It's recommended to use RAII-style locking mechanisms such as 
+``std::lock_guard`` or ``std::unique_lock``.
+
+Options
+---
+
+.. option:: LockableTypes
+
+   Semicolon-separated list of fully qualified names of types that support 
+   locking and unlocking a mutex.
+   Defaults to: ``::std::mutex;::std::recursive_mutex;::std::timed_mutex;
+   ::std::recursive_timed_mutex;::std::unique_lock``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -91,6 +91,12 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`cppcoreguidelines-use-raii-locks
+  ` check.
+
+  Checks for explicit usage of``std::mutex`` functions ``lock()``, 
+  ``try_lock()`` and ``unlock()``.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   `
   check.
Index: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h
@@ -0,0 +1,42 @@
+//===--- UseRaiiLocksCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2

[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

Ugh, could you please avoid doing lots a tiny changes every 5 minutes ? This 
causes spam on cfe-commits /:


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818



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


[PATCH] D58743: Handle built-in when importing SourceLocation and FileID

2019-03-01 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

@teemperor ping


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

https://reviews.llvm.org/D58743



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


[PATCH] D58819: [clang-format] clang-format off/on not respected when using C Style comments

2019-03-01 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 188931.
MyDeveloperDay added a comment.

Fix negative test case
support the same /*clang-format off*/ in the sort includes that 
the TokenLexer supports.


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

https://reviews.llvm.org/D58819

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/SortIncludesTest.cpp


Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -117,6 +117,43 @@
  "// clang-format on\n"));
 }
 
+TEST_F(SortIncludesTest, SupportClangFormatOffCStyle) {
+  EXPECT_EQ("#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format off */\n"
+"#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format on */\n",
+sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format off */\n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format on */\n"));
+
+  // Not really turning it off
+  EXPECT_EQ("#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format offically */\n"
+"#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format onwards */\n",
+sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format offically */\n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format onwards */\n"));
+}
+
 TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) {
   FmtStyle.SortIncludes = false;
   EXPECT_EQ("#include \"a.h\"\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1786,9 +1786,10 @@
 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
 
 StringRef Trimmed = Line.trim();
-if (Trimmed == "// clang-format off")
+if (Trimmed == "// clang-format off" || Trimmed == "/* clang-format off 
*/")
   FormattingOff = true;
-else if (Trimmed == "// clang-format on")
+else if (Trimmed == "// clang-format on" ||
+ Trimmed == "/* clang-format on */")
   FormattingOff = false;
 
 const bool EmptyLineSkipped =


Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -117,6 +117,43 @@
  "// clang-format on\n"));
 }
 
+TEST_F(SortIncludesTest, SupportClangFormatOffCStyle) {
+  EXPECT_EQ("#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format off */\n"
+"#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format on */\n",
+sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format off */\n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format on */\n"));
+
+  // Not really turning it off
+  EXPECT_EQ("#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format offically */\n"
+"#include \n"
+"#include \n"
+"#include \n"
+"/* clang-format onwards */\n",
+sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format offically */\n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "/* clang-format onwards */\n"));
+}
+
 TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) {
   FmtStyle.SortIncludes = false;
   EXPECT_EQ("#include \"a.h\"\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1786,9 +1786,10 @@
 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
 
 StringRef Trimmed = Line.trim();
-if (Trimmed == "// clang-format off")
+if (Trimmed == "// clang-format off" || Trimmed == "/* clang-format off */")
   FormattingOff = true;
-else if (Trimmed == "// clang-format on")
+else if (Trimmed == "// clang-format on" ||
+ Trimmed == "/* clang-format on */")
   FormattingOff = false;
 
 const bool EmptyLineSkipped =
___
cfe-commits mailing list
cfe-commits@lists.llvm

r355209 - [PGO] Use the explicit parameter in ProfileSummary API. NFC

2019-03-01 Thread Rong Xu via cfe-commits
Author: xur
Date: Fri Mar  1 09:50:20 2019
New Revision: 355209

URL: http://llvm.org/viewvc/llvm-project?rev=355209&view=rev
Log:
[PGO] Use the explicit parameter in ProfileSummary API. NFC

Use the explicit parameter in setProfileSummary() and getSummary().
This is a follow-up of r355131.

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=355209&r1=355208&r2=355209&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Mar  1 09:50:20 2019
@@ -52,6 +52,7 @@
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/ProfileSummary.h"
 #include "llvm/ProfileData/InstrProfReader.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -417,7 +418,9 @@ void CodeGenModule::Release() {
 OpenMPRuntime->clear();
   }
   if (PGOReader) {
-getModule().setProfileSummary(PGOReader->getSummary().getMD(VMContext));
+getModule().setProfileSummary(
+PGOReader->getSummary(/* UseCS */ false).getMD(VMContext),
+llvm::ProfileSummary::PSK_Instr);
 if (PGOStats.hasDiagnostics())
   PGOStats.reportDiagnostics(getDiags(), getCodeGenOpts().MainFileName);
   }


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


[PATCH] D58814: [clang][Index] Constructors and Destructors do not reference class

2019-03-01 Thread Nathan Hawes via Phabricator via cfe-commits
nathawes requested changes to this revision.
nathawes added a comment.
This revision now requires changes to proceed.

These references were added to support using the index data for symbol rename. 
I.e. so that when you rename the class, you can use the index data to find all 
occurrences of its name, including its use in constructor/destructor 
declarations and references (hence the test cases in 
test/Index/Core/index-source.cpp). If you need to specifically find references 
of the class symbol, as opposed to its name, could we instead distinguish these 
cases with a more specific SymbolRole, e.g. NameReference as opposed to 
Reference, and filter them based on that instead?


Repository:
  rC Clang

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

https://reviews.llvm.org/D58814



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


[PATCH] D58724: [gnustep-objc] Make the GNUstep v2 ABI work for Windows DLLs.

2019-03-01 Thread Dustin L. Howett via Phabricator via cfe-commits
DHowett-MSFT added inline comments.



Comment at: clang/lib/CodeGen/CGObjCGNU.cpp:188
 
+  Twine ManglePublicSymbol(StringRef Name) {
+return StringRef(CGM.getTriple().isOSBinFormatCOFF() ? "$_" : "._") + Name;

As of the latest revision, this now fails at runtime:

```
  0x01342976 (0x03D8D530 0x03D8DCA0 0x04045A08 0x04045A08), llvm::Twine::str() 
+ 0x166 bytes(s), e:\src\llvm\lib\suppor
  t\twine.cpp, line 29 + 0x5F byte(s)
  0x01664F99 (0x03D8D5C4 0x000A 0x 0x03D8DCA0), `anonymous 
namespace'::CGObjCGNUstep2::GetClassVar() + 0xB9
   bytes(s), e:\src\llvm\tools\clang\lib\codegen\cgobjcgnu.cpp, line 1207 + 
0x10 byte(s)
```

I believe we're running afoul of StringRef's lifetime here. I haven't had a 
chance to dig in.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58724



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


[PATCH] D58819: [clang-format] clang-format off/on not respected when using C Style comments

2019-03-01 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang/lib/Format/Format.cpp:1792
+else if (Trimmed == "// clang-format on" ||
+ Trimmed == "/* clang-format on */")
   FormattingOff = false;

Should we allow 
```
/* clang-format off
It is just horrible for this piece of code. */
```

? Multiline-comments could span multiple lines and to deactivates clang-format 
and give reasons.


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

https://reviews.llvm.org/D58819



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


[PATCH] D58818: [clang-tidy] added cppcoreguidelines-use-raii-locks check

2019-03-01 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp:35
+void UseRaiiLocksCheck::registerMatchers(MatchFinder *Finder) {
+  // lock_guards require c++11 or later
+  if (!getLangOpts().CPlusPlus11)

If we allow boost, pre c++11 is ok as well.
In general, plz use proper grammar, punctuation and full sentences in comments.



Comment at: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp:41
+  hasDeclaration(cxxRecordDecl(hasAnyListedName(LockableTypes));
+  // Match expressions of type mutex or mutex pointer
+  const auto MutexExpr =

please add proper punctutation in comments. we aim for correct text you can 
read and understand, with proper spelling and grammar.



Comment at: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp:65
+
+  const auto LockCallExpr = Result.Nodes.getNodeAs("lock");
+  const auto UnlockCallExpr =

please add the `*` for pointers to emphasize the difference between values and 
pointers.
In general we do not add `const` to values (as i believe is done in later 
lines), but only for pointers and references.



Comment at: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.cpp:69
+
+  const auto LockObjectName = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(

Please don't retrieve the name like this. Too error prone and compilatcated.

You can compare use `DeclRefExpr` 
(https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html) for your 
`MutexExpr` instead.
From there you go to the `Decl` and compare on pointer equality.



Comment at: clang-tidy/cppcoreguidelines/UseRaiiLocksCheck.h:28
+"LockableTypes",
+"::std::mutex;::std::recursive_mutex;::std::timed_mutex;::std::"
+"recursive_timed_mutex;::std::unique_lock")) {}

It might be a good idea to add the `boost` types as well? I believe they are 
interface-compatible, given the std version is derived from them.



Comment at: test/clang-tidy/cppcoreguidelines-use-raii-locks.cpp:4
+// Mock implementation of std::mutex
+namespace std {
+struct mutex {

Please add more tests

What happens for this?
```
void foo() {
  std::mutex m;
  m.lock();
  m.unlock();
  m.lock();
  m.unlock();
  m.try_lock();
  m.lock();
  m.unlock();
}
```

- Please add tests for templates, where the lock-type is a template parameter
- please add tests where the locking happens within macros
- please add tests for usage within loops
- where cases like `std::mutex m1; std::mutex &m2 = m1; // usage`. This should 
not be diagnosed, right?


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58818



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


[PATCH] D58841: [Diagnostics] Support -Wtype-limits for GCC compatibility

2019-03-01 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 created this revision.
xbolva00 added a reviewer: rsmith.
Herald added subscribers: cfe-commits, jdoerfert.
Herald added a project: clang.

Repository:
  rC Clang

https://reviews.llvm.org/D58841

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/test/Sema/compare.c
  clang/test/Sema/tautological-constant-compare.c
  clang/test/Sema/tautological-constant-enum-compare.c
  clang/test/SemaCXX/compare.cpp


Index: clang/test/SemaCXX/compare.cpp
===
--- clang/test/SemaCXX/compare.cpp
+++ clang/test/SemaCXX/compare.cpp
@@ -2,6 +2,7 @@
 // on integer sizes.
 
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify 
-Wsign-compare -Wtautological-constant-in-range-compare -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify 
-Wsign-compare -Wtype-limits -std=c++11 %s
 
 int test0(long a, unsigned long b) {
   enum EnumA {A};
Index: clang/test/Sema/tautological-constant-enum-compare.c
===
--- clang/test/Sema/tautological-constant-enum-compare.c
+++ clang/test/Sema/tautological-constant-enum-compare.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED 
-Wtautological-constant-in-range-compare -verify %s
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED 
-DSILENCE -Wno-tautological-constant-compare -verify %s
 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -DSILENCE 
-Wno-tautological-constant-compare -verify %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED 
-Wtype-limits -verify %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED 
-DSILENCE -Wno-type-limits -verify %s
 
 int main() {
   enum A { A_a = 2 };
Index: clang/test/Sema/tautological-constant-compare.c
===
--- clang/test/Sema/tautological-constant-compare.c
+++ clang/test/Sema/tautological-constant-compare.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only 
-Wtautological-constant-in-range-compare -DTEST -verify -x c++ %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only 
-Wtautological-type-limit-compare -DTEST -verify %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only 
-Wtautological-type-limit-compare -DTEST -verify -x c++ %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtype-limits -DTEST 
-verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtype-limits -DTEST 
-verify -x c++ %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wextra 
-Wno-sign-compare -verify %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wextra 
-Wno-sign-compare -verify -x c++ %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wall -verify %s
Index: clang/test/Sema/compare.c
===
--- clang/test/Sema/compare.c
+++ clang/test/Sema/compare.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify 
-Wsign-compare -Wtautological-constant-in-range-compare %s -Wno-unreachable-code
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify 
-Wsign-compare -Wtype-limits %s -Wno-unreachable-code
 
 int test(char *C) { // nothing here should warn.
   return C != ((void*)0);
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -481,6 +481,8 @@
[TautologicalTypeLimitCompare,
 TautologicalUnsignedZeroCompare,
 
TautologicalUnsignedEnumZeroCompare]>;
+// For compatibility with GCC; -Wtype-limits = 
-Wtautological-constant-in-range-compare
+def TypeLimits : DiagGroup<"type-limits", [TautologicalInRangeCompare]>;
 def TautologicalOutOfRangeCompare : 
DiagGroup<"tautological-constant-out-of-range-compare">;
 def TautologicalConstantCompare : DiagGroup<"tautological-constant-compare",
 [TautologicalOutOfRangeCompare]>;
@@ -778,7 +780,8 @@
 SignCompare,
 UnusedParameter,
 NullPointerArithmetic,
-EmptyInitStatement
+EmptyInitStatement,
+TypeLimits
   ]>;
 
 def Most : DiagGroup<"most", [


Index: clang/test/SemaCXX/compare.cpp
===
--- clang/test/SemaCXX/compare.cpp
+++ clang/test/SemaCXX/compare.cpp
@@ -2,6 +2,7 @@
 // on integer sizes.
 
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtautological-constant-in-range-compare -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-onl

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like elements

2019-03-01 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

In D50488#1409565 , @mgrang wrote:

> In D50488#1407975 , @Szelethus wrote:
>
> > But, as a work-in-progress alpha checker, the direction is set and looks 
> > great. Please let @NoQ have the final say.
>
>
> Thanks a lot @Szelethus! I will wait for @NoQ 's comments.


@NoQ Could you please review this patch?


Repository:
  rC Clang

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

https://reviews.llvm.org/D50488



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


[PATCH] D57986: [ProfileData] Sort FuncData before iteration to remove non-determinism

2019-03-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: lib/ProfileData/InstrProfWriter.cpp:389-397
+ auto nameA = A.first;
+ auto nameB = B.first;
+ int comp = nameA.compare(nameB);
+ if (comp)
+   return comp < 0;
+
+ auto hashA = A.second.first;

I guess you could write this as:

  return std::tie(A.first, A.second.first) < std::tie(B.first, B.second.first);

perhaps?


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

https://reviews.llvm.org/D57986



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


[PATCH] D58821: Inline asm constraints: allow ICE-like pointers for the "n" constraint (PR40890)

2019-03-01 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

My opinion doesn't carry as much weight as others who are more familiar with 
the front-end code, but LGTM.

One question, the code you added looks similar. Is there a way to extrapolate 
it into its own function? Maybe yet another `EvaluateAs*` method?




Comment at: clang/lib/Sema/SemaStmtAsm.cpp:389
+
+// For compatibility with GCC, we also allows pointers that would be
+// integral constant expressions if they were cast to int.

s/allows/allow/


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

https://reviews.llvm.org/D58821



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


[PATCH] D57986: [ProfileData] Sort FuncData before iteration to remove non-determinism

2019-03-01 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 188951.

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

https://reviews.llvm.org/D57986

Files:
  lib/ProfileData/InstrProfWriter.cpp


Index: lib/ProfileData/InstrProfWriter.cpp
===
--- lib/ProfileData/InstrProfWriter.cpp
+++ lib/ProfileData/InstrProfWriter.cpp
@@ -408,14 +408,30 @@
   else if (ProfileKind == PF_IRLevelWithCS)
 OS << "# CSIR level Instrumentation Flag\n:csir\n";
   InstrProfSymtab Symtab;
-  for (const auto &I : FunctionData)
-if (shouldEncodeData(I.getValue()))
+
+  using FuncPair = detail::DenseMapPair;
+  using RecordType = std::pair;
+  SmallVector OrderedFuncData;
+
+  for (const auto &I : FunctionData) {
+if (shouldEncodeData(I.getValue())) {
   if (Error E = Symtab.addFuncName(I.getKey()))
 return E;
-
-  for (const auto &I : FunctionData)
-if (shouldEncodeData(I.getValue()))
   for (const auto &Func : I.getValue())
-writeRecordInText(I.getKey(), Func.first, Func.second, Symtab, OS);
+OrderedFuncData.push_back(std::make_pair(I.getKey(), Func));
+}
+  }
+
+  llvm::sort(OrderedFuncData, [](const RecordType &A, const RecordType &B) {
+return std::tie(A.first, A.second.first) <
+   std::tie(B.first, B.second.first);
+  });
+
+  for (const auto &record : OrderedFuncData) {
+const auto &name = record.first;
+const auto &Func = record.second;
+writeRecordInText(name, Func.first, Func.second, Symtab, OS);
+  }
+
   return Error::success();
 }


Index: lib/ProfileData/InstrProfWriter.cpp
===
--- lib/ProfileData/InstrProfWriter.cpp
+++ lib/ProfileData/InstrProfWriter.cpp
@@ -408,14 +408,30 @@
   else if (ProfileKind == PF_IRLevelWithCS)
 OS << "# CSIR level Instrumentation Flag\n:csir\n";
   InstrProfSymtab Symtab;
-  for (const auto &I : FunctionData)
-if (shouldEncodeData(I.getValue()))
+
+  using FuncPair = detail::DenseMapPair;
+  using RecordType = std::pair;
+  SmallVector OrderedFuncData;
+
+  for (const auto &I : FunctionData) {
+if (shouldEncodeData(I.getValue())) {
   if (Error E = Symtab.addFuncName(I.getKey()))
 return E;
-
-  for (const auto &I : FunctionData)
-if (shouldEncodeData(I.getValue()))
   for (const auto &Func : I.getValue())
-writeRecordInText(I.getKey(), Func.first, Func.second, Symtab, OS);
+OrderedFuncData.push_back(std::make_pair(I.getKey(), Func));
+}
+  }
+
+  llvm::sort(OrderedFuncData, [](const RecordType &A, const RecordType &B) {
+return std::tie(A.first, A.second.first) <
+   std::tie(B.first, B.second.first);
+  });
+
+  for (const auto &record : OrderedFuncData) {
+const auto &name = record.first;
+const auto &Func = record.second;
+writeRecordInText(name, Func.first, Func.second, Symtab, OS);
+  }
+
   return Error::success();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58797: [Sema] Add some compile time _FORTIFY_SOURCE diagnostics

2019-03-01 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv added a comment.

Thanks for working on this!

I hope to take an in-depth look at this patch next week (if someone else 
doesn't beat me to it...), but wanted to note that I think enabling clang to 
emit these warnings on its own is a good thing. `diagnose_if` is great for 
potentially more targeted/implementation-defined things that standard libraries 
want to diagnose, but IMO clang should be able to catch trivially broken code 
like this regardless of the stdlib it's building against.


Repository:
  rC Clang

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

https://reviews.llvm.org/D58797



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


[PATCH] D58841: [Diagnostics] Support -Wtype-limits for GCC compatibility

2019-03-01 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri requested changes to this revision.
lebedev.ri added a comment.
This revision now requires changes to proceed.

See D41512 , rC322901 
, D51545 .




Comment at: clang/include/clang/Basic/DiagnosticGroups.td:784
+EmptyInitStatement,
+TypeLimits
   ]>;

`-Wtautological-constant-in-range-compare` is quite intentionally **not** in 
`-Wextra`.


Repository:
  rC Clang

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

https://reviews.llvm.org/D58841



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


[PATCH] D58821: Inline asm constraints: allow ICE-like pointers for the "n" constraint (PR40890)

2019-03-01 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGStmt.cpp:1852
+IntResult =
+llvm::APSInt::get(EVResult.Val.getLValueOffset().getQuantity());
+  else

This always returns an APSInt with width 64; is that really right?  I guess it 
might not really matter given that it's only going to be used as an immediate 
constant anyway, but it seems weird.



Comment at: clang/lib/Sema/SemaStmtAsm.cpp:394
+  IntResult = EVResult.Val.getInt();
+else if (EVResult.Val.isNullPointer())
+  IntResult = llvm::APSInt::get(

APValue::isNullPointer() asserts that the value is an LValue; do you need to 
check for that explicitly here?



Comment at: clang/lib/Sema/SemaStmtAsm.cpp:399
+  IntResult =
+  llvm::APSInt::get(EVResult.Val.getLValueOffset().getQuantity());
+else

I think it makes sense to add a method to APValue specifically to do the 
conversion from LValue to an APSInt, whether or not isNullPointer() is true, 
and use it both here and in IntExprEvaluator::VisitCastExpr in 
lib/AST/ExprConstant.cpp.  The logic is sort of subtle (and I'm not completely 
sure it's right for targets where null is not zero, but you shouldn't try to 
fix that here).


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

https://reviews.llvm.org/D58821



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


[PATCH] D54176: [PGO] clang part of change for context-sensitive PGO.

2019-03-01 Thread Rong Xu via Phabricator via cfe-commits
xur updated this revision to Diff 188955.
xur added a comment.

Integrated Teresa's suggestion to change the err() to assert.
Added documentation change suggested by David.


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

https://reviews.llvm.org/D54176

Files:
  docs/UsersManual.rst
  include/clang/Basic/CodeGenOptions.h
  include/clang/Driver/Options.td
  lib/CodeGen/BackendUtil.cpp
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/CommonArgs.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/pgotestir.proftext
  test/CodeGen/Inputs/pgotestir_cs.proftext
  test/CodeGen/cspgo-instrumentation.c
  test/CodeGen/cspgo-instrumentation_lto.c
  test/CodeGen/cspgo-instrumentation_thinlto.c

Index: test/CodeGen/cspgo-instrumentation_thinlto.c
===
--- test/CodeGen/cspgo-instrumentation_thinlto.c
+++ test/CodeGen/cspgo-instrumentation_thinlto.c
@@ -0,0 +1,52 @@
+// Test if CSPGO instrumentation and use pass are invoked in thinlto.
+//
+// RUN: rm -rf %t && mkdir %t
+// RUN: llvm-profdata merge -o %t/noncs.profdata %S/Inputs/pgotestir.proftext
+//
+// Ensure Pass PGOInstrumentationGenPass is not invoked in PreLink.
+// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata -fprofile-instrument=csllvm %s -fprofile-instrument-path=default.profraw -flto=thin -mllvm -debug-pass=Structure -emit-llvm-bc -o %t/foo_fe.bc 2>&1 | FileCheck %s -check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-PRE
+// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata -fprofile-instrument=csllvm %s -fprofile-instrument-path=default.profraw  -flto=thin -fexperimental-new-pass-manager -fdebug-pass-manager -emit-llvm-bc -o %t/foo_fe_pm.bc 2>&1 | FileCheck %s -check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-PRE-NEWPM
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-PRE: PGOInstrumentationUsePass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-PRE: PGOInstrumentationGenCreateVarPass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-PRE-NOT: PGOInstrumentationGenPass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-PRE-NEWPM: Running pass: PGOInstrumentationUse
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-PRE-NEWPM: Running pass: PGOInstrumentationGenCreateVar
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-PRE-NEWPM-NOT: Running pass: PGOInstrumentationGen on
+//
+// RUN: llvm-lto -thinlto -o %t/foo %t/foo_fe.bc
+// RUN: llvm-lto -thinlto -o %t/foo_pm %t/foo_fe_pm.bc
+// Ensure Pass PGOInstrumentationGenPass is invoked in PostLink.
+// RUN: %clang_cc1 -O2 -x ir %t/foo_fe.bc -fthinlto-index=%t/foo.thinlto.bc -fprofile-instrument=csllvm -fprofile-instrument-path=default.profraw  -flto=thin -emit-llvm -mllvm -debug-pass=Structure -o - 2>&1 | FileCheck %s -check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-POST
+// RUN: %clang_cc1 -O2 -x ir %t/foo_fe_pm.bc -fthinlto-index=%t/foo_pm.thinlto.bc -fexperimental-new-pass-manager -fdebug-pass-manager  -fprofile-instrument=csllvm -fprofile-instrument-path=default.profraw  -flto=thin -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-POST-NEWPM
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-POST-NOT: PGOInstrumentationUsePass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-POST-NOT: PGOInstrumentationGenCreateVarPass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-POST: PGOInstrumentationGenPass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-POST-NEWPM-NOT: Running pass: PGOInstrumentationUse
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-POST-NEWPM-NOT: Running pass: PGOInstrumentationGenCreateVar
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-POST-NEWPM: Running pass: PGOInstrumentationGen on
+//
+// RUN: llvm-profdata merge -o %t/cs.profdata %S/Inputs/pgotestir_cs.proftext
+//
+// Ensure Pass PGOInstrumentationUsePass is invoked Once in PreLink.
+// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/cs.profdata %s -flto=thin -mllvm -debug-pass=Structure -emit-llvm-bc -o %t/foo_fe.bc 2>&1 | FileCheck %s -check-prefix=CHECK-CSPGOUSEPASS-INVOKED-INSTR-USE-PRE
+// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/cs.profdata %s -flto=thin -fexperimental-new-pass-manager -fdebug-pass-manager -emit-llvm-bc -o %t/foo_fe_pm.bc 2>&1 | FileCheck %s -check-prefix=CHECK-CSPGOUSEPASS-INVOKED-INSTR-USE-PRE-NEWPM
+// CHECK-CSPGOUSEPASS-INVOKED-INSTR-USE-PRE: PGOInstrumentationUsePass
+// CHECK-CSPGOUSEPASS-INVOKED-INSTR-USE-PRE-NOT: PGOInstrumentationUsePass
+// CHECK-CSPGOUSEPASS-INVOKED-INSTR-USE-PRE-NEWPM: Running pass: PGOInstrumentationUse
+// CHECK-CSPGOUSEPASS-INVOKED-INSTR-USE-PRE-NEWPM-NOT: Running pass: PGOInstrumentationUse
+//
+// RUN: llvm-lto -thinlto -o %t/foo %t/foo_fe.bc
+// RUN: llvm-lto -thinlto -o %t/foo_pm %t/foo_fe_pm.bc
+// Ensure Pass PGOInstrumentationUSEPass is invoked in PostLink.
+// RUN: %clang_cc1 -O2 -x ir %t/foo_fe.bc -fthinlto-index=%t/foo.thinlto.bc -fprofile-instrument-use-path=%t/cs.profdata -flto=thin -emit-llvm -mllvm -debug-pass=Structure -o - 2>&1 | FileCheck %s -

[PATCH] D58841: [Diagnostics] Support -Wtype-limits for GCC compatibility

2019-03-01 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 188957.
xbolva00 added a comment.

Remove from -Wextra


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

https://reviews.llvm.org/D58841

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/test/Sema/compare.c
  clang/test/Sema/tautological-constant-compare.c
  clang/test/Sema/tautological-constant-enum-compare.c
  clang/test/SemaCXX/compare.cpp


Index: clang/test/SemaCXX/compare.cpp
===
--- clang/test/SemaCXX/compare.cpp
+++ clang/test/SemaCXX/compare.cpp
@@ -2,6 +2,7 @@
 // on integer sizes.
 
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify 
-Wsign-compare -Wtautological-constant-in-range-compare -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify 
-Wsign-compare -Wtype-limits -std=c++11 %s
 
 int test0(long a, unsigned long b) {
   enum EnumA {A};
Index: clang/test/Sema/tautological-constant-enum-compare.c
===
--- clang/test/Sema/tautological-constant-enum-compare.c
+++ clang/test/Sema/tautological-constant-enum-compare.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED 
-Wtautological-constant-in-range-compare -verify %s
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED 
-DSILENCE -Wno-tautological-constant-compare -verify %s
 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -DSILENCE 
-Wno-tautological-constant-compare -verify %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED 
-Wtype-limits -verify %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED 
-DSILENCE -Wno-type-limits -verify %s
 
 int main() {
   enum A { A_a = 2 };
Index: clang/test/Sema/tautological-constant-compare.c
===
--- clang/test/Sema/tautological-constant-compare.c
+++ clang/test/Sema/tautological-constant-compare.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only 
-Wtautological-constant-in-range-compare -DTEST -verify -x c++ %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only 
-Wtautological-type-limit-compare -DTEST -verify %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only 
-Wtautological-type-limit-compare -DTEST -verify -x c++ %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtype-limits -DTEST 
-verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtype-limits -DTEST 
-verify -x c++ %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wextra 
-Wno-sign-compare -verify %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wextra 
-Wno-sign-compare -verify -x c++ %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wall -verify %s
Index: clang/test/Sema/compare.c
===
--- clang/test/Sema/compare.c
+++ clang/test/Sema/compare.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify 
-Wsign-compare -Wtautological-constant-in-range-compare %s -Wno-unreachable-code
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify 
-Wsign-compare -Wtype-limits %s -Wno-unreachable-code
 
 int test(char *C) { // nothing here should warn.
   return C != ((void*)0);
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -481,6 +481,8 @@
[TautologicalTypeLimitCompare,
 TautologicalUnsignedZeroCompare,
 
TautologicalUnsignedEnumZeroCompare]>;
+// For compatibility with GCC; -Wtype-limits = 
-Wtautological-constant-in-range-compare
+def TypeLimits : DiagGroup<"type-limits", [TautologicalInRangeCompare]>;
 def TautologicalOutOfRangeCompare : 
DiagGroup<"tautological-constant-out-of-range-compare">;
 def TautologicalConstantCompare : DiagGroup<"tautological-constant-compare",
 [TautologicalOutOfRangeCompare]>;


Index: clang/test/SemaCXX/compare.cpp
===
--- clang/test/SemaCXX/compare.cpp
+++ clang/test/SemaCXX/compare.cpp
@@ -2,6 +2,7 @@
 // on integer sizes.
 
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtautological-constant-in-range-compare -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtype-limits -std=c++11 %s
 
 int test0(long a, unsigned long b) {
   enum EnumA {A};
Index: clang/test/Sema/tautological-constant-enum-compare.c
===

[PATCH] D58841: [Diagnostics] Support -Wtype-limits for GCC compatibility

2019-03-01 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a reviewer: thakis.
lebedev.ri resigned from this revision.
lebedev.ri added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticGroups.td:485
+// For compatibility with GCC; -Wtype-limits = 
-Wtautological-constant-in-range-compare
+def TypeLimits : DiagGroup<"type-limits", [TautologicalInRangeCompare]>;
 def TautologicalOutOfRangeCompare : 
DiagGroup<"tautological-constant-out-of-range-compare">;

Is gcc's `-Wtype-limits` *just* `-Wtautological-constant-in-range-compare`, or 
is something else should be there?


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

https://reviews.llvm.org/D58841



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


[PATCH] D58828: [analyzer] Fix taint propagation in GenericTaintChecker

2019-03-01 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

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

https://reviews.llvm.org/D58828



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


[PATCH] D58724: [gnustep-objc] Make the GNUstep v2 ABI work for Windows DLLs.

2019-03-01 Thread Dustin L. Howett via Phabricator via cfe-commits
DHowett-MSFT added inline comments.



Comment at: clang/lib/CodeGen/CGObjCGNU.cpp:188
 
+  Twine ManglePublicSymbol(StringRef Name) {
+return StringRef(CGM.getTriple().isOSBinFormatCOFF() ? "$_" : "._") + Name;

DHowett-MSFT wrote:
> As of the latest revision, this now fails at runtime:
> 
> ```
>   0x01342976 (0x03D8D530 0x03D8DCA0 0x04045A08 0x04045A08), 
> llvm::Twine::str() + 0x166 bytes(s), e:\src\llvm\lib\suppor
>   t\twine.cpp, line 29 + 0x5F byte(s)
>   0x01664F99 (0x03D8D5C4 0x000A 0x 0x03D8DCA0), `anonymous 
> namespace'::CGObjCGNUstep2::GetClassVar() + 0xB9
>bytes(s), e:\src\llvm\tools\clang\lib\codegen\cgobjcgnu.cpp, line 1207 + 
> 0x10 byte(s)
> ```
> 
> I believe we're running afoul of StringRef's lifetime here. I haven't had a 
> chance to dig in.
Alright, I don't completely understand why Twine is the way that it is, but 
here:

```
  Twine ManglePublicSymbol(StringRef Name)
```

When we construct `Twine(const char*, StringRef)`, the newly-minted Twine 
contains a _pointer to_ the passed-in StringRef. It's invalid immediately after 
`ManglePublicSymbol` returns. After a few layers of stack pop off, we end up 
with random garbage and undefined behavior.

A quick and effective fix is to switch `Name` to be of type `const Twine&`.

```
  Twine ManglePublicSymbol(const Twine& Name)
```

Name ends up being a twine rvalue with a LHSType of cString, and all is right 
in the world.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58724



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


[PATCH] D58841: [Diagnostics] Support -Wtype-limits for GCC compatibility

2019-03-01 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 marked an inline comment as done.
xbolva00 added a comment.

Ok, if concers




Comment at: clang/include/clang/Basic/DiagnosticGroups.td:485
+// For compatibility with GCC; -Wtype-limits = 
-Wtautological-constant-in-range-compare
+def TypeLimits : DiagGroup<"type-limits", [TautologicalInRangeCompare]>;
 def TautologicalOutOfRangeCompare : 
DiagGroup<"tautological-constant-out-of-range-compare">;

lebedev.ri wrote:
> Is gcc's `-Wtype-limits` *just* `-Wtautological-constant-in-range-compare`, 
> or is something else should be there?
-Wtautological-constant-in-range-compare is enough to diagnose 99% cases from:

https://github.com/gcc-mirror/gcc/blob/41d6b10e96a1de98e90a7c0378437c3255814b16/gcc/testsuite/g%2B%2B.dg/warn/Wtype-limits.C

One missed case is:
int test (int x) 
{
  if ((long long)x <= 0x123456789ABCLL)
return 1;
  else 
return 0;
}

Tried -Weverything, no help. We miss this case. I will open PR for that.

But anyway, this missed case should not block this patch.


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

https://reviews.llvm.org/D58841



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


[PATCH] D58819: [clang-format] clang-format off/on not respected when using C Style comments

2019-03-01 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay marked an inline comment as done.
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/Format.cpp:1792
+else if (Trimmed == "// clang-format on" ||
+ Trimmed == "/* clang-format on */")
   FormattingOff = false;

JonasToth wrote:
> Should we allow 
> ```
> /* clang-format off
> It is just horrible for this piece of code. */
> ```
> 
> ? Multiline-comments could span multiple lines and to deactivates 
> clang-format and give reasons.
initially that is kind of what I was trying to do, but if you look over in 
TokenLexer where its turned off for styling they check only for a single line

So to be honest if we are going to change it we should change it in both 
places, but perhaps that is just overkill.


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

https://reviews.llvm.org/D58819



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


[PATCH] D58819: [clang-format] clang-format off/on not respected when using C Style comments

2019-03-01 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang/lib/Format/Format.cpp:1792
+else if (Trimmed == "// clang-format on" ||
+ Trimmed == "/* clang-format on */")
   FormattingOff = false;

MyDeveloperDay wrote:
> JonasToth wrote:
> > Should we allow 
> > ```
> > /* clang-format off
> > It is just horrible for this piece of code. */
> > ```
> > 
> > ? Multiline-comments could span multiple lines and to deactivates 
> > clang-format and give reasons.
> initially that is kind of what I was trying to do, but if you look over in 
> TokenLexer where its turned off for styling they check only for a single line
> 
> So to be honest if we are going to change it we should change it in both 
> places, but perhaps that is just overkill.
Totally, not necessary in my eyes, nice plus, so dont implement it :D


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

https://reviews.llvm.org/D58819



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


[PATCH] D58841: [Diagnostics] Support -Wtype-limits for GCC compatibility

2019-03-01 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticGroups.td:485
+// For compatibility with GCC; -Wtype-limits = 
-Wtautological-constant-in-range-compare
+def TypeLimits : DiagGroup<"type-limits", [TautologicalInRangeCompare]>;
 def TautologicalOutOfRangeCompare : 
DiagGroup<"tautological-constant-out-of-range-compare">;

xbolva00 wrote:
> lebedev.ri wrote:
> > Is gcc's `-Wtype-limits` *just* `-Wtautological-constant-in-range-compare`, 
> > or is something else should be there?
> -Wtautological-constant-in-range-compare is enough to diagnose 99% cases from:
> 
> https://github.com/gcc-mirror/gcc/blob/41d6b10e96a1de98e90a7c0378437c3255814b16/gcc/testsuite/g%2B%2B.dg/warn/Wtype-limits.C
> 
> One missed case is:
> int test (int x) 
> {
>   if ((long long)x <= 0x123456789ABCLL)
> return 1;
>   else 
> return 0;
> }
> 
> Tried -Weverything, no help. We miss this case. I will open PR for that.
> 
> But anyway, this missed case should not block this patch.
> -Wtautological-constant-in-range-compare is enough to diagnose 99% cases from:

That doesn't really answer the question.
I'm sure that *adding* `-Wtautological-constant-in-range-compare` helps.
But what about the other way around?
Does passing `-Wno-type-limits` silence *all* the expected diags in that file?


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

https://reviews.llvm.org/D58841



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


[PATCH] D58841: [Diagnostics] Support -Wtype-limits for GCC compatibility

2019-03-01 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 marked an inline comment as done.
xbolva00 added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticGroups.td:485
+// For compatibility with GCC; -Wtype-limits = 
-Wtautological-constant-in-range-compare
+def TypeLimits : DiagGroup<"type-limits", [TautologicalInRangeCompare]>;
 def TautologicalOutOfRangeCompare : 
DiagGroup<"tautological-constant-out-of-range-compare">;

lebedev.ri wrote:
> xbolva00 wrote:
> > lebedev.ri wrote:
> > > Is gcc's `-Wtype-limits` *just* 
> > > `-Wtautological-constant-in-range-compare`, or is something else should 
> > > be there?
> > -Wtautological-constant-in-range-compare is enough to diagnose 99% cases 
> > from:
> > 
> > https://github.com/gcc-mirror/gcc/blob/41d6b10e96a1de98e90a7c0378437c3255814b16/gcc/testsuite/g%2B%2B.dg/warn/Wtype-limits.C
> > 
> > One missed case is:
> > int test (int x) 
> > {
> >   if ((long long)x <= 0x123456789ABCLL)
> > return 1;
> >   else 
> > return 0;
> > }
> > 
> > Tried -Weverything, no help. We miss this case. I will open PR for that.
> > 
> > But anyway, this missed case should not block this patch.
> > -Wtautological-constant-in-range-compare is enough to diagnose 99% cases 
> > from:
> 
> That doesn't really answer the question.
> I'm sure that *adding* `-Wtautological-constant-in-range-compare` helps.
> But what about the other way around?
> Does passing `-Wno-type-limits` silence *all* the expected diags in that file?
Yes, silences it correctly.


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

https://reviews.llvm.org/D58841



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


r355226 - [DWARF] Make -g with empty assembler source work better.

2019-03-01 Thread Paul Robinson via cfe-commits
Author: probinson
Date: Fri Mar  1 12:58:04 2019
New Revision: 355226

URL: http://llvm.org/viewvc/llvm-project?rev=355226&view=rev
Log:
[DWARF] Make -g with empty assembler source work better.

This was sometimes causing clang or llvm-mc to crash, and in other
cases could emit a bogus DWARF line-table header. I did an interim
patch in r352541; this patch should be a cleaner and more complete
fix, and retains the test.

Addresses PR40538.

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

Modified:
cfe/trunk/test/Misc/cc1as-asm-debug.s
cfe/trunk/tools/driver/cc1as_main.cpp

Modified: cfe/trunk/test/Misc/cc1as-asm-debug.s
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/cc1as-asm-debug.s?rev=355226&r1=355225&r2=355226&view=diff
==
--- cfe/trunk/test/Misc/cc1as-asm-debug.s (original)
+++ cfe/trunk/test/Misc/cc1as-asm-debug.s Fri Mar  1 12:58:04 2019
@@ -8,4 +8,5 @@
 // CHECK: {{\.}}section .debug_info
 // CHECK: {{\.}}section .debug_info
 // CHECK-NOT: {{\.}}section
-// CHECK: .ascii "comment.s"
+// Look for this as a relative path.
+// CHECK: .ascii "{{[^\\/].*}}comment.s"

Modified: cfe/trunk/tools/driver/cc1as_main.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1as_main.cpp?rev=355226&r1=355225&r2=355226&view=diff
==
--- cfe/trunk/tools/driver/cc1as_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1as_main.cpp Fri Mar  1 12:58:04 2019
@@ -336,7 +336,7 @@ static bool ExecuteAssembler(AssemblerIn
   SourceMgr SrcMgr;
 
   // Tell SrcMgr about this buffer, which is what the parser will pick up.
-  SrcMgr.AddNewSourceBuffer(std::move(*Buffer), SMLoc());
+  unsigned BufferIndex = SrcMgr.AddNewSourceBuffer(std::move(*Buffer), 
SMLoc());
 
   // Record the location of the include directories so that the lexer can find
   // it later.
@@ -393,12 +393,21 @@ static bool ExecuteAssembler(AssemblerIn
 Ctx.setDwarfDebugProducer(StringRef(Opts.DwarfDebugProducer));
   if (!Opts.DebugCompilationDir.empty())
 Ctx.setCompilationDir(Opts.DebugCompilationDir);
+  else {
+// If no compilation dir is set, try to use the current directory.
+SmallString<128> CWD;
+if (!sys::fs::current_path(CWD))
+  Ctx.setCompilationDir(CWD);
+  }
   if (!Opts.DebugPrefixMap.empty())
 for (const auto &KV : Opts.DebugPrefixMap)
   Ctx.addDebugPrefixMapEntry(KV.first, KV.second);
   if (!Opts.MainFileName.empty())
 Ctx.setMainFileName(StringRef(Opts.MainFileName));
   Ctx.setDwarfVersion(Opts.DwarfVersion);
+  if (Opts.GenDwarfForAssembly)
+Ctx.setGenDwarfRootFile(Opts.InputFile,
+SrcMgr.getMemoryBuffer(BufferIndex)->getBuffer());
 
   // Build up the feature string from the target feature list.
   std::string FS;


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


[PATCH] D58844: Give builtins and alloc/dealloc operators the default calling convention.

2019-03-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: SjoerdMeijer, Anastasia, yaxunl, rnk.
Herald added a subscriber: kristina.
Herald added a project: clang.

On SPIR targets, the default calling convention is SpirFunction.  
However, operator new/delete and builtins were being created with CC_C. 
The result is indirect references to new/delete (or builtins that are permitted
to be called indirectly have a mismatched type, as well as questionable codegen
in some cases.

This patch sets both to the default calling convention, so that it  


properly matches the calling convention of the target.


Repository:
  rC Clang

https://reviews.llvm.org/D58844

Files:
  lib/AST/ASTContext.cpp
  lib/Sema/SemaExprCXX.cpp
  test/CodeGenCXX/builtin-calling-conv.cpp


Index: test/CodeGenCXX/builtin-calling-conv.cpp
===
--- /dev/null
+++ test/CodeGenCXX/builtin-calling-conv.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple x86_64-linux-pc -DREDECL -emit-llvm %s -o - | 
FileCheck %s -check-prefix LINUX
+// RUN: %clang_cc1 -triple spir-unknown-unknown -DREDECL -DSPIR -emit-llvm %s 
-o - | FileCheck %s -check-prefix SPIR
+// RUN: %clang_cc1 -triple x86_64-linux-pc -emit-llvm %s -o - | FileCheck %s 
-check-prefix LINUX
+// RUN: %clang_cc1 -triple spir-unknown-unknown -DSPIR -emit-llvm %s -o - | 
FileCheck %s -check-prefix SPIR
+
+#ifdef REDECL
+namespace std {
+#ifdef SPIR
+using size_t = unsigned int;
+#else
+using size_t = unsigned long;
+#endif // SPIR
+} // namespace std
+
+float __builtin_atan2f(float, float);
+void *operator new(std::size_t);
+#endif // REDECL
+
+void foo();
+
+void user() {
+  int i;
+  ::operator new(5);
+  (void)__builtin_atan2f(1.1, 2.2);
+  foo();
+}
+
+// LINUX: define void @_Z4userv()
+// LINUX: call i8* @_Znwm
+// LINUX: call float @atan2f
+// LINUX: call void @_Z3foov
+// LINUX: declare noalias i8* @_Znwm(i64)
+// LINUX: declare float @atan2f(float, float)
+// LINUX: declare void @_Z3foov()
+
+// SPIR: define spir_func void @_Z4userv()
+// SPIR: call spir_func i8* @_Znwj
+// SPIR: call spir_func float @atan2f
+// SPIR: call spir_func void @_Z3foov
+// SPIR: declare spir_func noalias i8* @_Znwj(i32)
+// SPIR: declare spir_func float @atan2f(float, float)
+// SPIR: declare spir_func void @_Z3foov()
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2795,7 +2795,8 @@
 }
   }
 
-  FunctionProtoType::ExtProtoInfo EPI;
+  FunctionProtoType::ExtProtoInfo EPI(Context.getDefaultCallingConvention(
+  /*IsVariadic=*/false, /*IsCXXMethod=*/false));
 
   QualType BadAllocType;
   bool HasBadAllocExceptionSpec
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -9565,10 +9565,12 @@
   assert((TypeStr[0] != '.' || TypeStr[1] == 0) &&
  "'.' should only occur at end of builtin type list!");
 
-  FunctionType::ExtInfo EI(CC_C);
+  bool Variadic = (TypeStr[0] == '.');
+
+  FunctionType::ExtInfo EI(
+  getDefaultCallingConvention(Variadic, /*IsCXXMethod=*/false));
   if (BuiltinInfo.isNoReturn(Id)) EI = EI.withNoReturn(true);
 
-  bool Variadic = (TypeStr[0] == '.');
 
   // We really shouldn't be making a no-proto type here.
   if (ArgTypes.empty() && Variadic && !getLangOpts().CPlusPlus)


Index: test/CodeGenCXX/builtin-calling-conv.cpp
===
--- /dev/null
+++ test/CodeGenCXX/builtin-calling-conv.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple x86_64-linux-pc -DREDECL -emit-llvm %s -o - | FileCheck %s -check-prefix LINUX
+// RUN: %clang_cc1 -triple spir-unknown-unknown -DREDECL -DSPIR -emit-llvm %s -o - | FileCheck %s -check-prefix SPIR
+// RUN: %clang_cc1 -triple x86_64-linux-pc -emit-llvm %s -o - | FileCheck %s -check-prefix LINUX
+// RUN: %clang_cc1 -triple spir-unknown-unknown -DSPIR -emit-llvm %s -o - | FileCheck %s -check-prefix SPIR
+
+#ifdef REDECL
+namespace std {
+#ifdef SPIR
+using size_t = unsigned int;
+#else
+using size_t = unsigned long;
+#endif // SPIR
+} // namespace std
+
+float __builtin_atan2f(float, float);
+void *operator new(std::size_t);
+#endif // REDECL
+
+void foo();
+
+void user() {
+  int i;
+  ::operator new(5);
+  (void)__builtin_atan2f(1.1, 2.2);
+  foo();
+}
+
+// LINUX: define void @_Z4userv()
+// LINUX: call i8* @_Znwm
+// LINUX: call float @atan2f
+// LINUX: call void @_Z3foov
+// LINUX: declare noalias i8* @_Znwm(i64)
+// LINUX: declare float @atan2f(float, float)
+// LINUX: declare void @_Z3foov()
+
+// SPIR: define spir_func void @_Z4userv()
+// SPIR: call spir_func i8* @_Znwj
+// SPIR: call spir_func float @atan2f
+// SPIR: call spir_func void @_Z3

[PATCH] D58537: lib/Header: Simplify CMakeLists.txt

2019-03-01 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

@tstellar are you planning to land this soon? It'll conflict with D58791 
, but I'm not planning to land that for 
another few days, so I can rebase on top of this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58537



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


[PATCH] D58537: lib/Header: Simplify CMakeLists.txt

2019-03-01 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

In D58537#1415534 , @smeenai wrote:

> @tstellar are you planning to land this soon? It'll conflict with D58791 
> , but I'm not planning to land that for 
> another few days, so I can rebase on top of this one.


Yes, I'll push this later today.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58537



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


[PATCH] D58844: Give builtins and alloc/dealloc operators the default calling convention.

2019-03-01 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rC Clang

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

https://reviews.llvm.org/D58844



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


[PATCH] D58847: AMDGPU: Fix the mapping of sub group sync scope

2019-03-01 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl created this revision.
kzhuravl added reviewers: b-sumner, rampitec, t-tye.
Herald added subscribers: jfb, tpr, dstuttard, yaxunl, wdng.

Map memory_scope_sub_group to "wavefront" sync scope


https://reviews.llvm.org/D58847

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGenOpenCL/atomic-ops.cl


Index: test/CodeGenOpenCL/atomic-ops.cl
===
--- test/CodeGenOpenCL/atomic-ops.cl
+++ test/CodeGenOpenCL/atomic-ops.cl
@@ -41,7 +41,7 @@
   // CHECK: load atomic i32, i32* %{{[.0-9A-Z_a-z]+}} seq_cst
   x = __opencl_atomic_load(i, memory_order_seq_cst, 
memory_scope_all_svm_devices);
 
-  // CHECK: load atomic i32, i32* %{{[.0-9A-Z_a-z]+}} syncscope("subgroup") 
seq_cst
+  // CHECK: load atomic i32, i32* %{{[.0-9A-Z_a-z]+}} syncscope("wavefront") 
seq_cst
   x = __opencl_atomic_load(i, memory_order_seq_cst, memory_scope_sub_group);
 }
 
@@ -109,7 +109,7 @@
   // CHECK: load atomic i32, i32* %{{.*}} seq_cst
   // CHECK: br label %[[continue]]
   // CHECK: [[opencl_subgroup]]:
-  // CHECK: load atomic i32, i32* %{{.*}} syncscope("subgroup") seq_cst
+  // CHECK: load atomic i32, i32* %{{.*}} syncscope("wavefront") seq_cst
   // CHECK: br label %[[continue]]
   // CHECK: [[continue]]:
   int x = __opencl_atomic_load(i, memory_order_seq_cst, scope);
@@ -147,7 +147,7 @@
   // CHECK: [[MON_ALL]]:
   // CHECK: load atomic i32, i32* %{{.*}} monotonic
   // CHECK: [[MON_SUB]]:
-  // CHECK: load atomic i32, i32* %{{.*}} syncscope("subgroup") monotonic
+  // CHECK: load atomic i32, i32* %{{.*}} syncscope("wavefront") monotonic
   // CHECK: [[ACQ_WG]]:
   // CHECK: load atomic i32, i32* %{{.*}} syncscope("workgroup") acquire
   // CHECK: [[ACQ_DEV]]:
@@ -155,7 +155,7 @@
   // CHECK: [[ACQ_ALL]]:
   // CHECK: load atomic i32, i32* %{{.*}} acquire
   // CHECK: [[ACQ_SUB]]:
-  // CHECK: load atomic i32, i32* %{{.*}} syncscope("subgroup") acquire
+  // CHECK: load atomic i32, i32* %{{.*}} syncscope("wavefront") acquire
   // CHECK: [[SEQ_WG]]:
   // CHECK: load atomic i32, i32* %{{.*}} syncscope("workgroup") seq_cst
   // CHECK: [[SEQ_DEV]]:
@@ -163,7 +163,7 @@
   // CHECK: [[SEQ_ALL]]:
   // CHECK: load atomic i32, i32* %{{.*}} seq_cst
   // CHECK: [[SEQ_SUB]]:
-  // CHECK: load atomic i32, i32* %{{.*}} syncscope("subgroup") seq_cst
+  // CHECK: load atomic i32, i32* %{{.*}} syncscope("wavefront") seq_cst
   int x = __opencl_atomic_load(i, order, scope);
 }
 
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -7959,7 +7959,7 @@
 Name = "";
 break;
   case SyncScope::OpenCLSubGroup:
-Name = "subgroup";
+Name = "wavefront";
   }
   return C.getOrInsertSyncScopeID(Name);
 }


Index: test/CodeGenOpenCL/atomic-ops.cl
===
--- test/CodeGenOpenCL/atomic-ops.cl
+++ test/CodeGenOpenCL/atomic-ops.cl
@@ -41,7 +41,7 @@
   // CHECK: load atomic i32, i32* %{{[.0-9A-Z_a-z]+}} seq_cst
   x = __opencl_atomic_load(i, memory_order_seq_cst, memory_scope_all_svm_devices);
 
-  // CHECK: load atomic i32, i32* %{{[.0-9A-Z_a-z]+}} syncscope("subgroup") seq_cst
+  // CHECK: load atomic i32, i32* %{{[.0-9A-Z_a-z]+}} syncscope("wavefront") seq_cst
   x = __opencl_atomic_load(i, memory_order_seq_cst, memory_scope_sub_group);
 }
 
@@ -109,7 +109,7 @@
   // CHECK: load atomic i32, i32* %{{.*}} seq_cst
   // CHECK: br label %[[continue]]
   // CHECK: [[opencl_subgroup]]:
-  // CHECK: load atomic i32, i32* %{{.*}} syncscope("subgroup") seq_cst
+  // CHECK: load atomic i32, i32* %{{.*}} syncscope("wavefront") seq_cst
   // CHECK: br label %[[continue]]
   // CHECK: [[continue]]:
   int x = __opencl_atomic_load(i, memory_order_seq_cst, scope);
@@ -147,7 +147,7 @@
   // CHECK: [[MON_ALL]]:
   // CHECK: load atomic i32, i32* %{{.*}} monotonic
   // CHECK: [[MON_SUB]]:
-  // CHECK: load atomic i32, i32* %{{.*}} syncscope("subgroup") monotonic
+  // CHECK: load atomic i32, i32* %{{.*}} syncscope("wavefront") monotonic
   // CHECK: [[ACQ_WG]]:
   // CHECK: load atomic i32, i32* %{{.*}} syncscope("workgroup") acquire
   // CHECK: [[ACQ_DEV]]:
@@ -155,7 +155,7 @@
   // CHECK: [[ACQ_ALL]]:
   // CHECK: load atomic i32, i32* %{{.*}} acquire
   // CHECK: [[ACQ_SUB]]:
-  // CHECK: load atomic i32, i32* %{{.*}} syncscope("subgroup") acquire
+  // CHECK: load atomic i32, i32* %{{.*}} syncscope("wavefront") acquire
   // CHECK: [[SEQ_WG]]:
   // CHECK: load atomic i32, i32* %{{.*}} syncscope("workgroup") seq_cst
   // CHECK: [[SEQ_DEV]]:
@@ -163,7 +163,7 @@
   // CHECK: [[SEQ_ALL]]:
   // CHECK: load atomic i32, i32* %{{.*}} seq_cst
   // CHECK: [[SEQ_SUB]]:
-  // CHECK: load atomic i32, i32* %{{.*}} syncscope("subgroup") seq_cst
+  // CHECK: load atomic i32, i32* %{{.*}} syncscope("wavefront") seq_cst
   int x = __opencl_atomic_load(i, order, scope);
 }
 
Index: lib/CodeGen/TargetInfo.cpp

[PATCH] D58321: [WIP] Support for relative vtables

2019-03-01 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 188973.
leonardchan added a comment.
Herald added subscribers: llvm-commits, MaskRay, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Update to current working version without needing LTO


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58321

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/VTableBuilder.h
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CGVTables.h
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenCXX/debug-info-virtual-fn-relative.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  clang/test/CodeGenCXX/vtable-relative-abi.cpp
  clang/test/Driver/unstable-cxx-abi-vtables.cpp
  lld/ELF/Relocations.cpp

Index: lld/ELF/Relocations.cpp
===
--- lld/ELF/Relocations.cpp
+++ lld/ELF/Relocations.cpp
@@ -908,7 +908,7 @@
   }
 
   // Copy relocations are only possible if we are creating an executable.
-  if (Config->Shared) {
+  if (Config->Shared && Type == Target->CopyRel) {
 errorOrWarn("relocation " + toString(Type) +
 " cannot be used against symbol " + toString(Sym) +
 "; recompile with -fPIC" + getLocation(Sec, Sym, Offset));
Index: clang/test/Driver/unstable-cxx-abi-vtables.cpp
===
--- /dev/null
+++ clang/test/Driver/unstable-cxx-abi-vtables.cpp
@@ -0,0 +1,2 @@
+// RUN: %clang -flto -flto-relative-c++-abi-vtables -### %s 2>&1 | FileCheck -check-prefix=LTO-CLASSES %s
+// LTO-CLASSES: "-flto-relative-c++-abi-vtables"
Index: clang/test/CodeGenCXX/vtable-relative-abi.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/vtable-relative-abi.cpp
@@ -0,0 +1,123 @@
+// RUN: %clang_cc1 %s -flto -flto-unit -triple x86_64-unknown-linux-gnu -fvisibility hidden -flto-relative-c++-abi-vtables -emit-llvm -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-ITANIUM %s
+// RUN: %clang_cc1 %s -flto -flto-unit -triple x86_64-unknown-windows-msvc -flto-relative-c++-abi-vtables -emit-llvm -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MS %s
+// RUN: %clang_cc1 %s -flto -flto-unit -triple x86_64-unknown-linux-gnu -fvisibility hidden -emit-llvm -o - | FileCheck --check-prefix=CHECK-NOABI %s
+
+// CHECK-ITANIUM: @_ZTV1S = hidden unnamed_addr constant { { i8*, i8*, i32, i32 } } { { i8*, i8*, i32, i32 } { i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI1S to i8*), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.S*)* @_ZN1S2f1Ev to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i8*, i32, i32 } }, { { i8*, i8*, i32, i32 } }* @_ZTV1S, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.S*)* @_ZN1S2f2Ev to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i8*, i32, i32 } }, { { i8*, i8*, i32, i32 } }* @_ZTV1S, i32 0, i32 0, i32 3) to i64)) to i32) } }, align 8
+// CHECK-MS: @anon.[[NUM:[a-z0-9]+]].0 = private unnamed_addr constant { { i8*, i32, i32 } } { { i8*, i32, i32 } { i8* bitcast (%rtti.CompleteObjectLocator* @"??_R4S@@6B@" to i8*), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.S*)* @"?f1@S@@UEAAXXZ" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i32, i32 } }, { { i8*, i32, i32 } }* @anon.[[NUM]].0, i32 0, i32 0, i32 1) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.S*)* @"?f2@S@@UEAAXXZ" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i32, i32 } }, { { i8*, i32, i32 } }* @anon.[[NUM]].0, i32 0, i32 0, i32 2) to i64)) to i32) } }, comdat($"??_7S@@6B@")
+struct S {
+  S();
+  virtual void f1();
+  virtual void f2();
+};
+
+// CHECK-ITANIUM: @_ZTV1T = hidden unnamed_addr constant { { i8*, i8*, i32 } } { { i8*, i8*, i32 } { i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI1T to i8*), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.T*)* @_ZN1T1gEv to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i8*, i32 } }, { { i8*, i8*, i32 } }* @_ZTV1T, i32 0, i32 0, i32 2) to i64)) to i32) } }, align 8
+// CHECK-MS: @anon.[[NUM]].1 = private unnamed_addr constant { { i8*, i32 } } { { i8*, i32 } { i8* bitcast (%rtti.CompleteObjectLocator* @"??_R4T@@6B@" to i8*), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.T*)* @"?g@T@@UEAAXXZ" to i64), i64 ptrtoint (i32* getelementp

[PATCH] D58321: [WIP] Support for relative vtables

2019-03-01 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 188975.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58321

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/VTableBuilder.h
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CGVTables.h
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenCXX/debug-info-virtual-fn-relative.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  clang/test/CodeGenCXX/vtable-relative-abi.cpp
  clang/test/Driver/unstable-cxx-abi-vtables.cpp
  lld/ELF/Relocations.cpp

Index: lld/ELF/Relocations.cpp
===
--- lld/ELF/Relocations.cpp
+++ lld/ELF/Relocations.cpp
@@ -908,7 +908,7 @@
   }
 
   // Copy relocations are only possible if we are creating an executable.
-  if (Config->Shared) {
+  if (Config->Shared && Type == Target->CopyRel) {
 errorOrWarn("relocation " + toString(Type) +
 " cannot be used against symbol " + toString(Sym) +
 "; recompile with -fPIC" + getLocation(Sec, Sym, Offset));
Index: clang/test/Driver/unstable-cxx-abi-vtables.cpp
===
--- /dev/null
+++ clang/test/Driver/unstable-cxx-abi-vtables.cpp
@@ -0,0 +1,2 @@
+// RUN: %clang -flto -flto-relative-c++-abi-vtables -### %s 2>&1 | FileCheck -check-prefix=LTO-CLASSES %s
+// LTO-CLASSES: "-flto-relative-c++-abi-vtables"
Index: clang/test/CodeGenCXX/vtable-relative-abi.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/vtable-relative-abi.cpp
@@ -0,0 +1,123 @@
+// RUN: %clang_cc1 %s -flto -flto-unit -triple x86_64-unknown-linux-gnu -fvisibility hidden -flto-relative-c++-abi-vtables -emit-llvm -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-ITANIUM %s
+// RUN: %clang_cc1 %s -flto -flto-unit -triple x86_64-unknown-windows-msvc -flto-relative-c++-abi-vtables -emit-llvm -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MS %s
+// RUN: %clang_cc1 %s -flto -flto-unit -triple x86_64-unknown-linux-gnu -fvisibility hidden -emit-llvm -o - | FileCheck --check-prefix=CHECK-NOABI %s
+
+// CHECK-ITANIUM: @_ZTV1S = hidden unnamed_addr constant { { i8*, i8*, i32, i32 } } { { i8*, i8*, i32, i32 } { i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI1S to i8*), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.S*)* @_ZN1S2f1Ev to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i8*, i32, i32 } }, { { i8*, i8*, i32, i32 } }* @_ZTV1S, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.S*)* @_ZN1S2f2Ev to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i8*, i32, i32 } }, { { i8*, i8*, i32, i32 } }* @_ZTV1S, i32 0, i32 0, i32 3) to i64)) to i32) } }, align 8
+// CHECK-MS: @anon.[[NUM:[a-z0-9]+]].0 = private unnamed_addr constant { { i8*, i32, i32 } } { { i8*, i32, i32 } { i8* bitcast (%rtti.CompleteObjectLocator* @"??_R4S@@6B@" to i8*), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.S*)* @"?f1@S@@UEAAXXZ" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i32, i32 } }, { { i8*, i32, i32 } }* @anon.[[NUM]].0, i32 0, i32 0, i32 1) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.S*)* @"?f2@S@@UEAAXXZ" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i32, i32 } }, { { i8*, i32, i32 } }* @anon.[[NUM]].0, i32 0, i32 0, i32 2) to i64)) to i32) } }, comdat($"??_7S@@6B@")
+struct S {
+  S();
+  virtual void f1();
+  virtual void f2();
+};
+
+// CHECK-ITANIUM: @_ZTV1T = hidden unnamed_addr constant { { i8*, i8*, i32 } } { { i8*, i8*, i32 } { i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI1T to i8*), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.T*)* @_ZN1T1gEv to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i8*, i32 } }, { { i8*, i8*, i32 } }* @_ZTV1T, i32 0, i32 0, i32 2) to i64)) to i32) } }, align 8
+// CHECK-MS: @anon.[[NUM]].1 = private unnamed_addr constant { { i8*, i32 } } { { i8*, i32 } { i8* bitcast (%rtti.CompleteObjectLocator* @"??_R4T@@6B@" to i8*), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.T*)* @"?g@T@@UEAAXXZ" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i32 } }, { { i8*, i32 } }* @anon.[[NUM]].1, i32 0, i32 0, i32 1) to i64)) to i32) } }, comdat($"??_7T@@6B@")
+struct T {
+  T();
+  virtual void g();
+};
+
+// CHECK-ITANIUM: @_ZTV1U = hidden unnamed

[PATCH] D58814: [clang][Index] Constructors and Destructors do not reference class

2019-03-01 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added a comment.

> These references were added to support using the index data for symbol rename.

Understood -- thank you for providing the context (the original commit that 
added this code didn't have the explanation why this reference was added).  
However, my suggestion would be to still take this patch.  For symbol rename, 
my suggestion would be one of the following.

Option (1): Symbol rename is a complex operation that requires knowing many 
places where the class name appears.  So I think it is fair that it would need 
to navigate to all such declarations using the semantic index -- find the 
class, then find its constructors, destructor, out-of-line functions, find 
derived classes, then find `using` declarations in derived classes, find calls 
to constructors, destructor etc.  I don't think it is not the job of the core 
indexer API to hardcode all of these places as a "reference to the class".  
Different clients require different navigation to related symbols, and 
hardcoding all such navigation patterns in the indexer would create a messy 
index that is difficult to work with, since you'd have to filter out lots of 
stuff.  Not to even mention the index size.

Option (2): A client that wants to hardcode all navigation patterns in the 
index can still do this -- in the `IndexDataConsumer`, it is possible to handle 
the `ConstructorDecl` as a reference to the class, if desired.  The flow of the 
indexing information becomes more clear in my opinion: when there is a 
constructor decl in the source, the `IndexDataConsumer` gets one 
`ConstructorDecl`. Then the specific implementation of `IndexDataConsumer` 
decides to treat it also as a class reference, because it wants to support a 
specific approach to performing symbol renaming.

As is, the indexing information is misleading and surprising.  When we see a 
constructor decl or a constructor call, there is no reference to the class at 
that point -- there is a reference to a constructor.  I think index is supposed 
to expose semantic information, not just that there's a token in the source 
code that has the same spelling as the class name.

> could we instead distinguish these cases with a more specific SymbolRole, 
> e.g. NameReference as opposed to Reference, and filter them based on that 
> instead?

It feels like a workaround to me, that also pushes the fix to the clients of 
the indexing API. The core of the problem still exists: the indexing 
information is surprising, and requires extra work on the client to make it not 
surprising (filtering out NameReferences).


Repository:
  rC Clang

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

https://reviews.llvm.org/D58814



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


[PATCH] D58847: AMDGPU: Fix the mapping of sub group sync scope

2019-03-01 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec accepted this revision.
rampitec added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D58847



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


[PATCH] D58743: Handle built-in when importing SourceLocation and FileID

2019-03-01 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor accepted this revision.
teemperor added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


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

https://reviews.llvm.org/D58743



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


[PATCH] D58819: [clang-format] clang-format off/on not respected when using C Style comments

2019-03-01 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG


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

https://reviews.llvm.org/D58819



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


[PATCH] D58321: [WIP] Support for relative vtables

2019-03-01 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 188987.
leonardchan added a comment.

- Remove `hasHiddenLTOVisibility` from `CXXRecordDecl` and rename the flag to 
`-frelative-c++-abi-vtables`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58321

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/VTableBuilder.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CGVTables.h
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenCXX/debug-info-virtual-fn-relative.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  clang/test/CodeGenCXX/vtable-relative-abi.cpp
  clang/test/Driver/unstable-cxx-abi-vtables.cpp
  lld/ELF/Relocations.cpp

Index: lld/ELF/Relocations.cpp
===
--- lld/ELF/Relocations.cpp
+++ lld/ELF/Relocations.cpp
@@ -908,7 +908,7 @@
   }
 
   // Copy relocations are only possible if we are creating an executable.
-  if (Config->Shared) {
+  if (Config->Shared && Type == Target->CopyRel) {
 errorOrWarn("relocation " + toString(Type) +
 " cannot be used against symbol " + toString(Sym) +
 "; recompile with -fPIC" + getLocation(Sec, Sym, Offset));
Index: clang/test/Driver/unstable-cxx-abi-vtables.cpp
===
--- /dev/null
+++ clang/test/Driver/unstable-cxx-abi-vtables.cpp
@@ -0,0 +1,2 @@
+// RUN: %clang -flto -frelative-c++-abi-vtables -### %s 2>&1 | FileCheck -check-prefix=LTO-CLASSES %s
+// LTO-CLASSES: "-frelative-c++-abi-vtables"
Index: clang/test/CodeGenCXX/vtable-relative-abi.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/vtable-relative-abi.cpp
@@ -0,0 +1,123 @@
+// RUN: %clang_cc1 %s -flto -flto-unit -triple x86_64-unknown-linux-gnu -fvisibility hidden -frelative-c++-abi-vtables -emit-llvm -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-ITANIUM %s
+// RUN: %clang_cc1 %s -flto -flto-unit -triple x86_64-unknown-windows-msvc -frelative-c++-abi-vtables -emit-llvm -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MS %s
+// RUN: %clang_cc1 %s -flto -flto-unit -triple x86_64-unknown-linux-gnu -fvisibility hidden -emit-llvm -o - | FileCheck --check-prefix=CHECK-NOABI %s
+
+// CHECK-ITANIUM: @_ZTV1S = hidden unnamed_addr constant { { i8*, i8*, i32, i32 } } { { i8*, i8*, i32, i32 } { i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI1S to i8*), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.S*)* @_ZN1S2f1Ev to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i8*, i32, i32 } }, { { i8*, i8*, i32, i32 } }* @_ZTV1S, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.S*)* @_ZN1S2f2Ev to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i8*, i32, i32 } }, { { i8*, i8*, i32, i32 } }* @_ZTV1S, i32 0, i32 0, i32 3) to i64)) to i32) } }, align 8
+// CHECK-MS: @anon.[[NUM:[a-z0-9]+]].0 = private unnamed_addr constant { { i8*, i32, i32 } } { { i8*, i32, i32 } { i8* bitcast (%rtti.CompleteObjectLocator* @"??_R4S@@6B@" to i8*), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.S*)* @"?f1@S@@UEAAXXZ" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i32, i32 } }, { { i8*, i32, i32 } }* @anon.[[NUM]].0, i32 0, i32 0, i32 1) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.S*)* @"?f2@S@@UEAAXXZ" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i32, i32 } }, { { i8*, i32, i32 } }* @anon.[[NUM]].0, i32 0, i32 0, i32 2) to i64)) to i32) } }, comdat($"??_7S@@6B@")
+struct S {
+  S();
+  virtual void f1();
+  virtual void f2();
+};
+
+// CHECK-ITANIUM: @_ZTV1T = hidden unnamed_addr constant { { i8*, i8*, i32 } } { { i8*, i8*, i32 } { i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI1T to i8*), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.T*)* @_ZN1T1gEv to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i8*, i32 } }, { { i8*, i8*, i32 } }* @_ZTV1T, i32 0, i32 0, i32 2) to i64)) to i32) } }, align 8
+// CHECK-MS: @anon.[[NUM]].1 = private unnamed_addr constant { { i8*, i32 } } { { i8*, i32 } { i8* bitcast (%rtti.CompleteObjectLocator* @"??_R4T@@6B@" to i8*), i32 trunc (i64 sub (i64 ptrtoint (void (%struct.T*)* @"?g@T@@UEAAXXZ" to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i32 } }, { { i8*, i32 } }* @anon.[[NUM]].1, i32 0, i32 0, i32 1) to i64)) to i32) } }, comdat($"??_7T@@6B@")
+struct T {
+ 

[PATCH] D58321: [WIP] Support for relative vtables

2019-03-01 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

I think that you need to update the serialization code in 
`Serialization/ASTReaderDecl.cpp` and `Serialization/ASTWriterDecl.cpp` to 
account for the new flag.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58321



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


[PATCH] D58374: [Clang][NewPM] Don't bail out if the target machine is empty

2019-03-01 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 188999.
phosek marked an inline comment as done.
Herald added a subscriber: dschuff.

Repository:
  rC Clang

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

https://reviews.llvm.org/D58374

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/spir-half-type.cpp
  clang/test/Driver/le32-unknown-nacl.cpp


Index: clang/test/Driver/le32-unknown-nacl.cpp
===
--- clang/test/Driver/le32-unknown-nacl.cpp
+++ clang/test/Driver/le32-unknown-nacl.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang -target le32-unknown-nacl -### %s -emit-llvm-only -c 2>&1 | 
FileCheck %s -check-prefix=ECHO
 // RUN: %clang -target le32-unknown-nacl %s -emit-llvm -S -c -o - | FileCheck 
%s
+// RUN: %clang -target le32-unknown-nacl -fexperimental-new-pass-manager %s 
-emit-llvm -S -c -o - | FileCheck %s
 // RUN: %clang -target le32-unknown-nacl %s -emit-llvm -S -c -pthread -o - | 
FileCheck %s -check-prefix=THREADS
 
 // ECHO: {{.*}} "-cc1" {{.*}}le32-unknown-nacl.c
Index: clang/test/CodeGen/spir-half-type.cpp
===
--- clang/test/CodeGen/spir-half-type.cpp
+++ clang/test/CodeGen/spir-half-type.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -O0 -triple spir -emit-llvm %s -o - | FileCheck %s
 // RUN: %clang_cc1 -O0 -triple spir64 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir -fexperimental-new-pass-manager -emit-llvm 
%s -o - | FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir64 -fexperimental-new-pass-manager 
-emit-llvm %s -o - | FileCheck %s
 
 // This file tests that using the _Float16 type with the spir target will not
 // use the llvm intrinsics but instead will use the half arithmetic
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -955,13 +955,15 @@
   TimeRegion Region(FrontendTimesIsEnabled ? &CodeGenerationTime : nullptr);
   setCommandLineOpts(CodeGenOpts);
 
-  // The new pass manager always makes a target machine available to passes
-  // during construction.
-  CreateTargetMachine(/*MustCreateTM*/ true);
-  if (!TM)
-// This will already be diagnosed, just bail.
+  bool RequiresCodeGen = (Action != Backend_EmitNothing &&
+  Action != Backend_EmitBC &&
+  Action != Backend_EmitLL);
+  CreateTargetMachine(RequiresCodeGen);
+
+  if (RequiresCodeGen && !TM)
 return;
-  TheModule->setDataLayout(TM->createDataLayout());
+  if (TM)
+TheModule->setDataLayout(TM->createDataLayout());
 
   Optional PGOOpt;
 


Index: clang/test/Driver/le32-unknown-nacl.cpp
===
--- clang/test/Driver/le32-unknown-nacl.cpp
+++ clang/test/Driver/le32-unknown-nacl.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang -target le32-unknown-nacl -### %s -emit-llvm-only -c 2>&1 | FileCheck %s -check-prefix=ECHO
 // RUN: %clang -target le32-unknown-nacl %s -emit-llvm -S -c -o - | FileCheck %s
+// RUN: %clang -target le32-unknown-nacl -fexperimental-new-pass-manager %s -emit-llvm -S -c -o - | FileCheck %s
 // RUN: %clang -target le32-unknown-nacl %s -emit-llvm -S -c -pthread -o - | FileCheck %s -check-prefix=THREADS
 
 // ECHO: {{.*}} "-cc1" {{.*}}le32-unknown-nacl.c
Index: clang/test/CodeGen/spir-half-type.cpp
===
--- clang/test/CodeGen/spir-half-type.cpp
+++ clang/test/CodeGen/spir-half-type.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -O0 -triple spir -emit-llvm %s -o - | FileCheck %s
 // RUN: %clang_cc1 -O0 -triple spir64 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir -fexperimental-new-pass-manager -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir64 -fexperimental-new-pass-manager -emit-llvm %s -o - | FileCheck %s
 
 // This file tests that using the _Float16 type with the spir target will not
 // use the llvm intrinsics but instead will use the half arithmetic
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -955,13 +955,15 @@
   TimeRegion Region(FrontendTimesIsEnabled ? &CodeGenerationTime : nullptr);
   setCommandLineOpts(CodeGenOpts);
 
-  // The new pass manager always makes a target machine available to passes
-  // during construction.
-  CreateTargetMachine(/*MustCreateTM*/ true);
-  if (!TM)
-// This will already be diagnosed, just bail.
+  bool RequiresCodeGen = (Action != Backend_EmitNothing &&
+  Action != Backend_EmitBC &&
+  Action != Backend_EmitLL);
+  CreateTargetMachine(RequiresCodeGen);
+
+  if (RequiresCodeGen && !TM)
 return;
-  TheModule->setDataLayout(TM->createDataLayout());
+  if (TM)
+TheModule->set

[PATCH] D58854: [WebAssembly] Temporarily disable bulk-memory with -pthread

2019-03-01 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added a reviewer: sbc100.
Herald added subscribers: cfe-commits, jfb, sunfish, aheejin, jgravelle-google, 
dschuff.
Herald added a project: clang.
aheejin accepted this revision.
This revision is now accepted and ready to land.

To prevent the instability of bulk-memory in the wasm backend from
blocking separate pthread testing, temporarily remove the logic that
adds -mbulk-memory in the presence of -pthread. Since browsers will
ship bulk memory before or alongside threads, this change will be
reverted as soon as bulk memory has stabilized in the backend.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58854

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.c
  clang/test/Preprocessor/wasm-target-features.c


Index: clang/test/Preprocessor/wasm-target-features.c
===
--- clang/test/Preprocessor/wasm-target-features.c
+++ clang/test/Preprocessor/wasm-target-features.c
@@ -59,8 +59,7 @@
 // RUN: -target wasm64-unknown-unknown -matomics \
 // RUN:   | FileCheck %s -check-prefix=ATOMICS
 //
-// ATOMICS-DAG:#define __wasm_atomics__ 1{{$}}
-// ATOMICS-DAG:#define __wasm_bulk_memory__ 1{{$}}
+// ATOMICS:#define __wasm_atomics__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -pthread \
@@ -69,8 +68,7 @@
 // RUN: -target wasm64-unknown-unknown -pthread \
 // RUN:   | FileCheck %s -check-prefix=PTHREAD
 //
-// PTHREAD-DAG:#define __wasm_atomics__ 1{{$}}
-// PTHREAD-DAG:#define __wasm_bulk_memory__ 1{{$}}
+// PTHREAD:#define __wasm_atomics__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mcpu=mvp \
Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -41,18 +41,10 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics' and '-target-feature 
+bulk-memory'
+// '-pthread' sets '-target-feature +atomics'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread 2>&1 | FileCheck -check-prefix=PTHREAD %s
-// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" 
"-target-feature" "+bulk-memory"
+// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
 
 // '-pthread' not allowed with '-mno-atomics'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread -mno-atomics 2>&1 | FileCheck 
-check-prefix=PTHREAD_NO_ATOMICS %s
 // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with 
'-mno-atomics'
-
-// '-pthread' not allowed with '-mno-bulk-memory'
-// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread -mno-bulk-memory 2>&1 | FileCheck 
-check-prefix=PTHREAD_NO_BULKMEM %s
-// PTHREAD_NO_BULKMEM: invalid argument '-pthread' not allowed with 
'-mno-bulk-memory'
-
-// '-matomics' not allowed with '-mno-bulk-memory'
-// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -matomics -mno-bulk-memory 2>&1 | FileCheck 
-check-prefix=ATOMICS_NO_BULKMEM %s
-// ATOMICS_NO_BULKMEM: invalid argument '-matomics' not allowed with 
'-mno-bulk-memory'
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -124,8 +124,7 @@
  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fuse-init-array");
 
-  // '-pthread' implies '-target-feature +atomics' and
-  // '-target-feature +bulk-memory'
+  // '-pthread' implies '-target-feature +atomics'
   if (DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread,
  false)) {
 if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
@@ -133,27 +132,8 @@
   getDriver().Diag(diag::err_drv_argument_not_allowed_with)
   << "-pthread"
   << "-mno-atomics";
-if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
-   options::OPT_mbulk_memory, false))
-  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
-  << "-pthread"
-  << "-mno-bulk-memory";
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+atomics");
-CC1Args.push_back("-target-feature");
-CC1Args.push_back("+bulk-memory");
-  }
-
-  // '-matomics' implies '-mbulk-memory'
-  if (DriverArgs.hasFlag(options::OPT_matomics, options::OPT_mno_atomics,
- false)) {
-if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
-   options::OPT_mbulk_memory, false))
-  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
-  << "-mato

[PATCH] D58374: [Clang][NewPM] Don't bail out if the target machine is empty

2019-03-01 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D58374#1411376 , @chandlerc wrote:

> Maybe update at least some of the tests using these targets to additionally 
> run with the new pass manager explicitly enabled via flag?


Done


Repository:
  rC Clang

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

https://reviews.llvm.org/D58374



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


[PATCH] D58854: [WebAssembly] Temporarily disable bulk-memory with -pthread

2019-03-01 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC355248: [WebAssembly] Temporarily disable bulk-memory with 
-pthread (authored by tlively, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D58854?vs=188997&id=189000#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D58854

Files:
  lib/Driver/ToolChains/WebAssembly.cpp
  test/Driver/wasm-toolchain.c
  test/Preprocessor/wasm-target-features.c


Index: test/Preprocessor/wasm-target-features.c
===
--- test/Preprocessor/wasm-target-features.c
+++ test/Preprocessor/wasm-target-features.c
@@ -59,8 +59,7 @@
 // RUN: -target wasm64-unknown-unknown -matomics \
 // RUN:   | FileCheck %s -check-prefix=ATOMICS
 //
-// ATOMICS-DAG:#define __wasm_atomics__ 1{{$}}
-// ATOMICS-DAG:#define __wasm_bulk_memory__ 1{{$}}
+// ATOMICS:#define __wasm_atomics__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -pthread \
@@ -69,8 +68,7 @@
 // RUN: -target wasm64-unknown-unknown -pthread \
 // RUN:   | FileCheck %s -check-prefix=PTHREAD
 //
-// PTHREAD-DAG:#define __wasm_atomics__ 1{{$}}
-// PTHREAD-DAG:#define __wasm_bulk_memory__ 1{{$}}
+// PTHREAD:#define __wasm_atomics__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mcpu=mvp \
Index: test/Driver/wasm-toolchain.c
===
--- test/Driver/wasm-toolchain.c
+++ test/Driver/wasm-toolchain.c
@@ -41,18 +41,10 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics' and '-target-feature 
+bulk-memory'
+// '-pthread' sets '-target-feature +atomics'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread 2>&1 | FileCheck -check-prefix=PTHREAD %s
-// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" 
"-target-feature" "+bulk-memory"
+// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
 
 // '-pthread' not allowed with '-mno-atomics'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread -mno-atomics 2>&1 | FileCheck 
-check-prefix=PTHREAD_NO_ATOMICS %s
 // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with 
'-mno-atomics'
-
-// '-pthread' not allowed with '-mno-bulk-memory'
-// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread -mno-bulk-memory 2>&1 | FileCheck 
-check-prefix=PTHREAD_NO_BULKMEM %s
-// PTHREAD_NO_BULKMEM: invalid argument '-pthread' not allowed with 
'-mno-bulk-memory'
-
-// '-matomics' not allowed with '-mno-bulk-memory'
-// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -matomics -mno-bulk-memory 2>&1 | FileCheck 
-check-prefix=ATOMICS_NO_BULKMEM %s
-// ATOMICS_NO_BULKMEM: invalid argument '-matomics' not allowed with 
'-mno-bulk-memory'
Index: lib/Driver/ToolChains/WebAssembly.cpp
===
--- lib/Driver/ToolChains/WebAssembly.cpp
+++ lib/Driver/ToolChains/WebAssembly.cpp
@@ -124,8 +124,7 @@
  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fuse-init-array");
 
-  // '-pthread' implies '-target-feature +atomics' and
-  // '-target-feature +bulk-memory'
+  // '-pthread' implies '-target-feature +atomics'
   if (DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread,
  false)) {
 if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
@@ -133,27 +132,8 @@
   getDriver().Diag(diag::err_drv_argument_not_allowed_with)
   << "-pthread"
   << "-mno-atomics";
-if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
-   options::OPT_mbulk_memory, false))
-  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
-  << "-pthread"
-  << "-mno-bulk-memory";
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+atomics");
-CC1Args.push_back("-target-feature");
-CC1Args.push_back("+bulk-memory");
-  }
-
-  // '-matomics' implies '-mbulk-memory'
-  if (DriverArgs.hasFlag(options::OPT_matomics, options::OPT_mno_atomics,
- false)) {
-if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
-   options::OPT_mbulk_memory, false))
-  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
-  << "-matomics"
-  << "-mno-bulk-memory";
-CC1Args.push_back("-target-feature");
-CC1Args.push_back("+bulk-memory");
   }
 }
 


Index: test/Preprocessor/wasm-target-features.c
===
--- test/Preprocessor/wasm-target-features.c
+++ test/Preprocessor/wasm-target-features.

r355248 - [WebAssembly] Temporarily disable bulk-memory with -pthread

2019-03-01 Thread Thomas Lively via cfe-commits
Author: tlively
Date: Fri Mar  1 16:18:09 2019
New Revision: 355248

URL: http://llvm.org/viewvc/llvm-project?rev=355248&view=rev
Log:
[WebAssembly] Temporarily disable bulk-memory with -pthread

Summary:
To prevent the instability of bulk-memory in the wasm backend from
blocking separate pthread testing, temporarily remove the logic that
adds -mbulk-memory in the presence of -pthread. Since browsers will
ship bulk memory before or alongside threads, this change will be
reverted as soon as bulk memory has stabilized in the backend.

Reviewers: sbc100

Subscribers: dschuff, jgravelle-google, aheejin, sunfish, jfb, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
cfe/trunk/test/Driver/wasm-toolchain.c
cfe/trunk/test/Preprocessor/wasm-target-features.c

Modified: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp?rev=355248&r1=355247&r2=355248&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp Fri Mar  1 16:18:09 2019
@@ -124,8 +124,7 @@ void WebAssembly::addClangTargetOptions(
  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fuse-init-array");
 
-  // '-pthread' implies '-target-feature +atomics' and
-  // '-target-feature +bulk-memory'
+  // '-pthread' implies '-target-feature +atomics'
   if (DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread,
  false)) {
 if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
@@ -133,27 +132,8 @@ void WebAssembly::addClangTargetOptions(
   getDriver().Diag(diag::err_drv_argument_not_allowed_with)
   << "-pthread"
   << "-mno-atomics";
-if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
-   options::OPT_mbulk_memory, false))
-  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
-  << "-pthread"
-  << "-mno-bulk-memory";
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+atomics");
-CC1Args.push_back("-target-feature");
-CC1Args.push_back("+bulk-memory");
-  }
-
-  // '-matomics' implies '-mbulk-memory'
-  if (DriverArgs.hasFlag(options::OPT_matomics, options::OPT_mno_atomics,
- false)) {
-if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
-   options::OPT_mbulk_memory, false))
-  getDriver().Diag(diag::err_drv_argument_not_allowed_with)
-  << "-matomics"
-  << "-mno-bulk-memory";
-CC1Args.push_back("-target-feature");
-CC1Args.push_back("+bulk-memory");
   }
 }
 

Modified: cfe/trunk/test/Driver/wasm-toolchain.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/wasm-toolchain.c?rev=355248&r1=355247&r2=355248&view=diff
==
--- cfe/trunk/test/Driver/wasm-toolchain.c (original)
+++ cfe/trunk/test/Driver/wasm-toolchain.c Fri Mar  1 16:18:09 2019
@@ -41,18 +41,10 @@
 
 // Thread-related command line tests.
 
-// '-pthread' sets '-target-feature +atomics' and '-target-feature 
+bulk-memory'
+// '-pthread' sets '-target-feature +atomics'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread 2>&1 | FileCheck -check-prefix=PTHREAD %s
-// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" 
"-target-feature" "+bulk-memory"
+// PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics"
 
 // '-pthread' not allowed with '-mno-atomics'
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread -mno-atomics 2>&1 | FileCheck 
-check-prefix=PTHREAD_NO_ATOMICS %s
 // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with 
'-mno-atomics'
-
-// '-pthread' not allowed with '-mno-bulk-memory'
-// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -pthread -mno-bulk-memory 2>&1 | FileCheck 
-check-prefix=PTHREAD_NO_BULKMEM %s
-// PTHREAD_NO_BULKMEM: invalid argument '-pthread' not allowed with 
'-mno-bulk-memory'
-
-// '-matomics' not allowed with '-mno-bulk-memory'
-// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s -matomics -mno-bulk-memory 2>&1 | FileCheck 
-check-prefix=ATOMICS_NO_BULKMEM %s
-// ATOMICS_NO_BULKMEM: invalid argument '-matomics' not allowed with 
'-mno-bulk-memory'

Modified: cfe/trunk/test/Preprocessor/wasm-target-features.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/wasm-target-features.c?rev=355248&r1=355247&r2=355248&view=diff
==
--- cfe/trunk/test/Preprocessor/wasm-

[PATCH] D57986: [ProfileData] Sort FuncData before iteration to remove non-determinism

2019-03-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/ProfileData/InstrProfWriter.cpp:431-432
+  for (const auto &record : OrderedFuncData) {
+const auto &name = record.first;
+const auto &Func = record.second;
+writeRecordInText(name, Func.first, Func.second, Symtab, OS);

Inconsistent variable naming? (some start with upper case, some with lower case)

Currently I think the LLVM style says upper case is required.

Naming the types here might be reasonable for readability, but I'm not sure.


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

https://reviews.llvm.org/D57986



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


[PATCH] D57986: [ProfileData] Sort FuncData before iteration to remove non-determinism

2019-03-01 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 189002.
mgrang added a comment.

Addressed comments.


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

https://reviews.llvm.org/D57986

Files:
  lib/ProfileData/InstrProfWriter.cpp


Index: lib/ProfileData/InstrProfWriter.cpp
===
--- lib/ProfileData/InstrProfWriter.cpp
+++ lib/ProfileData/InstrProfWriter.cpp
@@ -408,14 +408,30 @@
   else if (ProfileKind == PF_IRLevelWithCS)
 OS << "# CSIR level Instrumentation Flag\n:csir\n";
   InstrProfSymtab Symtab;
-  for (const auto &I : FunctionData)
-if (shouldEncodeData(I.getValue()))
+
+  using FuncPair = detail::DenseMapPair;
+  using RecordType = std::pair;
+  SmallVector OrderedFuncData;
+
+  for (const auto &I : FunctionData) {
+if (shouldEncodeData(I.getValue())) {
   if (Error E = Symtab.addFuncName(I.getKey()))
 return E;
-
-  for (const auto &I : FunctionData)
-if (shouldEncodeData(I.getValue()))
   for (const auto &Func : I.getValue())
-writeRecordInText(I.getKey(), Func.first, Func.second, Symtab, OS);
+OrderedFuncData.push_back(std::make_pair(I.getKey(), Func));
+}
+  }
+
+  llvm::sort(OrderedFuncData, [](const RecordType &A, const RecordType &B) {
+return std::tie(A.first, A.second.first) <
+   std::tie(B.first, B.second.first);
+  });
+
+  for (const auto &record : OrderedFuncData) {
+const StringRef &Name = record.first;
+const FuncPair &Func = record.second;
+writeRecordInText(Name, Func.first, Func.second, Symtab, OS);
+  }
+
   return Error::success();
 }


Index: lib/ProfileData/InstrProfWriter.cpp
===
--- lib/ProfileData/InstrProfWriter.cpp
+++ lib/ProfileData/InstrProfWriter.cpp
@@ -408,14 +408,30 @@
   else if (ProfileKind == PF_IRLevelWithCS)
 OS << "# CSIR level Instrumentation Flag\n:csir\n";
   InstrProfSymtab Symtab;
-  for (const auto &I : FunctionData)
-if (shouldEncodeData(I.getValue()))
+
+  using FuncPair = detail::DenseMapPair;
+  using RecordType = std::pair;
+  SmallVector OrderedFuncData;
+
+  for (const auto &I : FunctionData) {
+if (shouldEncodeData(I.getValue())) {
   if (Error E = Symtab.addFuncName(I.getKey()))
 return E;
-
-  for (const auto &I : FunctionData)
-if (shouldEncodeData(I.getValue()))
   for (const auto &Func : I.getValue())
-writeRecordInText(I.getKey(), Func.first, Func.second, Symtab, OS);
+OrderedFuncData.push_back(std::make_pair(I.getKey(), Func));
+}
+  }
+
+  llvm::sort(OrderedFuncData, [](const RecordType &A, const RecordType &B) {
+return std::tie(A.first, A.second.first) <
+   std::tie(B.first, B.second.first);
+  });
+
+  for (const auto &record : OrderedFuncData) {
+const StringRef &Name = record.first;
+const FuncPair &Func = record.second;
+writeRecordInText(Name, Func.first, Func.second, Symtab, OS);
+  }
+
   return Error::success();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57986: [ProfileData] Sort FuncData before iteration to remove non-determinism

2019-03-01 Thread Mandeep Singh Grang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL355252: [ProfileData] Sort FuncData before iteration to 
remove non-determinism (authored by mgrang, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D57986?vs=189002&id=189009#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D57986

Files:
  llvm/trunk/lib/ProfileData/InstrProfWriter.cpp


Index: llvm/trunk/lib/ProfileData/InstrProfWriter.cpp
===
--- llvm/trunk/lib/ProfileData/InstrProfWriter.cpp
+++ llvm/trunk/lib/ProfileData/InstrProfWriter.cpp
@@ -408,14 +408,30 @@
   else if (ProfileKind == PF_IRLevelWithCS)
 OS << "# CSIR level Instrumentation Flag\n:csir\n";
   InstrProfSymtab Symtab;
-  for (const auto &I : FunctionData)
-if (shouldEncodeData(I.getValue()))
+
+  using FuncPair = detail::DenseMapPair;
+  using RecordType = std::pair;
+  SmallVector OrderedFuncData;
+
+  for (const auto &I : FunctionData) {
+if (shouldEncodeData(I.getValue())) {
   if (Error E = Symtab.addFuncName(I.getKey()))
 return E;
-
-  for (const auto &I : FunctionData)
-if (shouldEncodeData(I.getValue()))
   for (const auto &Func : I.getValue())
-writeRecordInText(I.getKey(), Func.first, Func.second, Symtab, OS);
+OrderedFuncData.push_back(std::make_pair(I.getKey(), Func));
+}
+  }
+
+  llvm::sort(OrderedFuncData, [](const RecordType &A, const RecordType &B) {
+return std::tie(A.first, A.second.first) <
+   std::tie(B.first, B.second.first);
+  });
+
+  for (const auto &record : OrderedFuncData) {
+const StringRef &Name = record.first;
+const FuncPair &Func = record.second;
+writeRecordInText(Name, Func.first, Func.second, Symtab, OS);
+  }
+
   return Error::success();
 }


Index: llvm/trunk/lib/ProfileData/InstrProfWriter.cpp
===
--- llvm/trunk/lib/ProfileData/InstrProfWriter.cpp
+++ llvm/trunk/lib/ProfileData/InstrProfWriter.cpp
@@ -408,14 +408,30 @@
   else if (ProfileKind == PF_IRLevelWithCS)
 OS << "# CSIR level Instrumentation Flag\n:csir\n";
   InstrProfSymtab Symtab;
-  for (const auto &I : FunctionData)
-if (shouldEncodeData(I.getValue()))
+
+  using FuncPair = detail::DenseMapPair;
+  using RecordType = std::pair;
+  SmallVector OrderedFuncData;
+
+  for (const auto &I : FunctionData) {
+if (shouldEncodeData(I.getValue())) {
   if (Error E = Symtab.addFuncName(I.getKey()))
 return E;
-
-  for (const auto &I : FunctionData)
-if (shouldEncodeData(I.getValue()))
   for (const auto &Func : I.getValue())
-writeRecordInText(I.getKey(), Func.first, Func.second, Symtab, OS);
+OrderedFuncData.push_back(std::make_pair(I.getKey(), Func));
+}
+  }
+
+  llvm::sort(OrderedFuncData, [](const RecordType &A, const RecordType &B) {
+return std::tie(A.first, A.second.first) <
+   std::tie(B.first, B.second.first);
+  });
+
+  for (const auto &record : OrderedFuncData) {
+const StringRef &Name = record.first;
+const FuncPair &Func = record.second;
+writeRecordInText(Name, Func.first, Func.second, Symtab, OS);
+  }
+
   return Error::success();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58537: lib/Header: Simplify CMakeLists.txt

2019-03-01 Thread Tom Stellard via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL355253: lib/Header: Simplify CMakeLists.txt (authored by 
tstellar, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D58537?vs=188749&id=189010#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58537

Files:
  cfe/trunk/lib/Headers/CMakeLists.txt


Index: cfe/trunk/lib/Headers/CMakeLists.txt
===
--- cfe/trunk/lib/Headers/CMakeLists.txt
+++ cfe/trunk/lib/Headers/CMakeLists.txt
@@ -123,60 +123,51 @@
 )
 
 set(output_dir ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/include)
-
-# Generate arm_neon.h
-clang_tablegen(arm_neon.h -gen-arm-neon
-  -I ${CLANG_SOURCE_DIR}/include/clang/Basic/
-  SOURCE ${CLANG_SOURCE_DIR}/include/clang/Basic/arm_neon.td)
-# Generate arm_fp16.h
-clang_tablegen(arm_fp16.h -gen-arm-fp16
-  -I ${CLANG_SOURCE_DIR}/include/clang/Basic/
-  SOURCE ${CLANG_SOURCE_DIR}/include/clang/Basic/arm_fp16.td)
-
 set(out_files)
-foreach( f ${files} ${cuda_wrapper_files} )
-  set( src ${CMAKE_CURRENT_SOURCE_DIR}/${f} )
-  set( dst ${output_dir}/${f} )
+
+function(copy_header_to_output_dir src_dir file)
+  set(src ${src_dir}/${file})
+  set(dst ${output_dir}/${file})
   add_custom_command(OUTPUT ${dst}
 DEPENDS ${src}
 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
-COMMENT "Copying clang's ${f}...")
+COMMENT "Copying clang's ${file}...")
   list(APPEND out_files ${dst})
+  set(out_files ${out_files} PARENT_SCOPE)
+endfunction(copy_header_to_output_dir)
+
+function(clang_generate_header td_option td_file out_file)
+  clang_tablegen(${out_file} ${td_option}
+  -I ${CLANG_SOURCE_DIR}/include/clang/Basic/
+  SOURCE ${CLANG_SOURCE_DIR}/include/clang/Basic/${td_file})
+
+  copy_header_to_output_dir(${CMAKE_CURRENT_BINARY_DIR} ${out_file})
+  set(out_files ${out_files} PARENT_SCOPE)
+endfunction(clang_generate_header)
+
+
+# Copy header files from the source directory to the build directory
+foreach( f ${files} ${cuda_wrapper_files} )
+  copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR} ${f})
 endforeach( f )
 
-add_custom_command(OUTPUT ${output_dir}/arm_neon.h
-  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h
-  COMMAND ${CMAKE_COMMAND} -E copy_if_different 
${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h ${output_dir}/arm_neon.h
-  COMMENT "Copying clang's arm_neon.h...")
-list(APPEND out_files ${output_dir}/arm_neon.h)
-add_custom_command(OUTPUT ${output_dir}/arm_fp16.h
-  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/arm_fp16.h
-  COMMAND ${CMAKE_COMMAND} -E copy_if_different 
${CMAKE_CURRENT_BINARY_DIR}/arm_fp16.h ${output_dir}/arm_fp16.h
-  COMMENT "Copying clang's arm_fp16.h...")
-list(APPEND out_files ${output_dir}/arm_fp16.h)
+# Generate header files and copy them to the build directory
+# Generate arm_neon.h
+clang_generate_header(-gen-arm-neon arm_neon.td arm_neon.h)
+# Generate arm_fp16.h
+clang_generate_header(-gen-arm-fp16 arm_fp16.td arm_fp16.h)
 
 add_custom_target(clang-headers ALL DEPENDS ${out_files})
 set_target_properties(clang-headers PROPERTIES
   FOLDER "Misc"
   RUNTIME_OUTPUT_DIRECTORY "${output_dir}")
 
-install(
-  FILES ${files} ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h
-  COMPONENT clang-headers
-  PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
-  DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include)
-
-install(
-  FILES ${files} ${CMAKE_CURRENT_BINARY_DIR}/arm_fp16.h
-  COMPONENT clang-headers
-  PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
-  DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include)
+set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION})
 
 install(
-  FILES ${cuda_wrapper_files}
-  COMPONENT clang-headers
-  PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
-  DESTINATION 
lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include/cuda_wrappers)
+  DIRECTORY ${output_dir}
+  DESTINATION ${header_install_dir}
+  COMPONENT clang-headers)
 
 if (NOT LLVM_ENABLE_IDE)
   add_llvm_install_targets(install-clang-headers


Index: cfe/trunk/lib/Headers/CMakeLists.txt
===
--- cfe/trunk/lib/Headers/CMakeLists.txt
+++ cfe/trunk/lib/Headers/CMakeLists.txt
@@ -123,60 +123,51 @@
 )
 
 set(output_dir ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/include)
-
-# Generate arm_neon.h
-clang_tablegen(arm_neon.h -gen-arm-neon
-  -I ${CLANG_SOURCE_DIR}/include/clang/Basic/
-  SOURCE ${CLANG_SOURCE_DIR}/include/clang/Basic/arm_neon.td)
-# Generate arm_fp16.h
-clang_tablegen(arm_fp16.h -gen-arm-fp16
-  -I ${CLANG_SOURCE_DIR}/include/clang/Basic/
-  SOURCE ${CLANG_SOURCE_DIR}/include/clang/Basic/arm_fp16.td)
-
 set(out_files)
-foreach( f ${files} ${cuda_wrapper_files} )
-  set( src ${CMAKE_CURRENT_SOURCE_DIR}/${f} )
-  

r355253 - lib/Header: Simplify CMakeLists.txt

2019-03-01 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Fri Mar  1 16:50:13 2019
New Revision: 355253

URL: http://llvm.org/viewvc/llvm-project?rev=355253&view=rev
Log:
lib/Header: Simplify CMakeLists.txt

Summary:
Replace cut and pasted code with cmake macros and reduce the number of
install commands.  This fixes an issue where the headers were being
installed twice.

This clean up should also make future modifications easier, like
adding a cmake option to install header files into a custom resource
directory.

Reviewers: chandlerc, smeenai, mgorny, beanz, phosek

Reviewed By: smeenai

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/Headers/CMakeLists.txt

Modified: cfe/trunk/lib/Headers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/CMakeLists.txt?rev=355253&r1=355252&r2=355253&view=diff
==
--- cfe/trunk/lib/Headers/CMakeLists.txt (original)
+++ cfe/trunk/lib/Headers/CMakeLists.txt Fri Mar  1 16:50:13 2019
@@ -123,60 +123,51 @@ set(cuda_wrapper_files
 )
 
 set(output_dir ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/include)
-
-# Generate arm_neon.h
-clang_tablegen(arm_neon.h -gen-arm-neon
-  -I ${CLANG_SOURCE_DIR}/include/clang/Basic/
-  SOURCE ${CLANG_SOURCE_DIR}/include/clang/Basic/arm_neon.td)
-# Generate arm_fp16.h
-clang_tablegen(arm_fp16.h -gen-arm-fp16
-  -I ${CLANG_SOURCE_DIR}/include/clang/Basic/
-  SOURCE ${CLANG_SOURCE_DIR}/include/clang/Basic/arm_fp16.td)
-
 set(out_files)
-foreach( f ${files} ${cuda_wrapper_files} )
-  set( src ${CMAKE_CURRENT_SOURCE_DIR}/${f} )
-  set( dst ${output_dir}/${f} )
+
+function(copy_header_to_output_dir src_dir file)
+  set(src ${src_dir}/${file})
+  set(dst ${output_dir}/${file})
   add_custom_command(OUTPUT ${dst}
 DEPENDS ${src}
 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
-COMMENT "Copying clang's ${f}...")
+COMMENT "Copying clang's ${file}...")
   list(APPEND out_files ${dst})
+  set(out_files ${out_files} PARENT_SCOPE)
+endfunction(copy_header_to_output_dir)
+
+function(clang_generate_header td_option td_file out_file)
+  clang_tablegen(${out_file} ${td_option}
+  -I ${CLANG_SOURCE_DIR}/include/clang/Basic/
+  SOURCE ${CLANG_SOURCE_DIR}/include/clang/Basic/${td_file})
+
+  copy_header_to_output_dir(${CMAKE_CURRENT_BINARY_DIR} ${out_file})
+  set(out_files ${out_files} PARENT_SCOPE)
+endfunction(clang_generate_header)
+
+
+# Copy header files from the source directory to the build directory
+foreach( f ${files} ${cuda_wrapper_files} )
+  copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR} ${f})
 endforeach( f )
 
-add_custom_command(OUTPUT ${output_dir}/arm_neon.h
-  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h
-  COMMAND ${CMAKE_COMMAND} -E copy_if_different 
${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h ${output_dir}/arm_neon.h
-  COMMENT "Copying clang's arm_neon.h...")
-list(APPEND out_files ${output_dir}/arm_neon.h)
-add_custom_command(OUTPUT ${output_dir}/arm_fp16.h
-  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/arm_fp16.h
-  COMMAND ${CMAKE_COMMAND} -E copy_if_different 
${CMAKE_CURRENT_BINARY_DIR}/arm_fp16.h ${output_dir}/arm_fp16.h
-  COMMENT "Copying clang's arm_fp16.h...")
-list(APPEND out_files ${output_dir}/arm_fp16.h)
+# Generate header files and copy them to the build directory
+# Generate arm_neon.h
+clang_generate_header(-gen-arm-neon arm_neon.td arm_neon.h)
+# Generate arm_fp16.h
+clang_generate_header(-gen-arm-fp16 arm_fp16.td arm_fp16.h)
 
 add_custom_target(clang-headers ALL DEPENDS ${out_files})
 set_target_properties(clang-headers PROPERTIES
   FOLDER "Misc"
   RUNTIME_OUTPUT_DIRECTORY "${output_dir}")
 
-install(
-  FILES ${files} ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h
-  COMPONENT clang-headers
-  PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
-  DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include)
-
-install(
-  FILES ${files} ${CMAKE_CURRENT_BINARY_DIR}/arm_fp16.h
-  COMPONENT clang-headers
-  PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
-  DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include)
+set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION})
 
 install(
-  FILES ${cuda_wrapper_files}
-  COMPONENT clang-headers
-  PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
-  DESTINATION 
lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include/cuda_wrappers)
+  DIRECTORY ${output_dir}
+  DESTINATION ${header_install_dir}
+  COMPONENT clang-headers)
 
 if (NOT LLVM_ENABLE_IDE)
   add_llvm_install_targets(install-clang-headers


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


  1   2   >