r304394 - Emit available_externally vtables opportunistically

2017-06-01 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Thu Jun  1 03:04:05 2017
New Revision: 304394

URL: http://llvm.org/viewvc/llvm-project?rev=304394&view=rev
Log:
Emit available_externally vtables opportunistically

Summary:
We can emit vtable definition having inline function
if they are all emitted.

Reviewers: rjmccall, rsmith

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/AST/VTableBuilder.h
cfe/trunk/lib/CodeGen/CGVTables.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp
cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp

Modified: cfe/trunk/include/clang/AST/VTableBuilder.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/VTableBuilder.h?rev=304394&r1=304393&r2=304394&view=diff
==
--- cfe/trunk/include/clang/AST/VTableBuilder.h (original)
+++ cfe/trunk/include/clang/AST/VTableBuilder.h Thu Jun  1 03:04:05 2017
@@ -154,6 +154,27 @@ public:
 
   bool isRTTIKind() const { return isRTTIKind(getKind()); }
 
+  GlobalDecl getGlobalDecl() const {
+assert(isUsedFunctionPointerKind() &&
+   "GlobalDecl can be created only from virtual function");
+
+auto *DtorDecl = dyn_cast(getFunctionDecl());
+switch (getKind()) {
+case CK_FunctionPointer:
+  return GlobalDecl(getFunctionDecl());
+case CK_CompleteDtorPointer:
+  return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Complete);
+case CK_DeletingDtorPointer:
+  return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Deleting);
+case CK_VCallOffset:
+case CK_VBaseOffset:
+case CK_OffsetToTop:
+case CK_RTTI:
+case CK_UnusedFunctionPointer:
+  llvm_unreachable("Only function pointers kinds");
+}
+  }
+
 private:
   static bool isFunctionPointerKind(Kind ComponentKind) {
 return isUsedFunctionPointerKind(ComponentKind) ||

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=304394&r1=304393&r2=304394&view=diff
==
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Thu Jun  1 03:04:05 2017
@@ -901,6 +901,8 @@ void CodeGenModule::EmitDeferredVTables(
   for (const CXXRecordDecl *RD : DeferredVTables)
 if (shouldEmitVTableAtEndOfTranslationUnit(*this, RD))
   VTables.GenerateClassData(RD);
+else if (shouldOpportunisticallyEmitVTables())
+  OpportunisticVTables.push_back(RD);
 
   assert(savedSize == DeferredVTables.size() &&
  "deferred extra vtables during vtable emission?");

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=304394&r1=304393&r2=304394&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Jun  1 03:04:05 2017
@@ -382,6 +382,7 @@ void InstrProfStats::reportDiagnostics(D
 
 void CodeGenModule::Release() {
   EmitDeferred();
+  EmitVTablesOpportunistically();
   applyGlobalValReplacements();
   applyReplacements();
   checkAliases();
@@ -1386,6 +1387,24 @@ void CodeGenModule::EmitDeferred() {
   }
 }
 
+void CodeGenModule::EmitVTablesOpportunistically() {
+  // Try to emit external vtables as available_externally if they have emitted
+  // all inlined virtual functions.  It runs after EmitDeferred() and therefore
+  // is not allowed to create new references to things that need to be emitted
+  // lazily. Note that it also uses fact that we eagerly emitting RTTI.
+
+  assert(OpportunisticVTables.empty() || shouldOpportunisticallyEmitVTables() 
&&
+   "Only emit opportunistic vtables with optimizations");
+
+  for (const CXXRecordDecl *RD : OpportunisticVTables) {
+assert(getVTables().isVTableExternal(RD) &&
+   "This queue should only contain external vtables");
+if (getCXXABI().canSpeculativelyEmitVTable(RD))
+  VTables.GenerateClassData(RD);
+  }
+  OpportunisticVTables.clear();
+}
+
 void CodeGenModule::EmitGlobalAnnotations() {
   if (Annotations.empty())
 return;
@@ -1906,6 +1925,10 @@ bool CodeGenModule::shouldEmitFunction(G
   return !isTriviallyRecursive(F);
 }
 
+bool CodeGenModule::shouldOpportunisticallyEmitVTables() {
+  return CodeGenOpts.OptimizationLevel > 0;
+}
+
 void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD, llvm::GlobalValue *GV) 
{
   const auto *D = cast(GD.getDecl());
 

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=304394&r1=304393&r2=304394&view=diff
=

r304397 - Fixed warnings

2017-06-01 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Thu Jun  1 04:24:36 2017
New Revision: 304397

URL: http://llvm.org/viewvc/llvm-project?rev=304397&view=rev
Log:
Fixed warnings

Modified:
cfe/trunk/include/clang/AST/VTableBuilder.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/include/clang/AST/VTableBuilder.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/VTableBuilder.h?rev=304397&r1=304396&r2=304397&view=diff
==
--- cfe/trunk/include/clang/AST/VTableBuilder.h (original)
+++ cfe/trunk/include/clang/AST/VTableBuilder.h Thu Jun  1 04:24:36 2017
@@ -173,6 +173,7 @@ public:
 case CK_UnusedFunctionPointer:
   llvm_unreachable("Only function pointers kinds");
 }
+llvm_unreachable("Should already return");
   }
 
 private:

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=304397&r1=304396&r2=304397&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Jun  1 04:24:36 2017
@@ -1393,8 +1393,8 @@ void CodeGenModule::EmitVTablesOpportuni
   // is not allowed to create new references to things that need to be emitted
   // lazily. Note that it also uses fact that we eagerly emitting RTTI.
 
-  assert(OpportunisticVTables.empty() || shouldOpportunisticallyEmitVTables() 
&&
-   "Only emit opportunistic vtables with optimizations");
+  assert((OpportunisticVTables.empty() || shouldOpportunisticallyEmitVTables())
+ && "Only emit opportunistic vtables with optimizations");
 
   for (const CXXRecordDecl *RD : OpportunisticVTables) {
 assert(getVTables().isVTableExternal(RD) &&


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


r304448 - Emit invariant.group.barrier when using union field

2017-06-01 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Thu Jun  1 13:39:34 2017
New Revision: 304448

URL: http://llvm.org/viewvc/llvm-project?rev=304448&view=rev
Log:
Emit invariant.group.barrier when using union field

Summary:
We need to emit barrier if the union field
is CXXRecordDecl because it might have vptrs. The testcode
was wrongly devirtualized. It also proves that having different
groups for different dynamic types is not sufficient.

Reviewers: rjmccall, rsmith, mehdi_amini

Subscribers: amharc, cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=304448&r1=304447&r2=304448&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Jun  1 13:39:34 2017
@@ -3530,6 +3530,25 @@ static Address emitAddrOfFieldStorage(Co
   return CGF.Builder.CreateStructGEP(base, idx, offset, field->getName());
 }
 
+static bool hasAnyVptr(const QualType Type, const ASTContext &Context) {
+  const auto *RD = Type.getTypePtr()->getAsCXXRecordDecl();
+  if (!RD)
+return false;
+
+  if (RD->isDynamicClass())
+return true;
+
+  for (const auto &Base : RD->bases())
+if (hasAnyVptr(Base.getType(), Context))
+  return true;
+
+  for (const FieldDecl *Field : RD->fields())
+if (hasAnyVptr(Field->getType(), Context))
+  return true;
+
+  return false;
+}
+
 LValue CodeGenFunction::EmitLValueForField(LValue base,
const FieldDecl *field) {
   LValueBaseInfo BaseInfo = base.getBaseInfo();
@@ -3572,6 +3591,14 @@ LValue CodeGenFunction::EmitLValueForFie
 assert(!type->isReferenceType() && "union has reference member");
 // TODO: handle path-aware TBAA for union.
 TBAAPath = false;
+
+const auto FieldType = field->getType();
+if (CGM.getCodeGenOpts().StrictVTablePointers &&
+hasAnyVptr(FieldType, getContext()))
+  // Because unions can easily skip invariant.barriers, we need to add
+  // a barrier every time CXXRecord field with vptr is referenced.
+  addr = Address(Builder.CreateInvariantGroupBarrier(addr.getPointer()),
+ addr.getAlignment());
   } else {
 // For structs, we GEP to the field that the record layout suggests.
 addr = emitAddrOfFieldStorage(*this, addr, field);

Modified: cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp?rev=304448&r1=304447&r2=304448&view=diff
==
--- cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp Thu Jun  1 13:39:34 
2017
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 
-fstrict-vtable-pointers -disable-llvm-passes -O2 -emit-llvm -o %t.ll
+// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 
-fstrict-vtable-pointers -std=c++11 -disable-llvm-passes -O2 -emit-llvm -o %t.ll
 // RUN: FileCheck --check-prefix=CHECK-CTORS %s < %t.ll
 // RUN: FileCheck --check-prefix=CHECK-NEW %s < %t.ll
 // RUN: FileCheck --check-prefix=CHECK-DTORS %s < %t.ll
@@ -180,6 +180,119 @@ struct DynamicFromStatic;
 // CHECK-CTORS-NOT: @llvm.invariant.group.barrier(
 // CHECK-CTORS-LABEL: {{^}}}
 
+struct A {
+  virtual void foo();
+};
+struct B : A {
+  virtual void foo();
+};
+
+union U {
+  A a;
+  B b;
+};
+
+void changeToB(U *u);
+void changeToA(U *u);
+
+void g2(A *a) {
+  a->foo();
+}
+// We have to guard access to union fields with invariant.group, because
+// it is very easy to skip the barrier with unions. In this example the inlined
+// g2 will produce loads with the same !invariant.group metadata, and
+// u->a and u->b would use the same pointer.
+// CHECK-NEW-LABEL: define void @_Z14UnionsBarriersP1U
+void UnionsBarriers(U *u) {
+  // CHECK-NEW: call void @_Z9changeToBP1U(
+  changeToB(u);
+  // CHECK-NEW: call i8* @llvm.invariant.group.barrier(i8*
+  // CHECK-NEW: call void @_Z2g2P1A(%struct.A*
+  g2(&u->b);
+  // CHECK-NEW: call void @_Z9changeToAP1U(%union.U* %6)
+  changeToA(u);
+  // CHECK-NEW: call i8* @llvm.invariant.group.barrier(i8*
+  // call void @_Z2g2P1A(%struct.A* %a)
+  g2(&u->a);
+  // CHECK-NEW-NOT: call i8* @llvm.invariant.group.barrier(i8*
+}
+
+struct HoldingVirtuals {
+  A a;
+};
+
+struct Empty {};
+struct AnotherEmpty {
+  Empty e;
+};
+union NoVptrs {
+  int a;
+  AnotherEmpty empty;
+};
+void take(AnotherEmpty &);
+
+// CHECK-NEW-LABEL: noBarriers
+void noBarriers(NoVptrs &noVptrs) {
+  // CHECK-NEW-NOT: call i8* @llvm.invariant.group.barrier(i8*
+  // CHECK-NEW: 42
+  noVptrs.a += 42;
+  // CHECK-NEW-NOT: call i8* @llvm.invariant.group.barrier(i8*
+  // CHECK-NE

r304455 - Fixed broken test (strict-vtable-pointers)

2017-06-01 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Thu Jun  1 14:08:05 2017
New Revision: 304455

URL: http://llvm.org/viewvc/llvm-project?rev=304455&view=rev
Log:
Fixed broken test (strict-vtable-pointers)

Modified:
cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp

Modified: cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp?rev=304455&r1=304454&r2=304455&view=diff
==
--- cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp Thu Jun  1 14:08:05 
2017
@@ -209,7 +209,7 @@ void UnionsBarriers(U *u) {
   // CHECK-NEW: call i8* @llvm.invariant.group.barrier(i8*
   // CHECK-NEW: call void @_Z2g2P1A(%struct.A*
   g2(&u->b);
-  // CHECK-NEW: call void @_Z9changeToAP1U(%union.U* %6)
+  // CHECK-NEW: call void @_Z9changeToAP1U(%union.U* 
   changeToA(u);
   // CHECK-NEW: call i8* @llvm.invariant.group.barrier(i8*
   // call void @_Z2g2P1A(%struct.A* %a)


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


r334600 - Add -fforce-emit-vtables

2018-06-13 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Wed Jun 13 06:55:42 2018
New Revision: 334600

URL: http://llvm.org/viewvc/llvm-project?rev=334600&view=rev
Log:
Add -fforce-emit-vtables

Summary:
 In many cases we can't devirtualize
 because definition of vtable is not present. Most of the
 time it is caused by inline virtual function not beeing
 emitted. Forcing emitting of vtable adds a reference of these
 inline virtual functions.
 Note that GCC was always doing it.

Reviewers: rjmccall, rsmith, amharc, kuhar

Subscribers: llvm-commits, cfe-commits

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

Co-authored-by: Krzysztof Pszeniczny 

Modified:
cfe/trunk/docs/ClangCommandLineReference.rst
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/docs/UsersManual.rst
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp

Modified: cfe/trunk/docs/ClangCommandLineReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangCommandLineReference.rst?rev=334600&r1=334599&r2=334600&view=diff
==
--- cfe/trunk/docs/ClangCommandLineReference.rst (original)
+++ cfe/trunk/docs/ClangCommandLineReference.rst Wed Jun 13 06:55:42 2018
@@ -1934,6 +1934,12 @@ Set the default symbol visibility for al
 
 Enables whole-program vtable optimization. Requires -flto
 
+.. option:: -fforce-emit-vtables, -fno-force-emit-vtables
+
+In order to improve devirtualization, forces emitting of vtables even in
+modules where it isn't necessary. It causes more inline virtual functions
+to be emitted.
+
 .. option:: -fwrapv, -fno-wrapv
 
 Treat signed integer overflow as two's complement

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=334600&r1=334599&r2=334600&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Wed Jun 13 06:55:42 2018
@@ -112,6 +112,12 @@ New Compiler Flags
   'no-strict' option, Clang attempts to match the overflowing behavior of the
   target's native float-to-int conversion instructions.
 
+- :option: `-fforce-emit-vtables` and `-fno-force-emit-vtables`.
+
+   In order to improve devirtualization, forces emitting of vtables even in
+   modules where it isn't necessary. It causes more inline virtual functions
+   to be emitted.
+
 - ...
 
 Deprecated Compiler Flags

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=334600&r1=334599&r2=334600&view=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Wed Jun 13 06:55:42 2018
@@ -1269,6 +1269,12 @@ are listed below.
devirtualization and virtual constant propagation, for classes with
:doc:`hidden LTO visibility `. Requires ``-flto``.
 
+.. option:: -fforce-emit-vtables
+
+   In order to improve devirtualization, forces emitting of vtables even in
+   modules where it isn't necessary. It causes more inline virtual functions
+   to be emitted.
+
 .. option:: -fno-assume-sane-operator-new
 
Don't assume that the C++'s new operator is sane.

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=334600&r1=334599&r2=334600&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Wed Jun 13 06:55:42 2018
@@ -293,6 +293,8 @@ LANGOPT(XRayAlwaysEmitTypedEvents, 1, 0,
 "controls whether to always emit intrinsic calls to "
 "__xray_typedevent(...) builtin.")
 
+LANGOPT(ForceEmitVTables, 1, 0, "whether to emit all vtables")
+
 BENIGN_LANGOPT(AllowEditorPlaceholders, 1, 0,
"allow editor placeholders in source")
 

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=334600&r1=334599&r2=334600&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Jun 13 06:55:42 2018
@@ -1688,6 +1688,11 @@ def fwhole_program_vtables : Flag<["-"],
   HelpText<"Enables whole-program vtable optimization. Requires -flto">;
 def fno_whole_program_vtables : Flag<["-"], "fno-whole-program-vtables">, 
Group,
   Flags<[CoreOption]>;
+def fforce_emi

r313278 - Enable __declspec(selectany) on any platform

2017-09-14 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Thu Sep 14 10:33:08 2017
New Revision: 313278

URL: http://llvm.org/viewvc/llvm-project?rev=313278&view=rev
Log:
Enable __declspec(selectany) on any platform

Summary:
This feature was disabled probably by mistake in rL300562
This fixes bug https://bugs.llvm.org/show_bug.cgi?id=33285

Reviewers: davide, rnk

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/test/Sema/attr-selectany.c
cfe/trunk/test/SemaCXX/attr-selectany.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=313278&r1=313277&r2=313278&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Thu Sep 14 10:33:08 2017
@@ -2472,9 +2472,9 @@ def DLLImport : InheritableAttr, TargetS
   let Documentation = [DLLImportDocs];
 }
 
-def SelectAny : InheritableAttr, TargetSpecificAttr {
+def SelectAny : InheritableAttr {
   let Spellings = [Declspec<"selectany">, GCC<"selectany">];
-  let Documentation = [Undocumented];
+  let Documentation = [SelectAnyDocs];
 }
 
 def Thread : Attr {

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=313278&r1=313277&r2=313278&view=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Thu Sep 14 10:33:08 2017
@@ -3192,3 +3192,18 @@ This attribute can be added to an Object
 ensure that this class cannot be subclassed.
   }];
 }
+
+
+def SelectAnyDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute appertains to a global symbol, causing it to have a weak
+definition (
+`linkonce `_
+), allowing the linker to select any definition.
+
+For more information see
+`gcc documentation 
`_
+or `msvc documentation `_.
+}];
+}

Modified: cfe/trunk/test/Sema/attr-selectany.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-selectany.c?rev=313278&r1=313277&r2=313278&view=diff
==
--- cfe/trunk/test/Sema/attr-selectany.c (original)
+++ cfe/trunk/test/Sema/attr-selectany.c Thu Sep 14 10:33:08 2017
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-win32 -fdeclspec -verify %s
 // RUN: %clang_cc1 -triple x86_64-mingw32 -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -verify -fdeclspec %s
+// RUN: %clang_cc1 -triple x86_64-win32-macho -verify -fdeclspec %s
 
 extern __declspec(selectany) const int x1 = 1; // no warning, const means we 
need extern in C++
 

Modified: cfe/trunk/test/SemaCXX/attr-selectany.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-selectany.cpp?rev=313278&r1=313277&r2=313278&view=diff
==
--- cfe/trunk/test/SemaCXX/attr-selectany.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-selectany.cpp Thu Sep 14 10:33:08 2017
@@ -1,4 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-win32 -fms-compatibility -fms-extensions 
-fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fms-compatibility 
-fms-extensions -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-win32-macho -fms-compatibility 
-fms-extensions -fsyntax-only -verify -std=c++11 %s
+
 // MSVC produces similar diagnostics.
 
 __declspec(selectany) void foo() { } // expected-error{{'selectany' can only 
be applied to data items with external linkage}}


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


r331448 - Rename invariant.group.barrier to launder.invariant.group

2018-05-03 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Thu May  3 04:03:01 2018
New Revision: 331448

URL: http://llvm.org/viewvc/llvm-project?rev=331448&view=rev
Log:
Rename invariant.group.barrier to launder.invariant.group

Summary:
This is one of the initial commit of "RFC: Devirtualization v2" proposal:
https://docs.google.com/document/d/16GVtCpzK8sIHNc2qZz6RN8amICNBtvjWUod2SujZVEo/edit?usp=sharing

Reviewers: rsmith, amharc, kuhar, sanjoy

Subscribers: arsenm, nhaehnle, javed.absar, hiraditya, llvm-commits

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

Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=331448&r1=331447&r2=331448&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Thu May  3 04:03:01 2018
@@ -1276,7 +1276,7 @@ void CodeGenFunction::EmitCtorPrologue(c
 if (CGM.getCodeGenOpts().StrictVTablePointers &&
 CGM.getCodeGenOpts().OptimizationLevel > 0 &&
 isInitializerOfDynamicClass(*B))
-  CXXThisValue = Builder.CreateInvariantGroupBarrier(LoadCXXThis());
+  CXXThisValue = Builder.CreateLaunderInvariantGroup(LoadCXXThis());
 EmitBaseInitializer(*this, ClassDecl, *B, CtorType);
   }
 
@@ -1293,7 +1293,7 @@ void CodeGenFunction::EmitCtorPrologue(c
 if (CGM.getCodeGenOpts().StrictVTablePointers &&
 CGM.getCodeGenOpts().OptimizationLevel > 0 &&
 isInitializerOfDynamicClass(*B))
-  CXXThisValue = Builder.CreateInvariantGroupBarrier(LoadCXXThis());
+  CXXThisValue = Builder.CreateLaunderInvariantGroup(LoadCXXThis());
 EmitBaseInitializer(*this, ClassDecl, *B, CtorType);
   }
 
@@ -1477,11 +1477,11 @@ void CodeGenFunction::EmitDestructorBody
 
 // Initialize the vtable pointers before entering the body.
 if (!CanSkipVTablePointerInitialization(*this, Dtor)) {
-  // Insert the llvm.invariant.group.barrier intrinsic before initializing
+  // Insert the llvm.launder.invariant.group intrinsic before initializing
   // the vptrs to cancel any previous assumptions we might have made.
   if (CGM.getCodeGenOpts().StrictVTablePointers &&
   CGM.getCodeGenOpts().OptimizationLevel > 0)
-CXXThisValue = Builder.CreateInvariantGroupBarrier(LoadCXXThis());
+CXXThisValue = Builder.CreateLaunderInvariantGroup(LoadCXXThis());
   InitializeVTablePointers(Dtor->getParent());
 }
 

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=331448&r1=331447&r2=331448&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu May  3 04:03:01 2018
@@ -3850,7 +3850,7 @@ LValue CodeGenFunction::EmitLValueForFie
 hasAnyVptr(FieldType, getContext()))
   // Because unions can easily skip invariant.barriers, we need to add
   // a barrier every time CXXRecord field with vptr is referenced.
-  addr = Address(Builder.CreateInvariantGroupBarrier(addr.getPointer()),
+  addr = Address(Builder.CreateLaunderInvariantGroup(addr.getPointer()),
  addr.getAlignment());
   } else {
 // For structs, we GEP to the field that the record layout suggests.

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=331448&r1=331447&r2=331448&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Thu May  3 04:03:01 2018
@@ -1696,13 +1696,13 @@ llvm::Value *CodeGenFunction::EmitCXXNew
   llvm::Type *elementTy = ConvertTypeForMem(allocType);
   Address result = Builder.CreateElementBitCast(allocation, elementTy);
 
-  // Passing pointer through invariant.group.barrier to avoid propagation of
+  // Passing pointer through launder.invariant.group to avoid propagation of
   // vptrs information which may be included in previous type.
   // To not break LTO with different optimizations levels, we do it regardless
   // of optimization level.
   if (CGM.getCodeGenOpts().StrictVTablePointers &&
   allocator->isReservedGlobalPlacementOperator())
-result = Address(Builder.CreateInvariantGroupBarrier(result.getPointer()),
+result = Address(Builder.CreateLaunderInvariantGroup(result.getPointer()),
  result.getAlignment());
 
   EmitNewInitializer(*this, E, allocType, elementTy, result, numElements,

Modified: cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
URL: 
http://llvm.org

r336137 - [CodeGenCXX] Emit strip.invariant.group with -fstrict-vtable-pointers

2018-07-02 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Mon Jul  2 12:21:36 2018
New Revision: 336137

URL: http://llvm.org/viewvc/llvm-project?rev=336137&view=rev
Log:
[CodeGenCXX] Emit strip.invariant.group with -fstrict-vtable-pointers

Summary:
Emmiting new intrinsic that strips invariant.groups to make
devirtulization sound, as described in RFC: Devirtualization v2.

Reviewers: rjmccall, rsmith, amharc, kuhar

Subscribers: llvm-commits, cfe-commits

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

Co-authored-by: Krzysztof Pszeniczny 

Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=336137&r1=336136&r2=336137&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Jul  2 12:21:36 2018
@@ -790,6 +790,18 @@ public:
 return data().Polymorphic || data().NumVBases != 0;
   }
 
+  /// @returns true if class is dynamic or might be dynamic because the
+  /// definition is incomplete of dependent.
+  bool mayBeDynamicClass() const {
+return !hasDefinition() || isDynamicClass() || hasAnyDependentBases();
+  }
+
+  /// @returns true if class is non dynamic or might be non dynamic because the
+  /// definition is incomplete of dependent.
+  bool mayBeNonDynamicClass() const {
+return !hasDefinition() || !isDynamicClass() || hasAnyDependentBases();
+  }
+
   void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; }
 
   bool isParsingBaseSpecifiers() const {

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=336137&r1=336136&r2=336137&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Jul  2 12:21:36 2018
@@ -810,6 +810,13 @@ public:
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext &Context) const;
 
+
+  /// Returns true if it is a class and it might be dynamic.
+  bool mayBeDynamicClass() const;
+
+  /// Returns true if it is not a class or if the class might not be dynamic.
+  bool mayBeNotDynamicClass() const;
+
   // Don't promise in the API that anything besides 'const' can be
   // easily added.
 

Modified: cfe/trunk/lib/AST/Type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=336137&r1=336136&r2=336137&view=diff
==
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Mon Jul  2 12:21:36 2018
@@ -88,6 +88,16 @@ const IdentifierInfo* QualType::getBaseT
   return nullptr;
 }
 
+bool QualType::mayBeDynamicClass() const {
+  const auto *ClassDecl = getTypePtr()->getPointeeCXXRecordDecl();
+  return ClassDecl && ClassDecl->mayBeDynamicClass();
+}
+
+bool QualType::mayBeNotDynamicClass() const {
+  const auto *ClassDecl = getTypePtr()->getPointeeCXXRecordDecl();
+  return !ClassDecl || ClassDecl->mayBeNonDynamicClass();
+}
+
 bool QualType::isConstant(QualType T, const ASTContext &Ctx) {
   if (T.isConstQualified())
 return true;

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=336137&r1=336136&r2=336137&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Jul  2 12:21:36 2018
@@ -3870,6 +3870,18 @@ LValue CodeGenFunction::EmitLValueForFie
   }
 
   Address addr = base.getAddress();
+  if (auto *ClassDef = dyn_cast(rec)) {
+if (CGM.getCodeGenOpts().StrictVTablePointers &&
+ClassDef->isDynamicClass()) {
+  // Getting to any field of dynamic object requires stripping dynamic
+  // information provided by invariant.group.  This is because accessing
+  // fields may leak the real address of dynamic object, which could result
+  // in miscompilation when leaked pointer would be compared.
+  auto *stripped = Builder.CreateStripInvariantGroup(addr.getPointer());
+  addr = Address(stripped, addr.getAlignment());
+}
+  }
+
   unsigned RecordCVR = base.getVRQualifiers();
   if (rec->isUnion()) {
 // For unions, there is no pointer adjustment.

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=336137&r1=336136&r2=336137&view=diff
==
--- cfe/trunk/lib

[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-06 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

Please add tests with

  long long p = static_cast(4);

and the same with const at beginning. I remember I had problems with this last 
time (Type->SourceRange was returning only source range for the first token.
I will review patch later.


https://reviews.llvm.org/D25316



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


[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-07 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

In https://reviews.llvm.org/D25316#564217, @malcolm.parsons wrote:

> In https://reviews.llvm.org/D25316#563930, @Prazek wrote:
>
> > Please add tests with
> >
> >   long long p = static_cast(4);
> >   
> >
> > and the same with const at beginning. I remember I had problems with this 
> > last time (Type->SourceRange was returning only source range for the first 
> > token.
>
>
> BuiltinTypeLoc only returns the first token:
>
>   SourceRange getLocalSourceRange() const {
> return SourceRange(getBuiltinLoc(), getBuiltinLoc());
>   }
>   
>
> The existing check fails too:
>
>   -long long *ll = new long long();
>   +auto long *ll = new long long();


Interesting! I remember checking it half year ago, and it was working 
(SourceRange was returning all tokens from first one
to asterisk). I remember there was some small features introduced, like instead 
of
auto p = long long new;
to produce
auto *p = long long new;

Maybe it was introduced in that patch. Anyway I think this have to be fixed 
somehow. Either by playing with lexer, or by fixing sourceRange


https://reviews.llvm.org/D25316



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


[PATCH] D25363: Store a SourceRange for multi-token builtin types

2016-10-08 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

Thanks for the patch! I think some unit test should be added.

Do you also handle cases like

  unsigned long long
  unsigned volatile long const long static

etc.
The problem here is that the whole type like "unsigned long long" could be in 
other tokens. 
I talked with Richard Smith while ago and one of the solutions proposed was to 
have "isValid()" for source range
returning false for cases like this

  unsigned const long




Comment at: include/clang/AST/TypeLoc.h:529
+  void setBuiltinLocStart(SourceLocation Loc) {
+if (getLocalData()->BuiltinRange.getEnd().isValid()) {
+  getLocalData()->BuiltinRange.setBegin(Loc);

Can you add a comment here? It might be because I don't know the AST API, but 
it is not clear for me what does it do.



Comment at: lib/Sema/DeclSpec.cpp:621
   TypeSpecWidth = W;
+  // Remember location of the last 'long'
+  TSTLoc = Loc;

What about cases like 
  unsigned int
  unsigned long

This is not only about long.


https://reviews.llvm.org/D25363



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


[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-08 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

Awesome to see this patch. After this one will make it to upstream, it will be 
much easier for me to do same with template functions.




Comment at: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp:2
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, 
value: '1'}]}" \
+// RUN:   -- -std=c++11

What is the difference between this test, and next test?
The name indicate that it removes star, but I see a lot of test that doesn't 
use star
and that seem to be duplicated with the next one.



Comment at: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp:25
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with 
a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  ll = static_cast(l);
+  unsigned long long ull = static_cast(l);

Is it possible to simply fix the double spaces?



Comment at: test/clang-tidy/modernize-use-auto-cast.cpp:14
+  long l = 1;
+  int i1 = static_cast(l);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with 
a cast to avoid duplicating the type name

How do you handle cases like

  long l = static_cast(i1);

I would expect it to produce warning, but not produce fixit (because it might 
change the behavior of program), but I still would like to get information 
about it because it seems like a bug.


https://reviews.llvm.org/D25316



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


[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-09 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

In https://reviews.llvm.org/D25316#565463, @malcolm.parsons wrote:

> In https://reviews.llvm.org/D25316#565378, @Prazek wrote:
>
> > Awesome to see this patch. After this one will make it to upstream, it will 
> > be much easier for me to do same with template functions.
>
>
> I was trying to match such functions:
>
>   varDecl(hasType(type().bind("type")),
>   hasInitializer(callExpr(callee(
>   functionDecl(isInstantiated(),
>hasTemplateArgument(
>0, 
> refersToType(type(equalsBoundNode("type")
>   .bind("fn")


I did some implementation long ago for boost-lexical-last here: 
https://reviews.llvm.org/D17765
My matchers were:

  Finder->addMatcher(
  declStmt(has(varDecl(hasInitializer(callExpr(callee(
   functionDecl(hasName(LEXICAL_CAST_NAME),
   unless(hasType(autoType())
  .bind("same_type"),
  this);
  
  Finder->addMatcher(
  declStmt(has(varDecl(hasInitializer(implicitCastExpr(has(callExpr(
   callee(functionDecl(hasName(LEXICAL_CAST_NAME))
  .bind("different_type"),
  this);




Comment at: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp:2
+// RUN: %check_clang_tidy %s modernize-use-auto %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, 
value: '1'}]}" \
+// RUN:   -- -std=c++11

malcolm.parsons wrote:
> Prazek wrote:
> > What is the difference between this test, and next test?
> > The name indicate that it removes star, but I see a lot of test that 
> > doesn't use star
> > and that seem to be duplicated with the next one.
> I could remove the duplicated tests, but the expected fixes are different so 
> I'd like to test with and without star removal.
so I think the best thing to do here, is to merge 2 files together, add second 
RUN: with different -check-prefix and use this prefix in the tests. At least 
this is how the tests in LLVM works, not sure if this is implemented in 
check_clang_tidy. 



Comment at: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp:25
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with 
a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  ll = static_cast(l);
+  unsigned long long ull = static_cast(l);

malcolm.parsons wrote:
> Prazek wrote:
> > Is it possible to simply fix the double spaces?
> The existing modernize-use-auto tests have the same problem.
> My codebase is clang-formatted regularly so it doesn't bother me.
I agree that it is not huge problem with clang-format and of course it is not 
required to fix it to push this patch upstream. It would be good to leave a 
comment somewhere with FIXME: about this, so it would be easier for some other 
contributor to fix it (or if it simple, just fix it in this patch :))


https://reviews.llvm.org/D25316



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


[PATCH] D25363: Store a SourceRange for multi-token builtin types

2016-10-09 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

In https://reviews.llvm.org/D25363#565445, @malcolm.parsons wrote:

> In https://reviews.llvm.org/D25363#565371, @Prazek wrote:
>
> > Thanks for the patch! I think some unit test should be added.
>
>
> Are there any existing unit tests for TypeLoc that I can add to?
>
> > Do you also handle cases like
> > 
> >   unsigned long long
>
> Yes - see tests in https://reviews.llvm.org/D25316.
>
> > The problem here is that the whole type like "unsigned long long" could be 
> > in other tokens. 
> >  I talked with Richard Smith while ago and one of the solutions proposed 
> > was to have "isValid()" for source range
> >  returning false for cases like this
> > 
> >   unsigned const long
>
> I see.  I hope that's a rare case that I can ignore for now.


I think there are some. Look at unittests/AST/ or unittests/ASTMatchers/. Sorry 
for being not so precise, but can't check it right now. I can check it later if 
you won't find it.


https://reviews.llvm.org/D25363



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


[PATCH] D25363: Store a SourceRange for multi-token builtin types

2016-10-09 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

In https://reviews.llvm.org/D25363#565472, @malcolm.parsons wrote:

> I've tested this with clang-query using `match typeLoc()` and a lot of 
> permutations of int, short, long, unsigned and const.


I am pretty sure it works, but someone could change the implementation and 
break your check without knowing it - not everyone compile and tests 
clang-extra, so we should have independent test.


https://reviews.llvm.org/D25363



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


[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-09 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

In https://reviews.llvm.org/D25316#565574, @malcolm.parsons wrote:

> In https://reviews.llvm.org/D25316#565567, @Prazek wrote:
>
> >   functionDecl(hasName(LEXICAL_CAST_NAME),
>
>
> I was trying to avoid specifying the name of the function so that it works 
> for any templated function/member function that returns its first template 
> type.


Good idea. I am not sure how it will work when you will run it on big codebase, 
so I wanted to make it configurable for any function name. But if it will work 
for 99% of useful cases, then it will be great!


https://reviews.llvm.org/D25316



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


[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-09 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.



Comment at: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp:25
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with 
a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  ll = static_cast(l);
+  unsigned long long ull = static_cast(l);

malcolm.parsons wrote:
> Prazek wrote:
> > malcolm.parsons wrote:
> > > Prazek wrote:
> > > > Is it possible to simply fix the double spaces?
> > > The existing modernize-use-auto tests have the same problem.
> > > My codebase is clang-formatted regularly so it doesn't bother me.
> > I agree that it is not huge problem with clang-format and of course it is 
> > not required to fix it to push this patch upstream. It would be good to 
> > leave a comment somewhere with FIXME: about this, so it would be easier for 
> > some other contributor to fix it (or if it simple, just fix it in this 
> > patch :))
> There's a FIXME comment in one of the existing modernize-use-auto test files.
Yes, but I am talking about FIXME comment in check code. IF someone reads the 
code, it is much more clear for them that this thing doesn't work completely, 
than if the programmer would see the error and would have to look at tests or 
execute clang-tidy to make sure that he understand code well.


https://reviews.llvm.org/D25316



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


[PATCH] D25316: [clang-tidy] Fix PR25499: Enhance modernize-use-auto to casts

2016-10-09 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

BTW I think changing the commit name by removing bug ID would be good, because 
it would be more clear that this is a feature commit, not a bug fix. 
You can move t he bug id, or the link to bug to the summary section.


https://reviews.llvm.org/D25316



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


Re: [clang-tools-extra] r289656 - modernize-use-auto NFC fixes

2016-12-15 Thread Piotr Padlewski via cfe-commits
Sure, I am planning to do so. I just wanted to firstly make all auto's and
the change was small enough that I though you would not mind pushing it
without review.
BTW the same thing in clang needs review: https://reviews.llvm.org/D27767

2016-12-15 17:08 GMT+01:00 Alexander Kornienko :

> For most loop changes here applying modernize-loop-convert would be better
> ;)
>
> On Wed, Dec 14, 2016 at 4:29 PM, Piotr Padlewski via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: prazek
>> Date: Wed Dec 14 09:29:23 2016
>> New Revision: 289656
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=289656&view=rev
>> Log:
>> modernize-use-auto NFC fixes
>>
>> Modified:
>> clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
>> clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling
>> /ApplyReplacements.cpp
>> clang-tools-extra/trunk/clang-query/Query.cpp
>> clang-tools-extra/trunk/clang-query/QueryParser.cpp
>> clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
>> clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProType
>> MemberInitCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/Special
>> MemberFunctionsCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructo
>> rCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/google/NonConstReferences.cpp
>> clang-tools-extra/trunk/clang-tidy/llvm/TwineLocalCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/misc/MoveForwardingRefere
>> nceCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/misc/MultipleStatementMac
>> roCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByR
>> eferenceCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/mpi/TypeMismatchCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolC
>> astCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/readability/NamespaceComm
>> entCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/readability/RedundantDecl
>> arationCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/readability/RedundantSmar
>> tptrGetCheck.cpp
>> clang-tools-extra/trunk/include-fixer/find-all-symbols/
>> FindAllSymbols.cpp
>> clang-tools-extra/trunk/modularize/CoverageChecker.cpp
>> clang-tools-extra/trunk/modularize/Modularize.cpp
>> clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp
>> clang-tools-extra/trunk/modularize/ModuleAssistant.cpp
>> clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
>> clang-tools-extra/trunk/pp-trace/PPTrace.cpp
>> clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyDiagno
>> sticConsumerTest.cpp
>> clang-tools-extra/trunk/unittests/clang-tidy/NamespaceAliaserTest.cpp
>> clang-tools-extra/trunk/unittests/clang-tidy/UsingInserterTest.cpp
>>
>> Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/
>> change-namespace/ChangeNamespace.cpp?rev=289656&r1=289655&
>> r2=289656&view=diff
>> 
>> ==
>> --- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
>> (original)
>> +++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Wed Dec
>> 14 09:29:23 2016
>> @@ -709,7 +709,7 @@ void ChangeNamespaceTool::fixTypeLoc(
>>return;
>>}
>>
>> -  const Decl *DeclCtx = Result.Nodes.getNodeAs("dc");
>> +  const auto *DeclCtx = Result.Nodes.getNodeAs("dc");
>>assert(DeclCtx && "Empty decl context.");
>>replaceQualifiedSymbolInDeclContext(Result,
>> DeclCtx->getDeclContext(), Start,
>>End, FromDecl);
>>
>> Modified: clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling
>> /ApplyReplacements.cpp
>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/
>> clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp?
>> rev=289656&r1=289655&r2=289656&view=diff
>> 
>> ==
>> --- 
>> clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
>> (original)
>> +++ 
>&

Re: [PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-15 Thread Piotr Padlewski via cfe-commits
I think that the feature I mentioned is right thing to put in this check,
however you don't have to implement it right now, just leave FIXIT comment

2016-12-15 20:55 GMT+01:00 Mads Ravn :

> Hi Piotr,
>
> That is a good point. Because it is not always -1 or 1 that determines
> lexicographical higher or lower.
>
> However, I don't think that is in the scope of this check. This check
> checks for string comparison (equality or inequality). Adding a match for
> if the user is using the compare function semantically wrong might make the
> check too ambiguous. Since str.compare(str) == 0 will check for equality
> and str.compare(str) != 0 will check for inequality. But str.compare(str)
> == 1 will check whether one string is lexicographically smaller than the
> other (and == -1 also). What do you think?
>
> Best regards,
> Mads Ravn
>
> On Thu, Dec 15, 2016 at 8:17 PM Piotr Padlewski via Phabricator <
> revi...@reviews.llvm.org> wrote:
>
>> Prazek added a comment.
>>
>> Good job.
>> I think it is resonable to warn in cases like:
>>
>>   if (str.compare(str2) == 1)
>>
>> or even
>>
>>   if(str.compare(str2) == -1)
>>
>> Sometimes people check for 1 or -1 instead of > 0 and < 0. If I remember
>> corectly PVS studio found some bugs like this.
>>
>>
>>
>> 
>> Comment at: clang-tidy/misc/StringCompareCheck.cpp:27
>> +   hasName("::std::basic_string"),
>> +  hasArgument(0, declRefExpr()), callee(memberExpr()));
>> +
>> 
>> malcolm.parsons wrote:
>> > I don't think you need to check what the first argument is.
>> +1, just check if you are calling function with 1 argument.
>> you can still use hasArgument(0, expr().bind("str2")) to bind argument
>>
>>
>> 
>> Comment at: clang-tidy/misc/StringCompareCheck.cpp:25
>> +return;
>> +  const auto strCompare = cxxMemberCallExpr(
>> +  callee(cxxMethodDecl(hasName("compare"),
>> 
>> Start with upper case
>>
>>
>> https://reviews.llvm.org/D27210
>>
>>
>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r289930 - [clang-tidy] fix missing anchor for MPI Module

2016-12-16 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Fri Dec 16 03:14:47 2016
New Revision: 289930

URL: http://llvm.org/viewvc/llvm-project?rev=289930&view=rev
Log:
[clang-tidy] fix missing anchor for MPI Module

Summary: MPIModule was not linked to plugins

Reviewers: alexfh, Alexander_Droste, hokein

Subscribers: JDevlieghere, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp

Modified: clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp?rev=289930&r1=289929&r2=289930&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp Fri Dec 16 
03:14:47 2016
@@ -108,6 +108,11 @@ extern volatile int ModernizeModuleAncho
 static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
 ModernizeModuleAnchorSource;
 
+// This anchor is used to force the linker to link the MPIModule.
+extern volatile int MPIModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
+  MPIModuleAnchorSource;
+
 // This anchor is used to force the linker to link the PerformanceModule.
 extern volatile int PerformanceModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =


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


Re: [PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-19 Thread Piotr Padlewski via cfe-commits
Firstly, please respond in phabricator if it is possible. When you send
email it doesn't appear in phabricator, it's probably a bug.

2016-12-19 8:00 GMT+01:00 Mads Ravn :

> Hi Piotr,
>
> Thank you for your detailed comments :)
>
> I would love some help with the other fixit. I have some notes on it at
> home. But my main catch is that is an implicit cast to boolean from
> str.compare(str) with maybe an ! in front of it. And I need to fix that to
> str.compare(str) == 0 or str.compare(str) != 0.
>
> Why fix it to something, that you will want to fix it again to str == str
and str != str?
I guess you just have to match parent of this expr is negation or anything,
bind negation to some name and then check if you matched to the negation or
not.


> Where should I put the warning in a static const global variable? Is it
> still in StringCompare.cpp or do we have a  joint files for these?
>
> Yep, StringCompare.cpp, just like in other checks.

> Best regards,
> Mads Ravn
>
> On Sun, Dec 18, 2016 at 11:26 PM Piotr Padlewski via Phabricator <
> revi...@reviews.llvm.org> wrote:
>
>> Prazek added a comment.
>>
>> Do you need some help with implementing the other fixit, or you just need
>> some extra time? It seems to be almost the same as your second fixit
>>
>>
>>
>> 
>> Comment at: clang-tidy/misc/StringCompareCheck.cpp:69-70
>> +diag(Matched->getLocStart(),
>> + "do not use 'compare' to test equality of strings; "
>> + "use the string equality operator instead");
>> +
>> 
>> Take this warning to some static const global variable
>>
>>
>> 
>> Comment at: clang-tidy/misc/StringCompareCheck.cpp:71
>> + "use the string equality operator instead");
>> +
>> +  if (const auto *Matched = Result.Nodes.getNodeAs("match2")) {
>> 
>> match1 and match2 are in different matchers (passed to register matchers)?
>>
>> If so put return here after diag to finish control flow for this case.
>>
>>
>> 
>> Comment at: clang-tidy/misc/StringCompareCheck.cpp:81
>> +  auto Diag = diag(Matched->getLocStart(),
>> +   "do not use 'compare' to test equality of
>> strings; "
>> +   "use the string equality operator instead");
>> 
>> and use it here
>>
>>
>> 
>> Comment at: clang-tidy/misc/StringCompareCheck.h:10-11
>> +
>> +#ifndef STRING_COMPARE_CHECK_H
>> +#define STRING_COMPARE_CHECK_H
>> +
>> 
>> This should be much longer string. Do you know about ./add_new_check?
>>
>> Please make one similar to other checks
>>
>>
>> 
>> Comment at: clang-tidy/misc/StringCompareCheck.h:36
>> +
>> +#endif // STRING_COMPARE_CHECK_H
>> 
>> DITTO
>>
>>
>> 
>> Comment at: test/clang-tidy/misc-string-compare.cpp:35-40
>> +  if (str1.compare(str2)) {
>> +  }
>> +  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to
>> test equality of strings; use the string equality operator instead
>> [misc-string-compare]
>> +  if (!str1.compare(str2)) {
>> +  }
>> +  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: do not use 'compare' to
>> test equality of strings; use the string equality operator instead
>> [misc-string-compare]
>> 
>> Why this one doesn't have fixit hint?
>>
>>
>> 
>> Comment at: test/clang-tidy/misc-string-compare.cpp:70
>> +  }
>> +  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to
>> test equality of strings;
>> +  if (str3->compare(str2) == 0) {
>> 
>> no fixit?
>>
>>
>> https://reviews.llvm.org/D27210
>>
>>
>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r290424 - Use after move bug fixes

2016-12-23 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Fri Dec 23 05:40:44 2016
New Revision: 290424

URL: http://llvm.org/viewvc/llvm-project?rev=290424&view=rev
Log:
Use after move bug fixes

Summary: Bunch of fixed bugs in Clang after running misc-use-after-move in 
clang-tidy.

Reviewers: rsmith, mboehme

Subscribers: cfe-commits, klimek

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

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/SortJavaScriptImports.cpp
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/lib/Lex/ModuleMap.cpp
cfe/trunk/lib/Tooling/RefactoringCallbacks.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=290424&r1=290423&r2=290424&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Dec 23 05:40:44 2016
@@ -844,9 +844,10 @@ private:
   Env.getSourceManager(), Start, Length, ReplacementText));
   // FIXME: handle error. For now, print error message and skip the
   // replacement for release version.
-  if (Err)
+  if (Err) {
 llvm::errs() << llvm::toString(std::move(Err)) << "\n";
-  assert(!Err);
+assert(false);
+  }
 };
 Replace(Start, 1, IsSingle ? "'" : "\"");
 Replace(FormatTok->Tok.getEndLoc().getLocWithOffset(-1), 1,
@@ -1193,9 +1194,10 @@ private:
   Fixes.add(tooling::Replacement(Env.getSourceManager(), SR, ""));
   // FIXME: better error handling. for now just print error message and 
skip
   // for the release version.
-  if (Err)
+  if (Err) {
 llvm::errs() << llvm::toString(std::move(Err)) << "\n";
-  assert(!Err && "Fixes must not conflict!");
+assert(false && "Fixes must not conflict!");
+  }
   Idx = End + 1;
 }
 
@@ -1327,9 +1329,10 @@ static void sortCppIncludes(const Format
   FileName, Includes.front().Offset, IncludesBlockSize, result));
   // FIXME: better error handling. For now, just skip the replacement for the
   // release version.
-  if (Err)
+  if (Err) {
 llvm::errs() << llvm::toString(std::move(Err)) << "\n";
-  assert(!Err);
+assert(false);
+  }
 }
 
 namespace {

Modified: cfe/trunk/lib/Format/SortJavaScriptImports.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/SortJavaScriptImports.cpp?rev=290424&r1=290423&r2=290424&view=diff
==
--- cfe/trunk/lib/Format/SortJavaScriptImports.cpp (original)
+++ cfe/trunk/lib/Format/SortJavaScriptImports.cpp Fri Dec 23 05:40:44 2016
@@ -197,9 +197,10 @@ public:
 ReferencesText));
 // FIXME: better error handling. For now, just print error message and skip
 // the replacement for the release version.
-if (Err)
+if (Err) {
   llvm::errs() << llvm::toString(std::move(Err)) << "\n";
-assert(!Err);
+  assert(false);
+}
 
 return Result;
   }

Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=290424&r1=290423&r2=290424&view=diff
==
--- cfe/trunk/lib/Format/WhitespaceManager.cpp (original)
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp Fri Dec 23 05:40:44 2016
@@ -501,9 +501,10 @@ void WhitespaceManager::storeReplacement
   SourceMgr, CharSourceRange::getCharRange(Range), Text));
   // FIXME: better error handling. For now, just print an error message in the
   // release version.
-  if (Err)
+  if (Err) {
 llvm::errs() << llvm::toString(std::move(Err)) << "\n";
-  assert(!Err);
+assert(false);
+  }
 }
 
 void WhitespaceManager::appendNewlineText(std::string &Text,

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=290424&r1=290423&r2=290424&view=diff
==
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Fri Dec 23 05:40:44 2016
@@ -827,7 +827,7 @@ void ModuleMap::addHeader(Module *Mod, M
   return;
 
   HeaderList.push_back(KH);
-  Mod->Headers[headerRoleToKind(Role)].push_back(std::move(Header));
+  Mod->Headers[headerRoleToKind(Role)].push_back(Header);
 
   bool isCompilingModuleHeader =
   LangOpts.isCompilingModule() && Mod->getTopLevelModule() == SourceModule;

Modified: cfe/trunk/lib/Tooling/RefactoringCallbacks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/RefactoringCallbacks.cpp?rev=290424&r1=290423&r2=290424&view=diff
==
--- cfe/trunk/lib/Tooling/RefactoringCallbacks.cpp (original)
+++ cfe/trunk/lib/Tooling/RefactoringCallbacks.cpp Fri Dec 23 05:4

r290675 - Mention devirtualization in release notes

2016-12-28 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Wed Dec 28 12:23:23 2016
New Revision: 290675

URL: http://llvm.org/viewvc/llvm-project?rev=290675&view=rev
Log:
Mention devirtualization in release notes

Modified:
cfe/trunk/docs/ReleaseNotes.rst

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=290675&r1=290674&r2=290675&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Wed Dec 28 12:23:23 2016
@@ -47,6 +47,24 @@ sections with improvements to Clang's su
 Major New Features
 --
 
+- Enhanced devirtualization with `-fstrict-vtable-pointers`. Clang 
devirtualizes
+across different basic blocks, like loops:
+
+.. code-block:: c++
+   struct A {
+   virtual void foo() {}
+   };
+   void indirect(A &a, int n) {
+   for (int i = 0 ; i < n; i++)
+   a.foo();
+
+   }
+   void test(int n) {
+   A a;
+   indirect(a);
+   }
+
+
 -  ...
 
 Improvements to Clang's diagnostics


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


r290676 - Revert "Mention devirtualization in release notes"

2016-12-28 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Wed Dec 28 12:25:30 2016
New Revision: 290676

URL: http://llvm.org/viewvc/llvm-project?rev=290676&view=rev
Log:
Revert "Mention devirtualization in release notes"

Accidental commit. LLVM changes have not been pushed yet
This reverts commit 592453413690a2d16784667d1644758b9af700c1.

Modified:
cfe/trunk/docs/ReleaseNotes.rst

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=290676&r1=290675&r2=290676&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Wed Dec 28 12:25:30 2016
@@ -47,24 +47,6 @@ sections with improvements to Clang's su
 Major New Features
 --
 
-- Enhanced devirtualization with `-fstrict-vtable-pointers`. Clang 
devirtualizes
-across different basic blocks, like loops:
-
-.. code-block:: c++
-   struct A {
-   virtual void foo() {}
-   };
-   void indirect(A &a, int n) {
-   for (int i = 0 ; i < n; i++)
-   a.foo();
-
-   }
-   void test(int n) {
-   A a;
-   indirect(a);
-   }
-
-
 -  ...
 
 Improvements to Clang's diagnostics


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


r290677 - [ItaniumABI] NFC changes

2016-12-28 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Wed Dec 28 12:26:08 2016
New Revision: 290677

URL: http://llvm.org/viewvc/llvm-project?rev=290677&view=rev
Log:
[ItaniumABI] NFC changes

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

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=290677&r1=290676&r2=290677&view=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Wed Dec 28 12:26:08 2016
@@ -366,11 +366,12 @@ public:
   void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type) override;
 
  private:
-   bool hasAnyUsedVirtualInlineFunction(const CXXRecordDecl *RD) const {
+   bool hasAnyVirtualInlineFunction(const CXXRecordDecl *RD) const {
 const auto &VtableLayout =
 CGM.getItaniumVTableContext().getVTableLayout(RD);
 
 for (const auto &VtableComponent : VtableLayout.vtable_components()) {
+  // Skip empty slot.
   if (!VtableComponent.isUsedFunctionPointerKind())
 continue;
 
@@ -1687,7 +1688,7 @@ bool ItaniumCXXABI::canSpeculativelyEmit
   // then we are safe to emit available_externally copy of vtable.
   // FIXME we can still emit a copy of the vtable if we
   // can emit definition of the inline functions.
-  return !hasAnyUsedVirtualInlineFunction(RD) && !isVTableHidden(RD);
+  return !hasAnyVirtualInlineFunction(RD) && !isVTableHidden(RD);
 }
 static llvm::Value *performTypeAdjustment(CodeGenFunction &CGF,
   Address InitialPtr,


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


Re: [PATCH] D23343: [clang-tidy] modernize-make-{smart_ptr} private ctor bugfix

2016-08-16 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.


Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:35
@@ +34,3 @@
+  auto CanCallCtor = unless(has(ignoringImpCasts(cxxConstructExpr(
+  hasDeclaration(decl(anyOf(isPrivate(), isProtected(;
+

aaron.ballman wrote:
> Perhaps: `unless(isPublic())` instead of `anyOf(isPrivate(), isProtected())`?
POD types doesn't have public constructors so it will fail :)


https://reviews.llvm.org/D23343



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


Re: [PATCH] D23343: [clang-tidy] modernize-make-{smart_ptr} private ctor bugfix

2016-08-16 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.


Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:35
@@ +34,3 @@
+  auto CanCallCtor = unless(has(ignoringImpCasts(cxxConstructExpr(
+  hasDeclaration(decl(anyOf(isPrivate(), isProtected(;
+

aaron.ballman wrote:
> Prazek wrote:
> > aaron.ballman wrote:
> > > Perhaps: `unless(isPublic())` instead of `anyOf(isPrivate(), 
> > > isProtected())`?
> > POD types doesn't have public constructors so it will fail :)
> Don't they have an implicit one for the purposes of a CXXConstructExpr? 
> Looking at an AST dump for:
> ```
> struct S {
>   int i;
> };
> ```
> yields:
> ```
> |-CXXRecordDecl 0x26d74ae5348  line:25:8 referenced 
> struct S definition
> | |-CXXRecordDecl 0x26d74ae5460  col:8 implicit struct S
> | |-FieldDecl 0x26d74ae7880  col:7 i 'int'
> | |-CXXConstructorDecl 0x26d74ae87b8  col:8 implicit used S 'void 
> (void) noexcept' inline
> | | `-CompoundStmt 0x26d74ae3850 
> | |-CXXConstructorDecl 0x26d74ae34a8  col:8 implicit constexpr S 'void 
> (const struct S &)' inline noexcept-unevaluated 0x26d74ae34a8
> | | `-ParmVarDecl 0x26d74ae35e0  col:8 'const struct S &'
> | `-CXXConstructorDecl 0x26d74ae3678  col:8 implicit constexpr S 'void 
> (struct S &&)' inline noexcept-unevaluated 0x26d74ae3678
> |   `-ParmVarDecl 0x26d74ae37b0  col:8 'struct S &&'
> ```
what about std::shared_ptr x = std::shared_ptr(new int); ?
If I recall correctly, it didn't work on this test.


https://reviews.llvm.org/D23343



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


Re: [PATCH] D23343: [clang-tidy] modernize-make-{smart_ptr} private ctor bugfix

2016-08-17 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.


Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:32-33
@@ -31,1 +31,4 @@
 
+  // Calling make_smart_ptr from within a member function of a type with a
+  // private or protected constructor would be ill-formed.
+  auto CanCallCtor = unless(has(ignoringImpCasts(cxxConstructExpr(

alexfh wrote:
> malcolm.parsons wrote:
> > The private constructor could also be called from a friend class.
> It might only be relevant, if `std::make_(shared|unique)` is declared as a 
> friend of the class in question, which is unlikely to be a common case and I 
> don't think we need to focus on this now.
I am totally aware of it, but I never saw a friend delcaration for any 
class/function from libc++.


https://reviews.llvm.org/D23343



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


Re: [PATCH] D23343: [clang-tidy] modernize-make-{smart_ptr} private ctor bugfix

2016-08-17 Thread Piotr Padlewski via cfe-commits
Prazek marked 8 inline comments as done.


Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:35
@@ +34,3 @@
+  auto CanCallCtor = unless(has(ignoringImpCasts(cxxConstructExpr(
+  hasDeclaration(decl(anyOf(isPrivate(), isProtected(;
+

alexfh wrote:
> Prazek wrote:
> > aaron.ballman wrote:
> > > Prazek wrote:
> > > > aaron.ballman wrote:
> > > > > Perhaps: `unless(isPublic())` instead of `anyOf(isPrivate(), 
> > > > > isProtected())`?
> > > > POD types doesn't have public constructors so it will fail :)
> > > Don't they have an implicit one for the purposes of a CXXConstructExpr? 
> > > Looking at an AST dump for:
> > > ```
> > > struct S {
> > >   int i;
> > > };
> > > ```
> > > yields:
> > > ```
> > > |-CXXRecordDecl 0x26d74ae5348  line:25:8 referenced 
> > > struct S definition
> > > | |-CXXRecordDecl 0x26d74ae5460  col:8 implicit struct S
> > > | |-FieldDecl 0x26d74ae7880  col:7 i 'int'
> > > | |-CXXConstructorDecl 0x26d74ae87b8  col:8 implicit used S 
> > > 'void (void) noexcept' inline
> > > | | `-CompoundStmt 0x26d74ae3850 
> > > | |-CXXConstructorDecl 0x26d74ae34a8  col:8 implicit constexpr S 
> > > 'void (const struct S &)' inline noexcept-unevaluated 0x26d74ae34a8
> > > | | `-ParmVarDecl 0x26d74ae35e0  col:8 'const struct S &'
> > > | `-CXXConstructorDecl 0x26d74ae3678  col:8 implicit constexpr S 
> > > 'void (struct S &&)' inline noexcept-unevaluated 0x26d74ae3678
> > > |   `-ParmVarDecl 0x26d74ae37b0  col:8 'struct S &&'
> > > ```
> > what about std::shared_ptr x = std::shared_ptr(new int); ?
> > If I recall correctly, it didn't work on this test.
> There's no `CXXConstructExpr` for primitive types:
> ```
> $ cat /tmp/qq.cc 
> #include 
> 
> struct S { S(); };
> void () {
>   std::shared_ptr p1 = std::shared_ptr(new int);
>   std::shared_ptr p2 = std::shared_ptr(new S);
> }
> $ clang-check -ast-dump -ast-dump-filter= /tmp/qq.cc -- -std=c++11
> Dumping :
> FunctionDecl 0x7f48270fb6e0  line:4:6  'void 
> (void)'
> `-CompoundStmt 0x7f48271582a8 
>   |-DeclStmt 0x7f4827131000 
>   | `-VarDecl 0x7f48270fb9c8  col:24 p1 
> 'std::shared_ptr':'class std::shared_ptr' cinit
>   |   `-ExprWithCleanups 0x7f4827130fe8  
> 'std::shared_ptr':'class std::shared_ptr'
>   | `-CXXConstructExpr 0x7f4827130fb0  
> 'std::shared_ptr':'class std::shared_ptr' 'void (class 
> std::shared_ptr &&) noexcept' elidable
>   |   `-MaterializeTemporaryExpr 0x7f4827130f98  'class 
> std::shared_ptr' xvalue
>   | `-CXXFunctionalCastExpr 0x7f48271303c8  
> 'std::shared_ptr':'class std::shared_ptr' functional cast to 
> std::shared_ptr 
>   |   `-CXXBindTemporaryExpr 0x7f48271303a8  
> 'std::shared_ptr':'class std::shared_ptr' (CXXTemporary 
> 0x7f48271303a0)
>   | `-CXXConstructExpr 0x7f4827130338  
> 'std::shared_ptr':'class std::shared_ptr' 'void (int *)'
>   |   `-CXXNewExpr 0x7f48270fbb58  'int *' 
> Function 0x7f4826a1c000 'operator new' 'void *(std::size_t)'
>   `-DeclStmt 0x7f4827158290 
> `-VarDecl 0x7f4827131238  col:22 p2 
> 'std::shared_ptr':'class std::shared_ptr' cinit
>   `-ExprWithCleanups 0x7f4827158278  
> 'std::shared_ptr':'class std::shared_ptr'
> `-CXXConstructExpr 0x7f4827158240  
> 'std::shared_ptr':'class std::shared_ptr' 'void (class 
> std::shared_ptr &&) noexcept' elidable
>   `-MaterializeTemporaryExpr 0x7f4827158228  'class 
> std::shared_ptr' xvalue
> `-CXXFunctionalCastExpr 0x7f4827157658  
> 'std::shared_ptr':'class std::shared_ptr' functional cast to 
> std::shared_ptr 
>   `-CXXBindTemporaryExpr 0x7f4827157638  
> 'std::shared_ptr':'class std::shared_ptr' (CXXTemporary 
> 0x7f4827157630)
> `-CXXConstructExpr 0x7f48271575c8  
> 'std::shared_ptr':'class std::shared_ptr' 'void (struct S *)'
>   `-CXXNewExpr 0x7f4827131838  'struct S *' 
> Function 0x7f4826a1c000 'operator new' 'void *(std::size_t)'
> `-CXXConstructExpr 0x7f4827131808  'struct S' 
> 'void (void)'
> ```
exactly.


https://reviews.llvm.org/D23343



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


Re: [PATCH] D23343: [clang-tidy] modernize-make-{smart_ptr} private ctor bugfix

2016-08-17 Thread Piotr Padlewski via cfe-commits
Prazek marked 2 inline comments as done.
Prazek added a comment.

https://reviews.llvm.org/D23343



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


Re: [PATCH] D23353: [clang-tidy] Add check 'misc-use-after-move'

2016-08-17 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

In https://reviews.llvm.org/D23353#516314, @mboehme wrote:

> In https://reviews.llvm.org/D23353#511362, @Prazek wrote:
>
> > I will review it later, but my first thoughts:
> >
> > 1. I think we should make some other group, because misc seems to be 
> > overloaded. I discussed it with Alex months ago - something like bugprone 
> > would be good.
>
>
> Agree that "misc" seems pretty overcrowded. I'll defer to those who have been 
> working on clang-tidy longer than me to make this call.
>
> > 2. Also it would be good to make link in cppcoreguidelines.
>
>
> How exactly would I create such a "link"? Are you just thinking of a link in 
> the documentation, or is there a way to have one clang-tidy check activate 
> another (and is this what you're thinking of)?


I am not sure if there is any other mechanism than just links in documentation. 
In the perfect word it would be nice to invoke this check using 
cppcoreguidelines-use-after-move also with some special options like Pedantic=1 
(That would warn about any use after move, even after reinitialization - this 
is what cppcoreguidelines says)



Comment at: clang-tidy/misc/UseAfterMoveCheck.cpp:134
@@ +133,3 @@
+/// various internal helper functions).
+class UseAfterMoveFinder {
+public:

What do you think about moving this, and maybe other things to some different 
header file to make it not so scary?


Comment at: clang-tidy/misc/UseAfterMoveCheck.cpp:649-652
@@ +648,6 @@
+FunctionBody = ContainingFunc->getBody();
+  }
+
+  if (!FunctionBody)
+return;
+

you can replace it with 
  else
return;


Comment at: test/clang-tidy/misc-use-after-move.cpp:504-505
@@ +503,4 @@
+std::move(a);
+a = A();
+a.foo();
+  }

I would like to mark it as use after move with some pedantic flag


https://reviews.llvm.org/D23353



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


Re: [PATCH] D23343: [clang-tidy] modernize-make-{smart_ptr} private ctor bugfix

2016-08-19 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.


Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:35
@@ +34,3 @@
+  auto CanCallCtor = unless(has(ignoringImpCasts(cxxConstructExpr(
+  hasDeclaration(decl(anyOf(isPrivate(), isProtected(;
+

alexfh wrote:
> Prazek wrote:
> > alexfh wrote:
> > > Prazek wrote:
> > > > aaron.ballman wrote:
> > > > > Prazek wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > Perhaps: `unless(isPublic())` instead of `anyOf(isPrivate(), 
> > > > > > > isProtected())`?
> > > > > > POD types doesn't have public constructors so it will fail :)
> > > > > Don't they have an implicit one for the purposes of a 
> > > > > CXXConstructExpr? Looking at an AST dump for:
> > > > > ```
> > > > > struct S {
> > > > >   int i;
> > > > > };
> > > > > ```
> > > > > yields:
> > > > > ```
> > > > > |-CXXRecordDecl 0x26d74ae5348  line:25:8 
> > > > > referenced struct S definition
> > > > > | |-CXXRecordDecl 0x26d74ae5460  col:8 implicit struct S
> > > > > | |-FieldDecl 0x26d74ae7880  col:7 i 'int'
> > > > > | |-CXXConstructorDecl 0x26d74ae87b8  col:8 implicit used 
> > > > > S 'void (void) noexcept' inline
> > > > > | | `-CompoundStmt 0x26d74ae3850 
> > > > > | |-CXXConstructorDecl 0x26d74ae34a8  col:8 implicit constexpr 
> > > > > S 'void (const struct S &)' inline noexcept-unevaluated 0x26d74ae34a8
> > > > > | | `-ParmVarDecl 0x26d74ae35e0  col:8 'const struct S &'
> > > > > | `-CXXConstructorDecl 0x26d74ae3678  col:8 implicit constexpr 
> > > > > S 'void (struct S &&)' inline noexcept-unevaluated 0x26d74ae3678
> > > > > |   `-ParmVarDecl 0x26d74ae37b0  col:8 'struct S &&'
> > > > > ```
> > > > what about std::shared_ptr x = std::shared_ptr(new int); ?
> > > > If I recall correctly, it didn't work on this test.
> > > There's no `CXXConstructExpr` for primitive types:
> > > ```
> > > $ cat /tmp/qq.cc 
> > > #include 
> > > 
> > > struct S { S(); };
> > > void () {
> > >   std::shared_ptr p1 = std::shared_ptr(new int);
> > >   std::shared_ptr p2 = std::shared_ptr(new S);
> > > }
> > > $ clang-check -ast-dump -ast-dump-filter= /tmp/qq.cc -- -std=c++11
> > > Dumping :
> > > FunctionDecl 0x7f48270fb6e0  line:4:6  
> > > 'void (void)'
> > > `-CompoundStmt 0x7f48271582a8 
> > >   |-DeclStmt 0x7f4827131000 
> > >   | `-VarDecl 0x7f48270fb9c8  col:24 p1 
> > > 'std::shared_ptr':'class std::shared_ptr' cinit
> > >   |   `-ExprWithCleanups 0x7f4827130fe8  
> > > 'std::shared_ptr':'class std::shared_ptr'
> > >   | `-CXXConstructExpr 0x7f4827130fb0  
> > > 'std::shared_ptr':'class std::shared_ptr' 'void (class 
> > > std::shared_ptr &&) noexcept' elidable
> > >   |   `-MaterializeTemporaryExpr 0x7f4827130f98  
> > > 'class std::shared_ptr' xvalue
> > >   | `-CXXFunctionalCastExpr 0x7f48271303c8  
> > > 'std::shared_ptr':'class std::shared_ptr' functional cast to 
> > > std::shared_ptr 
> > >   |   `-CXXBindTemporaryExpr 0x7f48271303a8  
> > > 'std::shared_ptr':'class std::shared_ptr' (CXXTemporary 
> > > 0x7f48271303a0)
> > >   | `-CXXConstructExpr 0x7f4827130338  
> > > 'std::shared_ptr':'class std::shared_ptr' 'void (int *)'
> > >   |   `-CXXNewExpr 0x7f48270fbb58  'int *' 
> > > Function 0x7f4826a1c000 'operator new' 'void *(std::size_t)'
> > >   `-DeclStmt 0x7f4827158290 
> > > `-VarDecl 0x7f4827131238  col:22 p2 
> > > 'std::shared_ptr':'class std::shared_ptr' cinit
> > >   `-ExprWithCleanups 0x7f4827158278  
> > > 'std::shared_ptr':'class std::shared_ptr'
> > > `-CXXConstructExpr 0x7f4827158240  
> > > 'std::shared_ptr':'class std::shared_ptr' 'void (class 
> > > std::shared_ptr &&) noexcept' elidable
> > >   `-MaterializeTemporaryExpr 0x7f4827158228  
> > > 'class std::shared_ptr' xvalue
> > > `-CXXFunctionalCastExpr 0x7f4827157658  
> > > 'std::shared_ptr':'class std::shared_ptr' functional cast to 
> > > std::shared_ptr 
> > >   `-CXXBindTemporaryExpr 0x7f4827157638  
> > > 'std::shared_ptr':'class std::shared_ptr' (CXXTemporary 
> > > 0x7f4827157630)
> > > `-CXXConstructExpr 0x7f48271575c8  
> > > 'std::shared_ptr':'class std::shared_ptr' 'void (struct S *)'
> > >   `-CXXNewExpr 0x7f4827131838  'struct S 
> > > *' Function 0x7f4826a1c000 'operator new' 'void *(std::size_t)'
> > > `-CXXConstructExpr 0x7f4827131808  'struct S' 
> > > 'void (void)'
> > > ```
> > exactly.
> But this means that `unless(isPublic())` should work, IIUC.
Oh I see.
Yea I remember right now what I did:
has(ignoringImpCasts(cxxConstructExpr(
  hasDeclaration(decl(isPublic(

This ofc not gonna work, but 

unless(has(ignoringImpCasts(cxxConstructExpr(
  hasDeclaration(decl(unless(isPublic(

should be totally fine


https://reviews.llvm.org/D23343



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


Re: [PATCH] D23343: [clang-tidy] modernize-make-{smart_ptr} private ctor bugfix

2016-08-21 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 68824.
Prazek added a comment.

- fixes


https://reviews.llvm.org/D23343

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  docs/ReleaseNotes.rst
  test/clang-tidy/modernize-make-shared.cpp
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -103,6 +103,38 @@
   std::unique_ptr Placement = std::unique_ptr(new (PInt) int{3});
 }
 
+// Calling make_smart_ptr from within a member function of a type with a
+// private or protected constructor would be ill-formed.
+class Private {
+private:
+  Private(int z) {}
+
+public:
+  Private() {}
+  void create() {
+auto callsPublic = std::unique_ptr(new Private);
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_unique instead
+// CHECK-FIXES: auto callsPublic = std::make_unique();
+auto ptr = std::unique_ptr(new Private(42));
+  }
+
+  virtual ~Private();
+};
+
+class Protected {
+protected:
+  Protected() {}
+
+public:
+  Protected(int, int) {}
+  void create() {
+auto callsPublic = std::unique_ptr(new Protected(1, 2));
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_unique instead
+// CHECK-FIXES: auto callsPublic = std::make_unique(1, 2);
+auto ptr = std::unique_ptr(new Protected);
+  }
+};
+
 void initialization(int T, Base b) {
   // Test different kinds of initialization of the pointee.
 
Index: test/clang-tidy/modernize-make-shared.cpp
===
--- test/clang-tidy/modernize-make-shared.cpp
+++ test/clang-tidy/modernize-make-shared.cpp
@@ -100,6 +100,38 @@
   std::shared_ptr Placement = std::shared_ptr(new (PInt) int{3});
 }
 
+// Calling make_smart_ptr from within a member function of a type with a
+// private or protected constructor would be ill-formed.
+class Private {
+private:
+  Private(int z) {}
+
+public:
+  Private() {}
+  void create() {
+auto callsPublic = std::shared_ptr(new Private);
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_shared instead
+// CHECK-FIXES: auto callsPublic = std::make_shared();
+auto ptr = std::shared_ptr(new Private(42));
+  }
+
+  virtual ~Private();
+};
+
+class Protected {
+protected:
+  Protected() {}
+
+public:
+  Protected(int, int) {}
+  void create() {
+auto callsPublic = std::shared_ptr(new Protected(1, 2));
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_shared instead
+// CHECK-FIXES: auto callsPublic = std::make_shared(1, 2);
+auto ptr = std::shared_ptr(new Protected);
+  }
+};
+
 void initialization(int T, Base b) {
   // Test different kinds of initialization of the pointee.
 
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -85,6 +85,15 @@
   Warns about the performance overhead arising from concatenating strings using
   the ``operator+``, instead of ``operator+=``.
 
+
+Fixed bugs:
+- `modernize-make-unique
+  `_
+  and `modernize-make-shared
+  `_
+  Calling ``make_{unique|shared}`` from within a member function of a type
+  with a private or protected constructor would be ill-formed.
+
 Improvements to include-fixer
 -
 
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -29,13 +29,19 @@
   if (!getLangOpts().CPlusPlus11)
 return;
 
+  // Calling make_smart_ptr from within a member function of a type with a
+  // private or protected constructor would be ill-formed.
+  auto CanCallCtor = unless(has(ignoringImpCasts(cxxConstructExpr(
+  hasDeclaration(decl(unless(isPublic(;
+
   Finder->addMatcher(
   cxxBindTemporaryExpr(has(ignoringParenImpCasts(
   cxxConstructExpr(
   hasType(getSmartPointerTypeMatcher()), argumentCountIs(1),
   hasArgument(0,
   cxxNewExpr(hasType(pointsTo(qualType(hasCanonicalType(
- equalsBoundNode(PointerType))
+ equalsBoundNode(PointerType),
+ CanCallCtor)
   .bind(NewExpression)))
   .bind(ConstructorCall,
   this);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r280180 - [clang-tidy] modernize-make-{smart_ptr} private ctor bugfix

2016-08-30 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Tue Aug 30 19:06:55 2016
New Revision: 280180

URL: http://llvm.org/viewvc/llvm-project?rev=280180&view=rev
Log:
[clang-tidy] modernize-make-{smart_ptr} private ctor bugfix

Summary:
Bugfix for 27321. When the constructor of stored pointer
type is private then it is invalid to change it to
make_shared or make_unique.

Reviewers: alexfh, aaron.ballman, hokein

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp?rev=280180&r1=280179&r2=280180&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp Tue Aug 
30 19:06:55 2016
@@ -29,13 +29,19 @@ void MakeSmartPtrCheck::registerMatchers
   if (!getLangOpts().CPlusPlus11)
 return;
 
+  // Calling make_smart_ptr from within a member function of a type with a
+  // private or protected constructor would be ill-formed.
+  auto CanCallCtor = unless(has(ignoringImpCasts(cxxConstructExpr(
+  hasDeclaration(decl(unless(isPublic(;
+
   Finder->addMatcher(
   cxxBindTemporaryExpr(has(ignoringParenImpCasts(
   cxxConstructExpr(
   hasType(getSmartPointerTypeMatcher()), argumentCountIs(1),
   hasArgument(0,
   
cxxNewExpr(hasType(pointsTo(qualType(hasCanonicalType(
- equalsBoundNode(PointerType))
+ equalsBoundNode(PointerType),
+ CanCallCtor)
   .bind(NewExpression)))
   .bind(ConstructorCall,
   this);

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=280180&r1=280179&r2=280180&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Tue Aug 30 19:06:55 2016
@@ -97,6 +97,14 @@ Improvements to clang-tidy
   Flags function parameters of a pointer type that could be changed to point to
   a constant type instead.
 
+Fixed bugs:
+- `modernize-make-unique
+  `_
+  and `modernize-make-shared
+  `_
+  Calling ``make_{unique|shared}`` from within a member function of a type
+  with a private or protected constructor would be ill-formed.
+
 Improvements to include-fixer
 -
 

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared.cpp?rev=280180&r1=280179&r2=280180&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared.cpp Tue Aug 
30 19:06:55 2016
@@ -100,6 +100,38 @@ void basic() {
   std::shared_ptr Placement = std::shared_ptr(new (PInt) int{3});
 }
 
+// Calling make_smart_ptr from within a member function of a type with a
+// private or protected constructor would be ill-formed.
+class Private {
+private:
+  Private(int z) {}
+
+public:
+  Private() {}
+  void create() {
+auto callsPublic = std::shared_ptr(new Private);
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_shared instead
+// CHECK-FIXES: auto callsPublic = std::make_shared();
+auto ptr = std::shared_ptr(new Private(42));
+  }
+
+  virtual ~Private();
+};
+
+class Protected {
+protected:
+  Protected() {}
+
+public:
+  Protected(int, int) {}
+  void create() {
+auto callsPublic = std::shared_ptr(new Protected(1, 2));
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_shared instead
+// CHECK-FIXES: auto callsPublic = std::make_shared(1, 2);
+auto ptr = std::shared_ptr(new Protected);
+  }
+};
+
 void initialization(int T, Base b) {
   // Test different kinds of initialization of the pointee.
 

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp?rev=280180&r1=280179&r2=280180&view=diff
===

Re: [PATCH] D23343: [clang-tidy] modernize-make-{smart_ptr} private ctor bugfix

2016-08-30 Thread Piotr Padlewski via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL280180: [clang-tidy] modernize-make-{smart_ptr} private ctor 
bugfix (authored by Prazek).

Changed prior to commit:
  https://reviews.llvm.org/D23343?vs=68824&id=69787#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23343

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp

Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
@@ -103,6 +103,38 @@
   std::unique_ptr Placement = std::unique_ptr(new (PInt) int{3});
 }
 
+// Calling make_smart_ptr from within a member function of a type with a
+// private or protected constructor would be ill-formed.
+class Private {
+private:
+  Private(int z) {}
+
+public:
+  Private() {}
+  void create() {
+auto callsPublic = std::unique_ptr(new Private);
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_unique instead
+// CHECK-FIXES: auto callsPublic = std::make_unique();
+auto ptr = std::unique_ptr(new Private(42));
+  }
+
+  virtual ~Private();
+};
+
+class Protected {
+protected:
+  Protected() {}
+
+public:
+  Protected(int, int) {}
+  void create() {
+auto callsPublic = std::unique_ptr(new Protected(1, 2));
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_unique instead
+// CHECK-FIXES: auto callsPublic = std::make_unique(1, 2);
+auto ptr = std::unique_ptr(new Protected);
+  }
+};
+
 void initialization(int T, Base b) {
   // Test different kinds of initialization of the pointee.
 
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared.cpp
@@ -100,6 +100,38 @@
   std::shared_ptr Placement = std::shared_ptr(new (PInt) int{3});
 }
 
+// Calling make_smart_ptr from within a member function of a type with a
+// private or protected constructor would be ill-formed.
+class Private {
+private:
+  Private(int z) {}
+
+public:
+  Private() {}
+  void create() {
+auto callsPublic = std::shared_ptr(new Private);
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_shared instead
+// CHECK-FIXES: auto callsPublic = std::make_shared();
+auto ptr = std::shared_ptr(new Private(42));
+  }
+
+  virtual ~Private();
+};
+
+class Protected {
+protected:
+  Protected() {}
+
+public:
+  Protected(int, int) {}
+  void create() {
+auto callsPublic = std::shared_ptr(new Protected(1, 2));
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_shared instead
+// CHECK-FIXES: auto callsPublic = std::make_shared(1, 2);
+auto ptr = std::shared_ptr(new Protected);
+  }
+};
+
 void initialization(int T, Base b) {
   // Test different kinds of initialization of the pointee.
 
Index: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -29,13 +29,19 @@
   if (!getLangOpts().CPlusPlus11)
 return;
 
+  // Calling make_smart_ptr from within a member function of a type with a
+  // private or protected constructor would be ill-formed.
+  auto CanCallCtor = unless(has(ignoringImpCasts(cxxConstructExpr(
+  hasDeclaration(decl(unless(isPublic(;
+
   Finder->addMatcher(
   cxxBindTemporaryExpr(has(ignoringParenImpCasts(
   cxxConstructExpr(
   hasType(getSmartPointerTypeMatcher()), argumentCountIs(1),
   hasArgument(0,
   cxxNewExpr(hasType(pointsTo(qualType(hasCanonicalType(
- equalsBoundNode(PointerType))
+ equalsBoundNode(PointerType),
+ CanCallCtor)
   .bind(NewExpression)))
   .bind(ConstructorCall,
   this);
Index: clang-tools-extra/trunk/docs/ReleaseNotes.rst
===
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst
@@ -97,6 +97,14 @@
   Flags function parameters of a pointer type that could be changed to point to
   a constant type instead.
 
+Fixed bugs:
+- `modernize-make-unique
+  `_
+  and `modernize-make-share

Re: [PATCH] D23343: [clang-tidy] modernize-make-{smart_ptr} private ctor bugfix

2016-08-30 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

Sorry for long delay. I had some issues with git-svn on mac.


Repository:
  rL LLVM

https://reviews.llvm.org/D23343



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


Re: [PATCH] D23353: [clang-tidy] Add check 'misc-use-after-move'

2016-09-01 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.


Comment at: clang-tidy/misc/UseAfterMoveCheck.cpp:191
@@ +190,3 @@
+
+if (const Stmt *S = Node.get()) {
+  Result.push_back(S);

Dry: const auto *



https://reviews.llvm.org/D23353



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


Re: [PATCH] D24339: [clang-tidy] Add check 'readability-redundant-member-init'

2016-09-08 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.


Comment at: clang-tidy/readability/RedundantMemberInitCheck.cpp:34
@@ +33,3 @@
+  const auto *Construct = 
Result.Nodes.getNodeAs("construct");
+  const auto arguments = Construct->arguments();
+

Arguments (upper case)


Repository:
  rL LLVM

https://reviews.llvm.org/D24339



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


Re: [PATCH] D24349: [clang-tidy] Extend readability-container-size-empty to arbitrary class with size() and empty()

2016-09-08 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.


Comment at: clang-tidy/readability/ContainerSizeEmptyCheck.cpp:34
@@ +33,3 @@
+  has(functionDecl(
+  isPublic(), hasName("size"), returns(isInteger()),
+  unless(anyOf(returns(isAnyCharacter()), returns(booleanType()),

Would be nice to have 'isStrictlyInteger' matcher to do this thing.


Repository:
  rL LLVM

https://reviews.llvm.org/D24349



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


Re: [PATCH] D24439: [Clang] Fix some Clang-tidy modernize-use-bool-literals and Include What You Use warnings; other minor fixes

2016-09-10 Thread Piotr Padlewski via cfe-commits
Prazek added a subscriber: Prazek.
Prazek accepted this revision.
Prazek added a reviewer: Prazek.
Prazek added a comment.
This revision is now accepted and ready to land.

Lgtm


Repository:
  rL LLVM

https://reviews.llvm.org/D24439



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


Re: [PATCH] D22057: Prevent devirtualization of calls to un-instantiated functions.

2016-09-10 Thread Piotr Padlewski via cfe-commits
Prazek added a subscriber: Prazek.


Comment at: lib/Sema/Sema.cpp:684
@@ +683,3 @@
+  for (auto PII : Pending) 
+if (FunctionDecl *Func = dyn_cast(PII.first))
+  Func->setMarkedForPendingInstantiation();

Dry. Use auto


https://reviews.llvm.org/D22057



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


r292112 - Add -fstrict-vtable-pointers to UsersManual

2017-01-16 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Mon Jan 16 07:20:08 2017
New Revision: 292112

URL: http://llvm.org/viewvc/llvm-project?rev=292112&view=rev
Log:
Add -fstrict-vtable-pointers to UsersManual

Summary: Add missing flag to UsersManual
It would be good to merge it to 4.0 branch.

Reviewers: hans

Subscribers: cfe-commits

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

Modified:
cfe/trunk/docs/UsersManual.rst

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=292112&r1=292111&r2=292112&view=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Mon Jan 16 07:20:08 2017
@@ -1097,6 +1097,13 @@ are listed below.
the behavior of sanitizers in the ``cfi`` group to allow checking
of cross-DSO virtual and indirect calls.
 
+
+.. option:: -fstrict-vtable-pointers
+   Enable optimizations based on the strict rules for overwriting polymorphic
+   C++ objects, i.e. the vptr is invariant during an object's lifetime.
+   This enables better devirtualization. Turned off by default, because it is
+   still experimental.
+
 .. option:: -ffast-math
 
Enable fast-math mode. This defines the ``__FAST_MATH__`` preprocessor


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


[clang-tools-extra] r296867 - [clang-tidy] Fix modernize-use-emplace docs

2017-03-03 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Fri Mar  3 06:42:22 2017
New Revision: 296867

URL: http://llvm.org/viewvc/llvm-project?rev=296867&view=rev
Log:
[clang-tidy] Fix modernize-use-emplace docs

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst?rev=296867&r1=296866&r2=296867&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst 
Fri Mar  3 06:42:22 2017
@@ -36,7 +36,7 @@ After:
 
 std::vector> w;
 w.emplace_back(21, 37);
-// This will be fixed to w.push_back(21, 37); in next version
+// This will be fixed to w.emplace_back(21L, 37L); in next version
 w.emplace_back(std::make_pair(21L, 37L);
 
 The other situation is when we pass arguments that will be converted to a type


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


[clang-tools-extra] r296888 - [clang-tidy] Yet another docs fixes

2017-03-03 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Fri Mar  3 11:16:11 2017
New Revision: 296888

URL: http://llvm.org/viewvc/llvm-project?rev=296888&view=rev
Log:
[clang-tidy] Yet another docs fixes

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst?rev=296888&r1=296887&r2=296888&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst 
Fri Mar  3 11:16:11 2017
@@ -69,7 +69,7 @@ exception safe. In this case the calls o
 
 This is because replacing it with ``emplace_back`` could cause a leak of this
 pointer if ``emplace_back`` would throw exception before emplacement (e.g. not
-enough memory to add new element).
+enough memory to add a new element).
 
 For more info read item 42 - "Consider emplacement instead of insertion." of
 Scott Meyers "Effective Modern C++".
@@ -79,14 +79,15 @@ The default smart pointers that are cons
 other classes use the :option:`SmartPointers` option.
 
 
-Check also fires if any argument of constructor call would be:
+Check also doesn't fire if any argument of the constructor call would be:
 
-  - bitfield (bitfields can't bind to rvalue/universal reference)
+  - a bit-field (bit-fields can't bind to rvalue/universal reference)
 
-  - ``new`` expression (to avoid leak) or if the argument would be converted 
via
-derived-to-base cast.
+  - a ``new`` expression (to avoid leak)
 
-This check requires C++11 of higher to run.
+  - if the argument would be converted via derived-to-base cast.
+
+This check requires C++11 or higher to run.
 
 Options
 ---


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


[clang-tools-extra] r289656 - modernize-use-auto NFC fixes

2016-12-14 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Wed Dec 14 09:29:23 2016
New Revision: 289656

URL: http://llvm.org/viewvc/llvm-project?rev=289656&view=rev
Log:
modernize-use-auto NFC fixes

Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp

clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
clang-tools-extra/trunk/clang-query/Query.cpp
clang-tools-extra/trunk/clang-query/QueryParser.cpp
clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp
clang-tools-extra/trunk/clang-tidy/google/NonConstReferences.cpp
clang-tools-extra/trunk/clang-tidy/llvm/TwineLocalCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/MoveForwardingReferenceCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/MultipleStatementMacroCheck.cpp

clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
clang-tools-extra/trunk/clang-tidy/mpi/TypeMismatchCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
clang-tools-extra/trunk/modularize/CoverageChecker.cpp
clang-tools-extra/trunk/modularize/Modularize.cpp
clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp
clang-tools-extra/trunk/modularize/ModuleAssistant.cpp
clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
clang-tools-extra/trunk/pp-trace/PPTrace.cpp

clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
clang-tools-extra/trunk/unittests/clang-tidy/NamespaceAliaserTest.cpp
clang-tools-extra/trunk/unittests/clang-tidy/UsingInserterTest.cpp

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=289656&r1=289655&r2=289656&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Wed Dec 14 
09:29:23 2016
@@ -709,7 +709,7 @@ void ChangeNamespaceTool::fixTypeLoc(
   return;
   }
 
-  const Decl *DeclCtx = Result.Nodes.getNodeAs("dc");
+  const auto *DeclCtx = Result.Nodes.getNodeAs("dc");
   assert(DeclCtx && "Empty decl context.");
   replaceQualifiedSymbolInDeclContext(Result, DeclCtx->getDeclContext(), Start,
   End, FromDecl);

Modified: 
clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp?rev=289656&r1=289655&r2=289656&view=diff
==
--- 
clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
 Wed Dec 14 09:29:23 2016
@@ -124,9 +124,7 @@ static void reportConflict(
 bool applyAllReplacements(const std::vector &Replaces,
   Rewriter &Rewrite) {
   bool Result = true;
-  for (std::vector::const_iterator I = Replaces.begin(),
- E = Replaces.end();
-   I != E; ++I) {
+  for (auto I = Replaces.begin(), E = Replaces.end(); I != E; ++I) {
 if (I->isApplicable()) {
   Result = I->apply(Rewrite) && Result;
 } else {
@@ -293,8 +291,7 @@ RangeVector calculateChangedRanges(
 
 bool writeFiles(const clang::Rewriter &Rewrites) {
 
-  for (Rewriter::const_buffer_iterator BufferI = Rewrites.buffer_begin(),
-   BufferE = Rewrites.buffer_end();
+  for (auto BufferI = Rewrites.buffer_begin(), BufferE = Rewrites.buffer_end();
BufferI != BufferE; ++BufferI) {
 StringRef FileName =
 Rewrites.getSourceMgr().getFileEntryForID(BufferI->first)->getName();

Modified: clang-tools-extra/trunk/clang-query/Query.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-query/Query.cpp?rev=289656&r1=289655&r2=289656&view=diff
==
--- clang-

[clang-tools-extra] r289658 - Deleted unused typedef

2016-12-14 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Wed Dec 14 09:42:23 2016
New Revision: 289658

URL: http://llvm.org/viewvc/llvm-project?rev=289658&view=rev
Log:
Deleted unused typedef

Modified:
clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp

Modified: clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp?rev=289658&r1=289657&r2=289658&view=diff
==
--- clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp (original)
+++ clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp Wed Dec 14 
09:42:23 2016
@@ -75,7 +75,6 @@ ModularizeUtilities *ModularizeUtilities
 
 // Load all header lists and dependencies.
 std::error_code ModularizeUtilities::loadAllHeaderListsAndDependencies() {
-  typedef std::vector::iterator Iter;
   // For each input file.
   for (auto I = InputFilePaths.begin(), E = InputFilePaths.end(); I != E; ++I) 
{
 llvm::StringRef InputPath = *I;


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


r301178 - [Devirtualization] Emit invariant.group loads with empty group md

2017-04-24 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Mon Apr 24 07:58:43 2017
New Revision: 301178

URL: http://llvm.org/viewvc/llvm-project?rev=301178&view=rev
Log:
[Devirtualization] Emit invariant.group loads with empty group md

Summary:
As discussed here
http://lists.llvm.org/pipermail/llvm-dev/2017-January/109332.html
having different groups doesn't solve the problem entirly.

Reviewers: rjmccall, rsmith

Subscribers: amharc, cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=301178&r1=301177&r2=301178&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Apr 24 07:58:43 2017
@@ -565,12 +565,8 @@ void CodeGenModule::DecorateInstructionW
 
 void CodeGenModule::DecorateInstructionWithInvariantGroup(
 llvm::Instruction *I, const CXXRecordDecl *RD) {
-  llvm::Metadata *MD = 
CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0));
-  auto *MetaDataNode = dyn_cast(MD);
-  // Check if we have to wrap MDString in MDNode.
-  if (!MetaDataNode)
-MetaDataNode = llvm::MDNode::get(getLLVMContext(), MD);
-  I->setMetadata(llvm::LLVMContext::MD_invariant_group, MetaDataNode);
+  I->setMetadata(llvm::LLVMContext::MD_invariant_group,
+ llvm::MDNode::get(getLLVMContext(), {}));
 }
 
 void CodeGenModule::Error(SourceLocation loc, StringRef message) {

Modified: cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp?rev=301178&r1=301177&r2=301178&view=diff
==
--- cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp Mon Apr 24 07:58:43 
2017
@@ -12,15 +12,15 @@ struct D : A {
 void testExternallyVisible() {
   A *a = new A;
 
-  // CHECK: load {{.*}} !invariant.group ![[A_MD:[0-9]+]]
+  // CHECK: load {{.*}} !invariant.group ![[MD:[0-9]+]]
   a->foo();
 
   D *d = new D;
   // CHECK: call void @_ZN1DC1Ev(
-  // CHECK: load {{.*}} !invariant.group ![[D_MD:[0-9]+]]
+  // CHECK: load {{.*}} !invariant.group ![[MD]]
   d->foo();
   A *a2 = d;
-  // CHECK: load {{.*}} !invariant.group ![[A_MD]]
+  // CHECK: load {{.*}} !invariant.group ![[MD]]
   a2->foo();
 }
 // CHECK-LABEL: {{^}}}
@@ -40,35 +40,32 @@ struct C : B {
 // CHECK-LABEL: define void @_Z21testInternallyVisibleb(
 void testInternallyVisible(bool p) {
   B *b = new B;
-  // CHECK: = load {{.*}}, !invariant.group ![[B_MD:[0-9]+]]
+  // CHECK: = load {{.*}}, !invariant.group ![[MD]]
   b->bar();
 
   // CHECK: call void @_ZN12_GLOBAL__N_11CC1Ev(
   C *c = new C;
-  // CHECK: = load {{.*}}, !invariant.group ![[C_MD:[0-9]+]]
+  // CHECK: = load {{.*}}, !invariant.group ![[MD]]
   c->bar();
 }
 
 // Checking A::A()
 // CHECK-LABEL: define linkonce_odr void @_ZN1AC2Ev(
-// CHECK: store {{.*}}, !invariant.group ![[A_MD]]
+// CHECK: store {{.*}}, !invariant.group ![[MD]]
 // CHECK-LABEL: {{^}}}
 
 // Checking D::D()
 // CHECK-LABEL: define linkonce_odr void @_ZN1DC2Ev(
 // CHECK:  = call i8* @llvm.invariant.group.barrier(i8*
 // CHECK:  call void @_ZN1AC2Ev(%struct.A*
-// CHECK: store {{.*}} !invariant.group ![[D_MD]]
+// CHECK: store {{.*}} !invariant.group ![[MD]]
 
 // Checking B::B()
 // CHECK-LABEL: define internal void @_ZN12_GLOBAL__N_11BC2Ev(
-// CHECK:  store {{.*}}, !invariant.group ![[B_MD]]
+// CHECK:  store {{.*}}, !invariant.group ![[MD]]
 
 // Checking C::C()
 // CHECK-LABEL: define internal void @_ZN12_GLOBAL__N_11CC2Ev(
-// CHECK:  store {{.*}}, !invariant.group ![[C_MD]]
+// CHECK:  store {{.*}}, !invariant.group ![[MD]]
 
-// CHECK: ![[A_MD]] = !{!"_ZTS1A"}
-// CHECK: ![[D_MD]] = !{!"_ZTS1D"}
-// CHECK: ![[B_MD]] = distinct !{}
-// CHECK: ![[C_MD]] = distinct !{}
+// CHECK: ![[MD]] = !{}


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


r303488 - [Devirtualization] insert placement new barrier with -O0

2017-05-20 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Sat May 20 03:56:18 2017
New Revision: 303488

URL: http://llvm.org/viewvc/llvm-project?rev=303488&view=rev
Log:
[Devirtualization] insert placement new barrier with -O0

Summary:
To not break LTO with different optimizations levels, we should insert
the barrier regardles of optimization level.

Reviewers: rjmccall, rsmith, mehdi_amini

Reviewed By: mehdi_amini

Subscribers: mehdi_amini, cfe-commits

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

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

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=303488&r1=303487&r2=303488&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Sat May 20 03:56:18 2017
@@ -1658,8 +1658,9 @@ llvm::Value *CodeGenFunction::EmitCXXNew
 
   // Passing pointer through invariant.group.barrier to avoid propagation of
   // vptrs information which may be included in previous type.
+  // To not break LTO with different optimizations levels, we do it regardless
+  // of optimization level.
   if (CGM.getCodeGenOpts().StrictVTablePointers &&
-  CGM.getCodeGenOpts().OptimizationLevel > 0 &&
   allocator->isReservedGlobalPlacementOperator())
 result = Address(Builder.CreateInvariantGroupBarrier(result.getPointer()),
  result.getAlignment());


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


[PATCH] D25898: [clang-tidy] Enhance modernize-make-unique to handle unique_ptr.reset()

2016-10-23 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

Besides this looks good




Comment at: test/clang-tidy/modernize-make-shared.cpp:122
+  Pderived = std::shared_ptr(new Derived());
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use std::make_shared instead
+  // CHECK-FIXES: Pderived = std::make_shared();

I think the warning here could be better. The user is using make_shared here.
Maybe ' warning: use std::make_shared with zero arguments ...', but only in 
this case



Comment at: test/clang-tidy/modernize-make-shared.cpp:129
+  // FIXME: OK to replace when auto is not used
+  std::shared_ptr PBase = std::shared_ptr(new Derived());
+

I think it is good to replace it even with auto, like
auto PBase = std::make_shared(new Derived());

For shared_ptr we can even do better, that we can't do for unique_ptr - we
coud change it to
auto PBase = std::make_shared();
because all conversions works.
Of course not in this patch, but it would be good to leave a comment about this 
here.


https://reviews.llvm.org/D25898



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


[PATCH] D24894: [clang-tidy] Prefer transparent functors to non-transparent one.

2016-10-23 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.



Comment at: clang-tidy/modernize/UseTransparentFunctorsCheck.cpp:70
+static const StringRef Message =
+"prefer transparent functors (aka diamond operators)";
+

The message would be much better if you would put the name of this functor, like
"prefer transparent functor (%0)" where %0 would be evaluated to 
'std::greater<>" etc.



Comment at: clang-tidy/modernize/UseTransparentFunctorsCheck.cpp:89-109
+  for (; ArgNum < FunctorParentLoc.getNumArgs(); ++ArgNum) {
+const TemplateArgument &Arg =
+FunctorParentLoc.getArgLoc(ArgNum).getArgument();
+if (Arg.getKind() != TemplateArgument::Type)
+  continue;
+QualType ParentArgType = Arg.getAsType();
+if (ParentArgType->isRecordType() &&

This can be moved to one or 2 functions, returning FunctorTypeLoc or 
llvm::Optional



Comment at: docs/clang-tidy/checks/modernize-use-transparent-functors.rst:32-33
+
+   If the option is set to non-zero (default is `0`), the check will not
+   warn on those cases where automatic FIXIT is not safe to apply.

I think
... will not warn on these cases as shown above, where automatic FIXIT...
would have been better.



Comment at: docs/clang-tidy/checks/modernize-use-transparent-functors.rst:33
+   If the option is set to non-zero (default is `0`), the check will not
+   warn on those cases where automatic FIXIT is not safe to apply.

Add a note
This check requires C++14 or higher to run.


https://reviews.llvm.org/D24894



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


[PATCH] D24894: [clang-tidy] Prefer transparent functors to non-transparent one.

2016-10-23 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.



Comment at: docs/clang-tidy/checks/modernize-use-transparent-functors.rst:12
+  .. code-block:: c++
+
+// Non-transparent functor  

Say somewhere that you also handle cases like
std::less(arg1, arg2)
because from this documentation I didn't know about it.


https://reviews.llvm.org/D24894



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


[PATCH] D21502: Fix heuristics skipping invalid ctor-initializers with C++11

2016-10-23 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

Richard?


https://reviews.llvm.org/D21502



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


[PATCH] D25898: [clang-tidy] Enhance modernize-make-unique to handle unique_ptr.reset()

2016-10-23 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.



Comment at: test/clang-tidy/modernize-make-shared.cpp:122
+  Pderived = std::shared_ptr(new Derived());
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use std::make_shared instead
+  // CHECK-FIXES: Pderived = std::make_shared();

malcolm.parsons wrote:
> Prazek wrote:
> > I think the warning here could be better. The user is using make_shared 
> > here.
> > Maybe ' warning: use std::make_shared with zero arguments ...', but only in 
> > this case
> The user isn't using make_shared.
true, I've read that incorectly



Comment at: test/clang-tidy/modernize-make-shared.cpp:129
+  // FIXME: OK to replace when auto is not used
+  std::shared_ptr PBase = std::shared_ptr(new Derived());
+

malcolm.parsons wrote:
> Prazek wrote:
> > I think it is good to replace it even with auto, like
> > auto PBase = std::make_shared(new Derived());
> > 
> > For shared_ptr we can even do better, that we can't do for unique_ptr - we
> > coud change it to
> > auto PBase = std::make_shared();
> > because all conversions works.
> > Of course not in this patch, but it would be good to leave a comment about 
> > this here.
> A smart pointer to Derived cannot be reset with a pointer to Base.
oh yea, I was only thinking about downcasting smart pointer


https://reviews.llvm.org/D25898



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


[PATCH] D26117: [Devirtualization] Decorate vfunction load with invariant.load

2016-10-29 Thread Piotr Padlewski via cfe-commits
Prazek created this revision.
Prazek added reviewers: rsmith, rengolin.
Prazek added subscribers: cfe-commits, rjmccall, nlewycky.

This patch was introduced one year ago, but because my google account
was disabled, I didn't get email with failing buildbot and I missed
revert of this commit. There was small but in test regex.
I am back.


https://reviews.llvm.org/D26117

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/virtual-function-calls.cpp


Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - 
-fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} !invariant.load ![[EMPTY_NODE:[0-9]+]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1618,7 +1618,16 @@
 
 llvm::Value *VFuncPtr =
 CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, 
CGF.getPointerAlign());
+
+// It's safe to add "invariant.load" without -fstrict-vtable-pointers, but
+// it would not help in devirtualization.
+if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+CGM.getCodeGenOpts().StrictVTablePointers)
+  Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+llvm::MDNode::get(CGM.getLLVMContext(),
+  llvm::ArrayRef()));
+return Inst;
   }
 }
 


Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - -fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} !invariant.load ![[EMPTY_NODE:[0-9]+]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1618,7 +1618,16 @@
 
 llvm::Value *VFuncPtr =
 CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+// It's safe to add "invariant.load" without -fstrict-vtable-pointers, but
+// it would not help in devirtualization.
+if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+CGM.getCodeGenOpts().StrictVTablePointers)
+  Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+llvm::MDNode::get(CGM.getLLVMContext(),
+  llvm::ArrayRef()));
+return Inst;
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26117: [Devirtualization] Decorate vfunction load with invariant.load

2016-10-29 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

Here is commit from last year
https://reviews.llvm.org/D13279


https://reviews.llvm.org/D26117



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


[PATCH] D26117: [Devirtualization] Decorate vfunction load with invariant.load

2016-10-29 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

merging with master. Gonna update patch in a minute.


https://reviews.llvm.org/D26117



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


[PATCH] D26117: [Devirtualization] Decorate vfunction load with invariant.load

2016-10-29 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 76302.
Prazek added a comment.

rebae


https://reviews.llvm.org/D26117

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/virtual-function-calls.cpp


Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - 
-fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} !invariant.load ![[EMPTY_NODE:[0-9]+]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1623,7 +1623,17 @@
 
 llvm::Value *VFuncPtr =
 CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-VFunc = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+auto *VFuncLoad = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF
+  .getPointerAlign());
+
+// It's safe to add "invariant.load" without -fstrict-vtable-pointers, but
+// it would not help in devirtualization.
+if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+CGM.getCodeGenOpts().StrictVTablePointers)
+  VFuncLoad->setMetadata(llvm::LLVMContext::MD_invariant_load,
+llvm::MDNode::get(CGM.getLLVMContext(),
+  llvm::ArrayRef()));
+VFunc = VFuncLoad;
   }
 
   CGCallee Callee(MethodDecl, VFunc);


Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - -fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} !invariant.load ![[EMPTY_NODE:[0-9]+]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1623,7 +1623,17 @@
 
 llvm::Value *VFuncPtr =
 CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-VFunc = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+auto *VFuncLoad = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF
+  .getPointerAlign());
+
+// It's safe to add "invariant.load" without -fstrict-vtable-pointers, but
+// it would not help in devirtualization.
+if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+CGM.getCodeGenOpts().StrictVTablePointers)
+  VFuncLoad->setMetadata(llvm::LLVMContext::MD_invariant_load,
+llvm::MDNode::get(CGM.getLLVMContext(),
+  llvm::ArrayRef()));
+VFunc = VFuncLoad;
   }
 
   CGCallee Callee(MethodDecl, VFunc);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26117: [Devirtualization] Decorate vfunction load with invariant.load

2016-10-29 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 76303.
Prazek added a comment.

Updated comment and reformatted


https://reviews.llvm.org/D26117

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/virtual-function-calls.cpp


Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - 
-fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} !invariant.load ![[EMPTY_NODE:[0-9]+]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1623,7 +1623,22 @@
 
 llvm::Value *VFuncPtr =
 CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-VFunc = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+auto *VFuncLoad =
+CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+// Add !invariant.load md to virtual function load to indicate that
+// function didn't change inside vtable.
+// It's safe to add it without -fstrict-vtable-pointers, but it would not
+// help in devirtualization because it will only matter if we will have 2
+// the same virtual function loads from the same vtable load, which won't
+// happen without enabled devirtualization with -fstrict-vtable-pointers.
+if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+CGM.getCodeGenOpts().StrictVTablePointers)
+  VFuncLoad->setMetadata(
+  llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+VFunc = VFuncLoad;
   }
 
   CGCallee Callee(MethodDecl, VFunc);


Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - -fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} !invariant.load ![[EMPTY_NODE:[0-9]+]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1623,7 +1623,22 @@
 
 llvm::Value *VFuncPtr =
 CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-VFunc = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+auto *VFuncLoad =
+CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+// Add !invariant.load md to virtual function load to indicate that
+// function didn't change inside vtable.
+// It's safe to add it without -fstrict-vtable-pointers, but it would not
+// help in devirtualization because it will only matter if we will have 2
+// the same virtual function loads from the same vtable load, which won't
+// happen without enabled devirtualization with -fstrict-vtable-pointers.
+if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+CGM.getCodeGenOpts().StrictVTablePointers)
+  VFuncLoad->setMetadata(
+  llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+VFunc = VFuncLoad;
   }
 
   CGCallee Callee(MethodDecl, VFunc);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r285496 - NFC small format

2016-10-29 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Sat Oct 29 10:28:25 2016
New Revision: 285496

URL: http://llvm.org/viewvc/llvm-project?rev=285496&view=rev
Log:
NFC small format

Modified:
cfe/trunk/lib/Analysis/UninitializedValues.cpp

Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=285496&r1=285495&r2=285496&view=diff
==
--- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Sat Oct 29 10:28:25 2016
@@ -348,7 +348,8 @@ public:
 }
 
 static const DeclRefExpr *getSelfInitExpr(VarDecl *VD) {
-  if (VD->getType()->isRecordType()) return nullptr;
+  if (VD->getType()->isRecordType())
+return nullptr;
   if (Expr *Init = VD->getInit()) {
 const DeclRefExpr *DRE
   = dyn_cast(stripCasts(VD->getASTContext(), Init));


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


r285497 - [Devirtualization] Decorate vfunction load with invariant.load

2016-10-29 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Sat Oct 29 10:28:30 2016
New Revision: 285497

URL: http://llvm.org/viewvc/llvm-project?rev=285497&view=rev
Log:
[Devirtualization] Decorate vfunction load with invariant.load

Summary:
This patch was introduced one year ago, but because my google account
was disabled, I didn't get email with failing buildbot and I missed
revert of this commit. There was small but in test regex.
I am back.

Reviewers: rsmith, rengolin

Subscribers: nlewycky, rjmccall, cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=285497&r1=285496&r2=285497&view=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Sat Oct 29 10:28:30 2016
@@ -1623,7 +1623,22 @@ CGCallee ItaniumCXXABI::getVirtualFuncti
 
 llvm::Value *VFuncPtr =
 CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-VFunc = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+auto *VFuncLoad =
+CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+// Add !invariant.load md to virtual function load to indicate that
+// function didn't change inside vtable.
+// It's safe to add it without -fstrict-vtable-pointers, but it would not
+// help in devirtualization because it will only matter if we will have 2
+// the same virtual function loads from the same vtable load, which won't
+// happen without enabled devirtualization with -fstrict-vtable-pointers.
+if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+CGM.getCodeGenOpts().StrictVTablePointers)
+  VFuncLoad->setMetadata(
+  llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+VFunc = VFuncLoad;
   }
 
   CGCallee Callee(MethodDecl, VFunc);

Modified: cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp?rev=285497&r1=285496&r2=285497&view=diff
==
--- cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp Sat Oct 29 10:28:30 
2016
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - 
-fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@ namespace VirtualNoreturn {
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} !invariant.load ![[EMPTY_NODE:[0-9]+]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}


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


[PATCH] D26117: [Devirtualization] Decorate vfunction load with invariant.load

2016-10-29 Thread Piotr Padlewski via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285497: [Devirtualization] Decorate vfunction load with 
invariant.load (authored by Prazek).

Changed prior to commit:
  https://reviews.llvm.org/D26117?vs=76303&id=76306#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26117

Files:
  cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
  cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp


Index: cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
===
--- cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
+++ cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - 
-fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} !invariant.load ![[EMPTY_NODE:[0-9]+]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
===
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1623,7 +1623,22 @@
 
 llvm::Value *VFuncPtr =
 CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-VFunc = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+auto *VFuncLoad =
+CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+// Add !invariant.load md to virtual function load to indicate that
+// function didn't change inside vtable.
+// It's safe to add it without -fstrict-vtable-pointers, but it would not
+// help in devirtualization because it will only matter if we will have 2
+// the same virtual function loads from the same vtable load, which won't
+// happen without enabled devirtualization with -fstrict-vtable-pointers.
+if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+CGM.getCodeGenOpts().StrictVTablePointers)
+  VFuncLoad->setMetadata(
+  llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+VFunc = VFuncLoad;
   }
 
   CGCallee Callee(MethodDecl, VFunc);


Index: cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
===
--- cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
+++ cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - -fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} !invariant.load ![[EMPTY_NODE:[0-9]+]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
===
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1623,7 +1623,22 @@
 
 llvm::Value *VFuncPtr =
 CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-VFunc = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+auto *VFuncLoad =
+CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+// Add !invariant.load md to virtual function load to indicate that
+// function didn't change inside vtable.
+// It's safe to add it without -fstrict-vtable-pointers, but it would not
+// help in devirtualization because it will only matter if we will have 2
+// the same virtual function loads from the same vtable load, which won't
+// happen without enabled devirtualization with -fstrict-vtable-pointers.
+if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+CGM.getCodeGenOpts().StrictVTablePointers)
+  VFuncLoad->setMetadata(
+  llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+VFunc = VFuncLoad;
   }
 
   CGCallee Callee(MethodDecl, VFunc);
_

[PATCH] D26511: [clang-tidy] Rename modernize-use-default to modernize-use-equals-default

2016-11-10 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

I think this change is not required at first place.
It is introduced because of "modernize-use-delete" was too ambiguous because of 
operator delete, so it was changed to "modernize-use-equals-delete". But this 
case is not ambiguous at all, so I don't see point changing that.
Maybe it would be better to find better name for the 
modernize-use-equals-delete to be modernize-delete-function or something before 
4.0 is released.


https://reviews.llvm.org/D26511



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


[PATCH] D21298: [Clang-tidy] delete null check

2016-11-10 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.



Comment at: test/clang-tidy/misc-delete-null-pointer.cpp:11
+  }
+  // CHECK-FIXES: delete p;
+  int *p3 = new int[3];

Is there check-fixes-not? This seems to be required here, because even if the 
fixit won't happen here, the test will pass.


https://reviews.llvm.org/D21298



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


Re: [clang-tools-extra] r286222 - [clang-tidy] clang-analyzer-alpha* checks are not registered, so there's no need to disable them

2016-11-11 Thread Piotr Padlewski via cfe-commits
Hmm, right now there is no way to use alpha checks in clang tidy?
Piotr

On Nov 10, 2016 10:57, "Malcolm Parsons via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

> On 9 November 2016 at 18:50, Devin Coughlin  wrote:
>
> > We agree that this is a valuable checker and are committed to getting it
> out of alpha. This check is in alpha because:
> >
> > a) The diagnostic experience is not very good. It reports a call path
> directly in the diagnostic message (for example “Call path: foo <— bar” for
> a call to foo() in bar()) rather than as a path diagnostic.
>
> Agreed.
>
> > b) The lack of path-sensitive reasoning may result in false positives
> when a called function uses a member variable flag to track whether
> initialization is complete and does not call the virtual member function
> during initialization.
>
> Right, we're not doing this.
>
> > c) The check issues a warning for both calls to pure virtual functions
> (which is always an error) and non-pure virtual functions (which is more of
> a code smell and may be a false positive).
>
> I'm using static analysis to find code smells.
>
> > I’ll commit to doing Step 1) in the immediate future and Step 2)
> eventually. Once the checker is on by default we’ll need to assess whether
> the false positive rate from c) is too high — if so, we’ll need to turn the
> non-pure-virtual case off by default.
>
> LGTM.
>
> Thanks,
> --
> Malcolm Parsons
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D12719: ScalarEvolution assume hanging bugfix

2015-09-08 Thread Piotr Padlewski via cfe-commits
Prazek created this revision.
Prazek added reviewers: rsmith, nlewycky.
Prazek added a subscriber: cfe-commits.
Herald added a subscriber: sanjoy.

http://reviews.llvm.org/D12719

Files:
  lib/Analysis/ScalarEvolution.cpp
  test/Analysis/ScalarEvolution/avoid-assume-hang.ll

Index: test/Analysis/ScalarEvolution/avoid-assume-hang.ll
===
--- /dev/null
+++ test/Analysis/ScalarEvolution/avoid-assume-hang.ll
@@ -0,0 +1,139 @@
+; RUN: opt %s -always-inline | opt -analyze -scalar-evolution
+; There was optimization bug in ScalarEvolution, that causes too long 
+; compute time and stack overflow crash.
+
+declare void @body(i32)
+declare void @llvm.assume(i1)
+
+define available_externally void @assume1(i64 %i.ext, i64 %a) alwaysinline {
+  %cmp0 = icmp ne i64 %i.ext, %a
+  call void @llvm.assume(i1 %cmp0)
+
+  %a1 = add i64 %a, 1
+  %cmp1 = icmp ne i64 %i.ext, %a1
+  call void @llvm.assume(i1 %cmp1)
+
+  %a2 = add i64 %a1, 1
+  %cmp2 = icmp ne i64 %i.ext, %a2
+  call void @llvm.assume(i1 %cmp2)
+
+  %a3 = add i64 %a2, 1
+  %cmp3 = icmp ne i64 %i.ext, %a3
+  call void @llvm.assume(i1 %cmp3)
+
+  %a4 = add i64 %a3, 1
+  %cmp4 = icmp ne i64 %i.ext, %a4
+  call void @llvm.assume(i1 %cmp4)
+
+  ret void
+}
+
+define available_externally void @assume2(i64 %i.ext, i64 %a) alwaysinline {
+  call void @assume1(i64 %i.ext, i64 %a)
+
+  %a1 = add i64 %a, 5
+  %cmp1 = icmp ne i64 %i.ext, %a1
+  call void @assume1(i64 %i.ext, i64 %a1)
+
+  %a2 = add i64 %a1, 5
+  %cmp2 = icmp ne i64 %i.ext, %a2
+  call void @assume1(i64 %i.ext, i64 %a2)
+
+  %a3 = add i64 %a2, 5
+  %cmp3 = icmp ne i64 %i.ext, %a3
+  call void @assume1(i64 %i.ext, i64 %a3)
+
+  %a4 = add i64 %a3, 5
+  %cmp4 = icmp ne i64 %i.ext, %a4
+  call void @assume1(i64 %i.ext, i64 %a4)
+
+  ret void
+}
+
+define available_externally void @assume3(i64 %i.ext, i64 %a) alwaysinline {
+  call void @assume2(i64 %i.ext, i64 %a)
+
+  %a1 = add i64 %a, 25
+  %cmp1 = icmp ne i64 %i.ext, %a1
+  call void @assume2(i64 %i.ext, i64 %a1)
+
+  %a2 = add i64 %a1, 25
+  %cmp2 = icmp ne i64 %i.ext, %a2
+  call void @assume2(i64 %i.ext, i64 %a2)
+
+  %a3 = add i64 %a2, 25
+  %cmp3 = icmp ne i64 %i.ext, %a3
+  call void @assume2(i64 %i.ext, i64 %a3)
+
+  %a4 = add i64 %a3, 25
+  %cmp4 = icmp ne i64 %i.ext, %a4
+  call void @assume2(i64 %i.ext, i64 %a4)
+
+  ret void
+}
+
+define available_externally void @assume4(i64 %i.ext, i64 %a) alwaysinline {
+  call void @assume3(i64 %i.ext, i64 %a)
+
+  %a1 = add i64 %a, 125
+  %cmp1 = icmp ne i64 %i.ext, %a1
+  call void @assume3(i64 %i.ext, i64 %a1)
+
+  %a2 = add i64 %a1, 125
+  %cmp2 = icmp ne i64 %i.ext, %a2
+  call void @assume3(i64 %i.ext, i64 %a2)
+
+  %a3 = add i64 %a2, 125
+  %cmp3 = icmp ne i64 %i.ext, %a3
+  call void @assume3(i64 %i.ext, i64 %a3)
+
+  %a4 = add i64 %a3, 125
+  %cmp4 = icmp ne i64 %i.ext, %a4
+  call void @assume3(i64 %i.ext, i64 %a4)
+
+  ret void
+}
+
+define available_externally void @assume5(i64 %i.ext, i64 %a) alwaysinline {
+  call void @assume4(i64 %i.ext, i64 %a)
+
+  %a1 = add i64 %a, 625
+  %cmp1 = icmp ne i64 %i.ext, %a1
+  call void @assume4(i64 %i.ext, i64 %a1)
+
+  %a2 = add i64 %a1, 625
+  %cmp2 = icmp ne i64 %i.ext, %a2
+  call void @assume4(i64 %i.ext, i64 %a2)
+
+  %a3 = add i64 %a2, 625
+  %cmp3 = icmp ne i64 %i.ext, %a3
+  call void @assume4(i64 %i.ext, i64 %a3)
+
+  %a4 = add i64 %a3, 625
+  %cmp4 = icmp ne i64 %i.ext, %a4
+  call void @assume4(i64 %i.ext, i64 %a4)
+
+  ret void
+}
+
+define void @fn(i32 %init) {
+entry:
+  br label %loop
+
+loop:
+  %i = phi i32 [%init, %entry], [%next, %loop]
+  call void @body(i32 %i)
+
+  %i.ext = zext i32 %i to i64
+
+  call void @assume5(i64 %i.ext, i64 5)
+
+  %i.next = add i64 %i.ext, 1
+  %next = trunc i64 %i.next to i32
+  %done = icmp eq i32 %i, 5
+
+  br i1 %done, label %exit, label %loop
+
+exit:
+  ret void
+}
\ No newline at end of file
Index: lib/Analysis/ScalarEvolution.cpp
===
--- lib/Analysis/ScalarEvolution.cpp
+++ lib/Analysis/ScalarEvolution.cpp
@@ -6958,18 +6958,6 @@
 LoopContinuePredicate->getSuccessor(0) != L->getHeader()))
 return true;
 
-  // Check conditions due to any @llvm.assume intrinsics.
-  for (auto &AssumeVH : AC.assumptions()) {
-if (!AssumeVH)
-  continue;
-auto *CI = cast(AssumeVH);
-if (!DT.dominates(CI, Latch->getTerminator()))
-  continue;
-
-if (isImpliedCond(Pred, LHS, RHS, CI->getArgOperand(0), false))
-  return true;
-  }
-
   struct ClearWalkingBEDominatingCondsOnExit {
 ScalarEvolution &SE;
 
@@ -6981,14 +6969,26 @@
 }
   };
 
-  // We don't want more than one activation of the following loop on the stack
+  // We don't want more than one activation of the following loops on the stack
   // -- that can lead to O(n!) time complexity.
   if (WalkingBEDominatingConds)
 return false;
 
   WalkingBEDominatingConds = true

Re: [PATCH] D12719: ScalarEvolution assume hanging bugfix

2015-09-08 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.


Comment at: lib/Analysis/ScalarEvolution.cpp:6980
@@ -6991,1 +6979,3 @@
 
+  // Check conditions due to any @llvm.assume intrinsics.
+  for (auto &AssumeVH : AC.assumptions()) {

nlewycky wrote:
> What is it about this check which is a problem? Or put another way, why is 
> this not okay but the call to isImpliedCond on line 6956 is fine? The problem 
> is recursion through isImpliedCond->getSCEV->..., right?
The problem is that the check wasn't covering assume loop which caused big hang.

Stacktrace looked more like this
(isImpliedCond -> getZeroExtendExpr -> isLoopBackedgeGuardedByCond) x much


http://reviews.llvm.org/D12719



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


Re: [PATCH] D12719: ScalarEvolution assume hanging bugfix

2015-09-08 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

I checked it, it is of course not infinite. I am not sure about n! in case of 
assumes. I having 10 or 20 assumes will not make it slow. @rsmith was helping 
me with it, and he thinks that for assumes it is O(n^2), because results are 
memorized.

So it this case, 1000 assumes is enough to make difference



Comment at: lib/Analysis/ScalarEvolution.cpp:6980
@@ -6991,1 +6979,3 @@
 
+  // Check conditions due to any @llvm.assume intrinsics.
+  for (auto &AssumeVH : AC.assumptions()) {

nlewycky wrote:
> Prazek wrote:
> > nlewycky wrote:
> > > What is it about this check which is a problem? Or put another way, why 
> > > is this not okay but the call to isImpliedCond on line 6956 is fine? The 
> > > problem is recursion through isImpliedCond->getSCEV->..., right?
> > The problem is that the check wasn't covering assume loop which caused big 
> > hang.
> > 
> > Stacktrace looked more like this
> > (isImpliedCond -> getZeroExtendExpr -> isLoopBackedgeGuardedByCond) x much
> Does the code from 6953 to 6959 need to move below this check too? Is there 
> another bug here?
I don't think so. I think the results are memorized, so calling sImpliedCond in 
6956 will not cause lag.


http://reviews.llvm.org/D12719



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


Re: [PATCH] D12719: ScalarEvolution assume hanging bugfix

2015-09-08 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

I used "hanging out" in the meaning of being very slow, not sure if it is right 
word for it.


http://reviews.llvm.org/D12719



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


Re: [PATCH] D12128: Generating available_externally vtables bugfix

2015-09-09 Thread Piotr Padlewski via cfe-commits
Prazek accepted this revision.
Prazek added a reviewer: Prazek.
Prazek added a comment.
This revision is now accepted and ready to land.

Have to accept revision to close it


http://reviews.llvm.org/D12128



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


r247199 - Generating assumption loads of vptr after ctor call (fixed)

2015-09-09 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Wed Sep  9 17:20:28 2015
New Revision: 247199

URL: http://llvm.org/viewvc/llvm-project?rev=247199&view=rev
Log:
Generating assumption loads of vptr after ctor call (fixed)

Generating call assume(icmp %vtable, %global_vtable) after constructor
call for devirtualization purposes.

For more info go to:
http://lists.llvm.org/pipermail/cfe-dev/2015-July/044227.html

Edit:
Fixed version because of PR24479.
After this patch got reverted because of ScalarEvolution bug (D12719)
Merged after John McCall big patch (Added Address).

http://reviews.llvm.org/D11859

Added:
cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXXABI.h
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGVTables.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/test/CodeGen/available-externally-hidden.cpp
cfe/trunk/test/CodeGenCXX/ctor-globalopt.cpp
cfe/trunk/test/CodeGenCXX/thunks.cpp
cfe/trunk/test/CodeGenCXX/virtual-base-ctor.cpp
cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=247199&r1=247198&r2=247199&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.h Wed Sep  9 17:20:28 2015
@@ -228,8 +228,10 @@ public:
   virtual void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E) = 0;
   virtual llvm::GlobalVariable *getThrowInfo(QualType T) { return nullptr; }
 
-  virtual bool canEmitAvailableExternallyVTable(
-  const CXXRecordDecl *RD) const = 0;
+  /// \brief Determine whether it's possible to emit a vtable for \p RD, even
+  /// though we do not know that the vtable has been marked as used by semantic
+  /// analysis.
+  virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const = 0;
 
   virtual void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C) = 0;
 
@@ -355,13 +357,25 @@ public:
   virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
  const CXXRecordDecl *RD) = 0;
 
+  /// Checks if ABI requires extra virtual offset for vtable field.
+  virtual bool
+  isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF,
+  CodeGenFunction::VPtr Vptr) = 0;
+
+  /// Checks if ABI requires to initilize vptrs for given dynamic class.
+  virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass) = 
0;
+
+  /// Get the address point of the vtable for the given base subobject.
+  virtual llvm::Constant *
+  getVTableAddressPoint(BaseSubobject Base,
+const CXXRecordDecl *VTableClass) = 0;
+
   /// Get the address point of the vtable for the given base subobject while
-  /// building a constructor or a destructor. On return, NeedsVirtualOffset
-  /// tells if a virtual base adjustment is needed in order to get the offset
-  /// of the base subobject.
-  virtual llvm::Value *getVTableAddressPointInStructor(
-  CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base,
-  const CXXRecordDecl *NearestVBase, bool &NeedsVirtualOffset) = 0;
+  /// building a constructor or a destructor.
+  virtual llvm::Value *
+  getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl 
*RD,
+  BaseSubobject Base,
+  const CXXRecordDecl *NearestVBase) = 0;
 
   /// Get the address point of the vtable for the given base subobject while
   /// building a constexpr.

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=247199&r1=247198&r2=247199&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Sep  9 17:20:28 2015
@@ -1417,7 +1417,8 @@ void CodeGenModule::ConstructAttributeLi
 
 if (const FunctionDecl *Fn = dyn_cast(TargetDecl)) {
   const FunctionProtoType *FPT = Fn->getType()->getAs();
-  if (FPT && FPT->isNothrow(getContext()))
+  if (FPT && !isUnresolvedExceptionSpec(FPT->getExceptionSpecType()) &&
+  FPT->isNothrow(getContext()))
 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
   // Don't use [[noreturn]] or _Noreturn for a call to a virtual function.
   // These attributes are not inherited by overloads.

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=247199&r1=247198&r2=247199&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CG

r247332 - Revert "Generating assumption loads of vptr after ctor call (fixed)"

2015-09-10 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Thu Sep 10 15:18:30 2015
New Revision: 247332

URL: http://llvm.org/viewvc/llvm-project?rev=247332&view=rev
Log:
Revert "Generating assumption loads of vptr after ctor call (fixed)"

It seems that there is small bug, and we can't generate assume loads
when some virtual functions have internal visibiliy
This reverts commit 982bb7d966947812d216489b3c519c9825cacbf2.

Removed:
cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXXABI.h
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGVTables.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/test/CodeGen/available-externally-hidden.cpp
cfe/trunk/test/CodeGenCXX/ctor-globalopt.cpp
cfe/trunk/test/CodeGenCXX/thunks.cpp
cfe/trunk/test/CodeGenCXX/virtual-base-ctor.cpp
cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=247332&r1=247331&r2=247332&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.h Thu Sep 10 15:18:30 2015
@@ -228,10 +228,8 @@ public:
   virtual void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E) = 0;
   virtual llvm::GlobalVariable *getThrowInfo(QualType T) { return nullptr; }
 
-  /// \brief Determine whether it's possible to emit a vtable for \p RD, even
-  /// though we do not know that the vtable has been marked as used by semantic
-  /// analysis.
-  virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const = 0;
+  virtual bool canEmitAvailableExternallyVTable(
+  const CXXRecordDecl *RD) const = 0;
 
   virtual void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C) = 0;
 
@@ -357,25 +355,13 @@ public:
   virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
  const CXXRecordDecl *RD) = 0;
 
-  /// Checks if ABI requires extra virtual offset for vtable field.
-  virtual bool
-  isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF,
-  CodeGenFunction::VPtr Vptr) = 0;
-
-  /// Checks if ABI requires to initilize vptrs for given dynamic class.
-  virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass) = 
0;
-
-  /// Get the address point of the vtable for the given base subobject.
-  virtual llvm::Constant *
-  getVTableAddressPoint(BaseSubobject Base,
-const CXXRecordDecl *VTableClass) = 0;
-
   /// Get the address point of the vtable for the given base subobject while
-  /// building a constructor or a destructor.
-  virtual llvm::Value *
-  getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl 
*RD,
-  BaseSubobject Base,
-  const CXXRecordDecl *NearestVBase) = 0;
+  /// building a constructor or a destructor. On return, NeedsVirtualOffset
+  /// tells if a virtual base adjustment is needed in order to get the offset
+  /// of the base subobject.
+  virtual llvm::Value *getVTableAddressPointInStructor(
+  CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base,
+  const CXXRecordDecl *NearestVBase, bool &NeedsVirtualOffset) = 0;
 
   /// Get the address point of the vtable for the given base subobject while
   /// building a constexpr.

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=247332&r1=247331&r2=247332&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Sep 10 15:18:30 2015
@@ -1417,8 +1417,7 @@ void CodeGenModule::ConstructAttributeLi
 
 if (const FunctionDecl *Fn = dyn_cast(TargetDecl)) {
   const FunctionProtoType *FPT = Fn->getType()->getAs();
-  if (FPT && !isUnresolvedExceptionSpec(FPT->getExceptionSpecType()) &&
-  FPT->isNothrow(getContext()))
+  if (FPT && FPT->isNothrow(getContext()))
 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
   // Don't use [[noreturn]] or _Noreturn for a call to a virtual function.
   // These attributes are not inherited by overloads.

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=247332&r1=247331&r2=247332&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Thu Sep 10 15:18:30 2015
@@ -1984,14 +1984,12 @@ void CodeGenFunction::EmitCXXConstructor
  bool ForVirtualBase,
 

[PATCH] D12865: Generating available_externally vtables and assume loads bugfix

2015-09-14 Thread Piotr Padlewski via cfe-commits
Prazek created this revision.
Prazek added reviewers: rsmith, rjmccall, hans, majnemer.
Prazek added a subscriber: cfe-commits.

http://reviews.llvm.org/D12865

Files:
  include/clang/AST/VTableBuilder.h
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/vtable-assume-load.cpp
  test/CodeGenCXX/vtable-available-externally.cpp

Index: test/CodeGenCXX/vtable-available-externally.cpp
===
--- test/CodeGenCXX/vtable-available-externally.cpp
+++ test/CodeGenCXX/vtable-available-externally.cpp
@@ -11,6 +11,7 @@
 // RUN: FileCheck --check-prefix=CHECK-TEST13 %s < %t.opt
 // RUN: FileCheck --check-prefix=CHECK-TEST14 %s < %t.opt
 // RUN: FileCheck --check-prefix=CHECK-TEST15 %s < %t.opt
+// RUN: FileCheck --check-prefix=CHECK-TEST16 %s < %t.opt
 
 #include 
 
@@ -365,3 +366,28 @@
 }
 }
 
+namespace Test16 {
+// Both classes have methods that are hidden, because of it we can't
+// generate available_externally vtables.
+// CHECK-TEST16-DAG: @_ZTVN6Test161SE = external unnamed_addr constant
+// CHECK-TEST16-DAG: @_ZTVN6Test162S2E = available_externally
+
+struct S {
+  __attribute__((visibility("hidden"))) virtual void doStuff();
+};
+
+struct S2 {
+  virtual void doStuff();
+  __attribute__((visibility("hidden"))) void unused();
+
+};
+
+void test() {
+  S *s = new S;
+  s->doStuff();
+
+  S2 *s2 = new S2;
+  s2->doStuff();
+}
+}
+
Index: test/CodeGenCXX/vtable-assume-load.cpp
===
--- test/CodeGenCXX/vtable-assume-load.cpp
+++ test/CodeGenCXX/vtable-assume-load.cpp
@@ -9,6 +9,7 @@
 // RUN: FileCheck --check-prefix=CHECK6 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK7 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK8 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK9 --input-file=%t.ll %s
 namespace test1 {
 
 struct A {
@@ -174,19 +175,19 @@
 } // testMS
 
 namespace test6 {
-// CHECK6: @_ZTVN5test61AE = external
 struct A {
   A();
   virtual void foo();
   virtual ~A() {}
 };
 struct B : A {
   B();
 };
-// Because A's vtable is external, it's safe to generate assumption loads.
+// FIXME: Because A's vtable is external, and all functions aint hidden,
+// it's safe to generate assumption loads.
 // CHECK6-LABEL: define void @_ZN5test61gEv()
 // CHECK6: call void @_ZN5test61AC1Ev(
-// CHECK6: call void @llvm.assume(
+// CHECK6-NOT: call void @llvm.assume(
 
 // We can't emit assumption loads for B, because if we would refer to vtable
 // it would refer to functions that will not be able to find (like implicit
@@ -243,7 +244,6 @@
 };
 inline void C::bar() {}
 
-// CHECK8-DAG: @_ZTVN5test81DE = external unnamed_addr constant
 struct D : A {
   D();
   void foo();
@@ -275,8 +275,9 @@
   c.bar();
 }
 
+// FIXME: We could generate assumption loads here.
 // CHECK8-LABEL: define void @_ZN5test81dEv()
-// CHECK8: call void @llvm.assume(
+// CHECK8-NOT: call void @llvm.assume(
 // CHECK8-LABEL: }
 void d() {
   D d;
@@ -291,3 +292,21 @@
   e.bar();
 }
 }
+
+namespace test9 {
+
+struct S {
+  __attribute__((visibility("hidden"))) S();
+  virtual void doStuff();
+};
+
+// CHECK9-LABEL: define void @_ZN5test94testEv()
+// CHECK9-NOT: @llvm.assume(
+// CHECK9: }
+void test() {
+  S *s = new S();
+  s->doStuff();
+  delete s;
+}
+}
+
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -386,6 +386,26 @@
 }
 return false;
   }
+
+  bool isVTableHidden(const CXXRecordDecl *RD) const {
+const auto &VtableLayout =
+CGM.getItaniumVTableContext().getVTableLayout(RD);
+
+for (const auto &VtableComponent : VtableLayout.vtable_components()) {
+  if (VtableComponent.isRTTIKind()) {
+const CXXRecordDecl *RTTIDecl = VtableComponent.getRTTIDecl();
+if (RTTIDecl->getVisibility() == Visibility::HiddenVisibility)
+  return true;
+  }
+  else if (VtableComponent.isUsedFunctionPointerKind()) {
+const CXXMethodDecl *Method = VtableComponent.getFunctionDecl();
+if (Method->getVisibility() == Visibility::HiddenVisibility &&
+!Method->isDefined())
+  return true;
+  }
+}
+return false;
+  }
 };
 
 class ARMCXXABI : public ItaniumCXXABI {
@@ -1615,11 +1635,11 @@
   if (CGM.getLangOpts().AppleKext)
 return false;
 
-  // If we don't have any inline virtual functions,
+  // If we don't have any inline virtual functions, and if vtable is not hidden,
   // then we are safe to emit available_externally copy of vtable.
   // FIXME we can still emit a copy of the vtable if we
   // can emit definition of the inline functions.
-  return !hasAnyUsedVirtualInlineFunction(RD);
+  return !hasAnyUsedVirtualInlineFunction(RD) && !isVTableHidden(RD);
 }
 static llvm::Value *performTypeAdjustment(CodeGenFunction &CGF,

Re: [PATCH] D12865: Generating available_externally vtables and assume loads bugfix

2015-09-14 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 34750.

http://reviews.llvm.org/D12865

Files:
  include/clang/AST/VTableBuilder.h
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/vtable-assume-load.cpp
  test/CodeGenCXX/vtable-available-externally.cpp

Index: test/CodeGenCXX/vtable-available-externally.cpp
===
--- test/CodeGenCXX/vtable-available-externally.cpp
+++ test/CodeGenCXX/vtable-available-externally.cpp
@@ -11,6 +11,7 @@
 // RUN: FileCheck --check-prefix=CHECK-TEST13 %s < %t.opt
 // RUN: FileCheck --check-prefix=CHECK-TEST14 %s < %t.opt
 // RUN: FileCheck --check-prefix=CHECK-TEST15 %s < %t.opt
+// RUN: FileCheck --check-prefix=CHECK-TEST16 %s < %t.opt
 
 #include 
 
@@ -365,3 +366,28 @@
 }
 }
 
+namespace Test16 {
+// S has virtual method that is hidden, because of it we can't
+// generate available_externally vtable for it.
+// CHECK-TEST16-DAG: @_ZTVN6Test161SE = external unnamed_addr constant
+// CHECK-TEST16-DAG: @_ZTVN6Test162S2E = available_externally
+
+struct S {
+  __attribute__((visibility("hidden"))) virtual void doStuff();
+};
+
+struct S2 {
+  virtual void doStuff();
+  __attribute__((visibility("hidden"))) void unused();
+
+};
+
+void test() {
+  S *s = new S;
+  s->doStuff();
+
+  S2 *s2 = new S2;
+  s2->doStuff();
+}
+}
+
Index: test/CodeGenCXX/vtable-assume-load.cpp
===
--- test/CodeGenCXX/vtable-assume-load.cpp
+++ test/CodeGenCXX/vtable-assume-load.cpp
@@ -9,6 +9,7 @@
 // RUN: FileCheck --check-prefix=CHECK6 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK7 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK8 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK9 --input-file=%t.ll %s
 namespace test1 {
 
 struct A {
@@ -174,19 +175,19 @@
 } // testMS
 
 namespace test6 {
-// CHECK6: @_ZTVN5test61AE = external
 struct A {
   A();
   virtual void foo();
   virtual ~A() {}
 };
 struct B : A {
   B();
 };
-// Because A's vtable is external, it's safe to generate assumption loads.
+// FIXME: Because A's vtable is external, and all functions aint hidden,
+// it's safe to generate assumption loads.
 // CHECK6-LABEL: define void @_ZN5test61gEv()
 // CHECK6: call void @_ZN5test61AC1Ev(
-// CHECK6: call void @llvm.assume(
+// CHECK6-NOT: call void @llvm.assume(
 
 // We can't emit assumption loads for B, because if we would refer to vtable
 // it would refer to functions that will not be able to find (like implicit
@@ -243,7 +244,6 @@
 };
 inline void C::bar() {}
 
-// CHECK8-DAG: @_ZTVN5test81DE = external unnamed_addr constant
 struct D : A {
   D();
   void foo();
@@ -275,8 +275,9 @@
   c.bar();
 }
 
+// FIXME: We could generate assumption loads here.
 // CHECK8-LABEL: define void @_ZN5test81dEv()
-// CHECK8: call void @llvm.assume(
+// CHECK8-NOT: call void @llvm.assume(
 // CHECK8-LABEL: }
 void d() {
   D d;
@@ -291,3 +292,21 @@
   e.bar();
 }
 }
+
+namespace test9 {
+
+struct S {
+  __attribute__((visibility("hidden"))) S();
+  virtual void doStuff();
+};
+
+// CHECK9-LABEL: define void @_ZN5test94testEv()
+// CHECK9-NOT: @llvm.assume(
+// CHECK9: }
+void test() {
+  S *s = new S();
+  s->doStuff();
+  delete s;
+}
+}
+
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -386,6 +386,26 @@
 }
 return false;
   }
+
+  bool isVTableHidden(const CXXRecordDecl *RD) const {
+const auto &VtableLayout =
+CGM.getItaniumVTableContext().getVTableLayout(RD);
+
+for (const auto &VtableComponent : VtableLayout.vtable_components()) {
+  if (VtableComponent.isRTTIKind()) {
+const CXXRecordDecl *RTTIDecl = VtableComponent.getRTTIDecl();
+if (RTTIDecl->getVisibility() == Visibility::HiddenVisibility)
+  return true;
+  }
+  else if (VtableComponent.isUsedFunctionPointerKind()) {
+const CXXMethodDecl *Method = VtableComponent.getFunctionDecl();
+if (Method->getVisibility() == Visibility::HiddenVisibility &&
+!Method->isDefined())
+  return true;
+  }
+}
+return false;
+  }
 };
 
 class ARMCXXABI : public ItaniumCXXABI {
@@ -1615,11 +1635,11 @@
   if (CGM.getLangOpts().AppleKext)
 return false;
 
-  // If we don't have any inline virtual functions,
+  // If we don't have any inline virtual functions, and if vtable is not hidden,
   // then we are safe to emit available_externally copy of vtable.
   // FIXME we can still emit a copy of the vtable if we
   // can emit definition of the inline functions.
-  return !hasAnyUsedVirtualInlineFunction(RD);
+  return !hasAnyUsedVirtualInlineFunction(RD) && !isVTableHidden(RD);
 }
 static llvm::Value *performTypeAdjustment(CodeGenFunction &CGF,
   Address InitialPtr,
Index: lib/CodeGen/CGClass.cpp
==

Re: [PATCH] D12865: Generating available_externally vtables and assume loads bugfix

2015-09-14 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 34761.
Prazek marked 3 inline comments as done.

http://reviews.llvm.org/D12865

Files:
  include/clang/AST/VTableBuilder.h
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/vtable-assume-load.cpp
  test/CodeGenCXX/vtable-available-externally.cpp

Index: test/CodeGenCXX/vtable-available-externally.cpp
===
--- test/CodeGenCXX/vtable-available-externally.cpp
+++ test/CodeGenCXX/vtable-available-externally.cpp
@@ -11,6 +11,7 @@
 // RUN: FileCheck --check-prefix=CHECK-TEST13 %s < %t.opt
 // RUN: FileCheck --check-prefix=CHECK-TEST14 %s < %t.opt
 // RUN: FileCheck --check-prefix=CHECK-TEST15 %s < %t.opt
+// RUN: FileCheck --check-prefix=CHECK-TEST16 %s < %t.opt
 
 #include 
 
@@ -365,3 +366,28 @@
 }
 }
 
+namespace Test16 {
+// S has virtual method that is hidden, because of it we can't
+// generate available_externally vtable for it.
+// CHECK-TEST16-DAG: @_ZTVN6Test161SE = external unnamed_addr constant
+// CHECK-TEST16-DAG: @_ZTVN6Test162S2E = available_externally
+
+struct S {
+  __attribute__((visibility("hidden"))) virtual void doStuff();
+};
+
+struct S2 {
+  virtual void doStuff();
+  __attribute__((visibility("hidden"))) void unused();
+
+};
+
+void test() {
+  S *s = new S;
+  s->doStuff();
+
+  S2 *s2 = new S2;
+  s2->doStuff();
+}
+}
+
Index: test/CodeGenCXX/vtable-assume-load.cpp
===
--- test/CodeGenCXX/vtable-assume-load.cpp
+++ test/CodeGenCXX/vtable-assume-load.cpp
@@ -9,6 +9,7 @@
 // RUN: FileCheck --check-prefix=CHECK6 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK7 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK8 --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=CHECK9 --input-file=%t.ll %s
 namespace test1 {
 
 struct A {
@@ -174,19 +175,19 @@
 } // testMS
 
 namespace test6 {
-// CHECK6: @_ZTVN5test61AE = external
 struct A {
   A();
   virtual void foo();
   virtual ~A() {}
 };
 struct B : A {
   B();
 };
-// Because A's vtable is external, it's safe to generate assumption loads.
+// FIXME: Because A's vtable is external, and no virtual functions are hidden,
+// it's safe to generate assumption loads.
 // CHECK6-LABEL: define void @_ZN5test61gEv()
 // CHECK6: call void @_ZN5test61AC1Ev(
-// CHECK6: call void @llvm.assume(
+// CHECK6-NOT: call void @llvm.assume(
 
 // We can't emit assumption loads for B, because if we would refer to vtable
 // it would refer to functions that will not be able to find (like implicit
@@ -243,7 +244,6 @@
 };
 inline void C::bar() {}
 
-// CHECK8-DAG: @_ZTVN5test81DE = external unnamed_addr constant
 struct D : A {
   D();
   void foo();
@@ -275,8 +275,9 @@
   c.bar();
 }
 
+// FIXME: We could generate assumption loads here.
 // CHECK8-LABEL: define void @_ZN5test81dEv()
-// CHECK8: call void @llvm.assume(
+// CHECK8-NOT: call void @llvm.assume(
 // CHECK8-LABEL: }
 void d() {
   D d;
@@ -291,3 +292,21 @@
   e.bar();
 }
 }
+
+namespace test9 {
+
+struct S {
+  __attribute__((visibility("hidden"))) S();
+  virtual void doStuff();
+};
+
+// CHECK9-LABEL: define void @_ZN5test94testEv()
+// CHECK9-NOT: @llvm.assume(
+// CHECK9: }
+void test() {
+  S *s = new S();
+  s->doStuff();
+  delete s;
+}
+}
+
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -386,6 +386,25 @@
 }
 return false;
   }
+
+  bool isVTableHidden(const CXXRecordDecl *RD) const {
+const auto &VtableLayout =
+CGM.getItaniumVTableContext().getVTableLayout(RD);
+
+for (const auto &VtableComponent : VtableLayout.vtable_components()) {
+  if (VtableComponent.isRTTIKind()) {
+const CXXRecordDecl *RTTIDecl = VtableComponent.getRTTIDecl();
+if (RTTIDecl->getVisibility() == Visibility::HiddenVisibility)
+  return true;
+  } else if (VtableComponent.isUsedFunctionPointerKind()) {
+const CXXMethodDecl *Method = VtableComponent.getFunctionDecl();
+if (Method->getVisibility() == Visibility::HiddenVisibility &&
+!Method->isDefined())
+  return true;
+  }
+}
+return false;
+  }
 };
 
 class ARMCXXABI : public ItaniumCXXABI {
@@ -1615,11 +1634,11 @@
   if (CGM.getLangOpts().AppleKext)
 return false;
 
-  // If we don't have any inline virtual functions,
+  // If we don't have any inline virtual functions, and if vtable is not hidden,
   // then we are safe to emit available_externally copy of vtable.
   // FIXME we can still emit a copy of the vtable if we
   // can emit definition of the inline functions.
-  return !hasAnyUsedVirtualInlineFunction(RD);
+  return !hasAnyUsedVirtualInlineFunction(RD) && !isVTableHidden(RD);
 }
 static llvm::Value *performTypeAdjustment(CodeGenFunction &CGF,
   Address InitialPtr,
Index

Re: [PATCH] D12865: Generating available_externally vtables and assume loads bugfix

2015-09-14 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.


Comment at: lib/CodeGen/ItaniumCXXABI.cpp:394-406
@@ +393,15 @@
+
+for (const auto &VtableComponent : VtableLayout.vtable_components()) {
+  if (VtableComponent.isRTTIKind()) {
+const CXXRecordDecl *RTTIDecl = VtableComponent.getRTTIDecl();
+if (RTTIDecl->getVisibility() == Visibility::HiddenVisibility)
+  return true;
+  } else if (VtableComponent.isUsedFunctionPointerKind()) {
+const CXXMethodDecl *Method = VtableComponent.getFunctionDecl();
+if (Method->getVisibility() == Visibility::HiddenVisibility &&
+!Method->isDefined())
+  return true;
+  }
+}
+return false;
+  }

isUdedFunctionPointerKind check for CK_FunctionPointer, CK_CompleteDtorPointer, 
CK_DeletingDtorPointer


http://reviews.llvm.org/D12865



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


r247646 - Generating assumption loads of vptr after ctor call (fixed)

2015-09-14 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Mon Sep 14 19:37:06 2015
New Revision: 247646

URL: http://llvm.org/viewvc/llvm-project?rev=247646&view=rev
Log:
Generating assumption loads of vptr after ctor call (fixed)

Generating call assume(icmp %vtable, %global_vtable) after constructor
call for devirtualization purposes.

For more info go to:
http://lists.llvm.org/pipermail/cfe-dev/2015-July/044227.html

Edit:
Fixed version because of PR24479 and other bug caused in chrome.
After this patch got reverted because of ScalarEvolution bug (D12719)
Merged after John McCall big patch (Added Address).

http://reviews.llvm.org/D11859
http://reviews.llvm.org/D12865

Added:
cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp
Modified:
cfe/trunk/include/clang/AST/VTableBuilder.h
cfe/trunk/lib/CodeGen/CGCXXABI.h
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGVTables.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/test/CodeGen/available-externally-hidden.cpp
cfe/trunk/test/CodeGenCXX/ctor-globalopt.cpp
cfe/trunk/test/CodeGenCXX/thunks.cpp
cfe/trunk/test/CodeGenCXX/virtual-base-ctor.cpp
cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp

Modified: cfe/trunk/include/clang/AST/VTableBuilder.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/VTableBuilder.h?rev=247646&r1=247645&r2=247646&view=diff
==
--- cfe/trunk/include/clang/AST/VTableBuilder.h (original)
+++ cfe/trunk/include/clang/AST/VTableBuilder.h Mon Sep 14 19:37:06 2015
@@ -122,7 +122,7 @@ public:
   }
 
   const CXXRecordDecl *getRTTIDecl() const {
-assert(getKind() == CK_RTTI && "Invalid component kind!");
+assert(isRTTIKind() && "Invalid component kind!");
 return reinterpret_cast(getPointer());
   }
 
@@ -153,6 +153,8 @@ public:
 return isFunctionPointerKind(getKind());
   }
 
+  bool isRTTIKind() const { return isRTTIKind(getKind()); }
+
 private:
   static bool isFunctionPointerKind(Kind ComponentKind) {
 return isUsedFunctionPointerKind(ComponentKind) ||
@@ -166,6 +168,9 @@ private:
 return ComponentKind == CK_CompleteDtorPointer ||
ComponentKind == CK_DeletingDtorPointer;
   }
+  static bool isRTTIKind(Kind ComponentKind) {
+return ComponentKind == CK_RTTI;
+  }
 
   VTableComponent(Kind ComponentKind, CharUnits Offset) {
 assert((ComponentKind == CK_VCallOffset ||
@@ -178,7 +183,7 @@ private:
   }
 
   VTableComponent(Kind ComponentKind, uintptr_t Ptr) {
-assert((ComponentKind == CK_RTTI || isFunctionPointerKind(ComponentKind)) 
&&
+assert((isRTTIKind(ComponentKind) || isFunctionPointerKind(ComponentKind)) 
&&
"Invalid component kind!");
 
 assert((Ptr & 7) == 0 && "Pointer not sufficiently aligned!");

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=247646&r1=247645&r2=247646&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.h Mon Sep 14 19:37:06 2015
@@ -224,8 +224,10 @@ public:
   virtual void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E) = 0;
   virtual llvm::GlobalVariable *getThrowInfo(QualType T) { return nullptr; }
 
-  virtual bool canEmitAvailableExternallyVTable(
-  const CXXRecordDecl *RD) const = 0;
+  /// \brief Determine whether it's possible to emit a vtable for \p RD, even
+  /// though we do not know that the vtable has been marked as used by semantic
+  /// analysis.
+  virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const = 0;
 
   virtual void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C) = 0;
 
@@ -351,13 +353,25 @@ public:
   virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
  const CXXRecordDecl *RD) = 0;
 
+  /// Checks if ABI requires extra virtual offset for vtable field.
+  virtual bool
+  isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF,
+  CodeGenFunction::VPtr Vptr) = 0;
+
+  /// Checks if ABI requires to initilize vptrs for given dynamic class.
+  virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass) = 
0;
+
+  /// Get the address point of the vtable for the given base subobject.
+  virtual llvm::Constant *
+  getVTableAddressPoint(BaseSubobject Base,
+const CXXRecordDecl *VTableClass) = 0;
+
   /// Get the address point of the vtable for the given base subobject while
-  /// building a constructor or a destructor. On return, NeedsVirtualOffset
-  /// tells if a virtual base adjustment is needed in order to get the offset
-  /// of the base subobject.
-  virtual llvm::Value *getVTableAddressPointInStructor(
-  CodeGenFunction 

Re: [PATCH] D12865: Generating available_externally vtables and assume loads bugfix

2015-09-14 Thread Piotr Padlewski via cfe-commits
Prazek closed this revision.
Prazek added a comment.

Assume loads released.


http://reviews.llvm.org/D12865



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


r247650 - small test bugfix

2015-09-14 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Mon Sep 14 19:55:29 2015
New Revision: 247650

URL: http://llvm.org/viewvc/llvm-project?rev=247650&view=rev
Log:
small test bugfix

Modified:
cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp

Modified: cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp?rev=247650&r1=247649&r2=247650&view=diff
==
--- cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp Mon Sep 14 19:55:29 2015
@@ -296,8 +296,8 @@ void e() {
 namespace test9 {
 
 struct S {
-  __attribute__((visibility("hidden"))) S();
-  virtual void doStuff();
+  S();
+  __attribute__((visibility("hidden"))) virtual void doStuff();
 };
 
 // CHECK9-LABEL: define void @_ZN5test94testEv()


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


Re: [PATCH] D12026: Decorating vptr load & stores with !invariant.group

2015-09-15 Thread Piotr Padlewski via cfe-commits
Prazek updated the summary for this revision.
Prazek updated this revision to Diff 34833.

http://reviews.llvm.org/D12026

Files:
  lib/CodeGen/CGAtomic.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGenCXX/invariant.group-for-vptrs.cpp

Index: test/CodeGenCXX/invariant.group-for-vptrs.cpp
===
--- /dev/null
+++ test/CodeGenCXX/invariant.group-for-vptrs.cpp
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm %s -fstrict-vtable-pointers -O1 -o - -disable-llvm-optzns | FileCheck %s
+
+struct A {
+  virtual void foo();
+};
+
+struct D : A {
+  void foo();
+};
+
+// CHECK-LABEL: define void @_Z21testExternallyVisiblev()
+void testExternallyVisible() {
+  A *a = new A;
+
+  // CHECK: load {{.*}} !invariant.group ![[A_MD:[0-9]+]]
+  a->foo();
+
+  D *d = new D;
+  // CHECK: call void @_ZN1DC1Ev(
+  // CHECK: load {{.*}} !invariant.group ![[D_MD:[0-9]+]]
+  d->foo();
+  A *a2 = d;
+  // CHECK: load {{.*}} !invariant.group ![[A_MD]]
+  a2->foo();
+}
+// CHECK-LABEL: }
+
+namespace {
+
+struct B {
+  virtual void bar();
+};
+
+struct C : B {
+  void bar();
+};
+
+}
+
+// CHECK-LABEL: define void @_Z21testInternallyVisibleb(
+void testInternallyVisible(bool p) {
+  B *b = new B;
+  // CHECK: = load {{.*}}, !invariant.group ![[B_MD:[0-9]+]]
+  b->bar();
+
+  // CHECK: call void @_ZN12_GLOBAL__N_11CC1Ev(
+  C *c = new C;
+  // CHECK: = load {{.*}}, !invariant.group ![[C_MD:[0-9]+]]
+  c->bar();
+}
+
+// Checking A::A()
+// CHECK-LABEL: define linkonce_odr void @_ZN1AC2Ev(
+// CHECK: store {{.*}}, !invariant.group ![[A_MD]]
+// CHECK-LABEL: }
+
+// Checking D::D()
+// CHECK-LABEL: define linkonce_odr void @_ZN1DC2Ev(
+
+// CHECK:  call void @_ZN1AC2Ev(%struct.A*
+// CHECK:  = call i8* @llvm.invariant.group.barrier(i8*
+// CHECK: store {{.*}} !invariant.group ![[D_MD]]
+
+// Checking B::B()
+// CHECK-LABEL: define internal void @_ZN12_GLOBAL__N_11BC2Ev(
+// CHECK:  store {{.*}}, !invariant.group ![[B_MD]]
+
+// Checking C::C()
+// CHECK-LABEL: define internal void @_ZN12_GLOBAL__N_11CC2Ev(
+// CHECK:  store {{.*}}, !invariant.group ![[C_MD]]
+
+// CHECK: ![[A_MD]] = !{!"_ZTS1A"}
+// CHECK: ![[D_MD]] = !{!"_ZTS1D"}
+// CHECK: ![[B_MD]] = distinct !{}
+// CHECK: ![[C_MD]] = distinct !{}
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1831,7 +1831,9 @@
   Ty = Ty->getPointerTo()->getPointerTo();
   Address VPtr =
   adjustThisArgumentForVirtualFunctionCall(CGF, GD, This, true);
-  llvm::Value *VTable = CGF.GetVTablePtr(VPtr, Ty);
+
+  auto *MethodDecl = cast(GD.getDecl());
+  llvm::Value *VTable = CGF.GetVTablePtr(VPtr, Ty, MethodDecl->getParent());
 
   MicrosoftVTableContext::MethodVFTableLocation ML =
   CGM.getMicrosoftVTableContext().getMethodVFTableLocation(GD);
@@ -1958,7 +1960,8 @@
   // Load the vfptr and then callee from the vftable.  The callee should have
   // adjusted 'this' so that the vfptr is at offset zero.
   llvm::Value *VTable = CGF.GetVTablePtr(
-  getThisAddress(CGF), ThunkTy->getPointerTo()->getPointerTo());
+  getThisAddress(CGF), ThunkTy->getPointerTo()->getPointerTo(), MD->getParent());
+
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, ML.Index, "vfn");
   llvm::Value *Callee =
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -584,7 +584,7 @@
 CGF.CGM.getDynamicOffsetAlignment(ThisAddr.getAlignment(), RD,
   CGF.getPointerAlign());
   llvm::Value *VTable =
-CGF.GetVTablePtr(Address(This, VTablePtrAlign), VTableTy);
+CGF.GetVTablePtr(Address(This, VTablePtrAlign), VTableTy, RD);
 
   // Apply the offset.
   llvm::Value *VTableOffset = FnAsInt;
@@ -1012,7 +1012,10 @@
 // to pass to the deallocation function.
 
 // Grab the vtable pointer as an intptr_t*.
-llvm::Value *VTable = CGF.GetVTablePtr(Ptr, CGF.IntPtrTy->getPointerTo());
+auto *ClassDecl =
+cast(ElementType->getAs()->getDecl());
+llvm::Value *VTable =
+CGF.GetVTablePtr(Ptr, CGF.IntPtrTy->getPointerTo(), ClassDecl);
 
 // Track back to entry -2 and pull out the offset there.
 llvm::Value *OffsetPtr = CGF.Builder.CreateConstInBoundsGEP1_64(
@@ -1211,8 +1214,10 @@
QualType SrcRecordTy,
Address ThisPtr,
llvm::Type *StdTypeInfoPtrTy) {
+  auto *ClassDecl =
+  cast(SrcRecordTy->getAs()->getDecl());
   llvm::Value *Value =
-  CGF.GetVTabl

Re: [PATCH] D12026: Decorating vptr load & stores with !invariant.group

2015-09-15 Thread Piotr Padlewski via cfe-commits
Prazek marked an inline comment as done.


Comment at: lib/CodeGen/CodeGenModule.cpp:3859
@@ -3848,4 +3858,3 @@
   } else {
-InternalId = llvm::MDNode::getDistinct(getLLVMContext(),
-   llvm::ArrayRef());
+InternalId = llvm::MDNode::getDistinct(getLLVMContext(), {});
   }

rsmith wrote:
> I think this may break the MSVC build, and it looks unrelated to the other 
> changes. Revert this bit, or use `llvm::None`. In the latter case, commit 
> this separately.
ok


http://reviews.llvm.org/D12026



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


Re: [PATCH] D12312: Emiting invariant.group.barrier and adding -fstrict-vptrs

2015-09-15 Thread Piotr Padlewski via cfe-commits
Prazek marked an inline comment as done.
Prazek added a comment.

http://reviews.llvm.org/D12312



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


Re: [PATCH] D12312: Emiting invariant.group.barrier and adding -fstrict-vptrs

2015-09-15 Thread Piotr Padlewski via cfe-commits
Prazek accepted this revision.
Prazek added a reviewer: Prazek.
Prazek added a comment.
This revision is now accepted and ready to land.

Accept to close


http://reviews.llvm.org/D12312



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


r247725 - Decorating vptr load & stores with !invariant.group

2015-09-15 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Tue Sep 15 16:46:55 2015
New Revision: 247725

URL: http://llvm.org/viewvc/llvm-project?rev=247725&view=rev
Log:
Decorating vptr load & stores with !invariant.group

Adding !invariant.group to vptr load/stores for devirtualization purposes.
For more goto:
http://lists.llvm.org/pipermail/cfe-dev/2015-July/044227.html

http://reviews.llvm.org/D12026

Added:
cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
Modified:
cfe/trunk/lib/CodeGen/CGAtomic.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp

Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=247725&r1=247724&r2=247725&view=diff
==
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Tue Sep 15 16:46:55 2015
@@ -1246,7 +1246,7 @@ llvm::Value *AtomicInfo::EmitAtomicLoadO
   if (IsVolatile)
 Load->setVolatile(true);
   if (LVal.getTBAAInfo())
-CGF.CGM.DecorateInstruction(Load, LVal.getTBAAInfo());
+CGF.CGM.DecorateInstructionWithTBAA(Load, LVal.getTBAAInfo());
   return Load;
 }
 
@@ -1769,7 +1769,7 @@ void CodeGenFunction::EmitAtomicStore(RV
 if (IsVolatile)
   store->setVolatile(true);
 if (dest.getTBAAInfo())
-  CGM.DecorateInstruction(store, dest.getTBAAInfo());
+  CGM.DecorateInstructionWithTBAA(store, dest.getTBAAInfo());
 return;
   }
 

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=247725&r1=247724&r2=247725&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Tue Sep 15 16:46:55 2015
@@ -25,6 +25,7 @@
 #include "clang/CodeGen/CGFunctionInfo.h"
 #include "clang/Frontend/CodeGenOptions.h"
 #include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/Metadata.h"
 
 using namespace clang;
 using namespace CodeGen;
@@ -2087,7 +2088,8 @@ void CodeGenFunction::EmitVTableAssumpti
 ApplyNonVirtualAndVirtualOffset(*this, This, NonVirtualOffset, nullptr,
 Vptr.VTableClass, Vptr.NearestVBase);
 
-  llvm::Value *VPtrValue = GetVTablePtr(This, VTableGlobal->getType());
+  llvm::Value *VPtrValue =
+  GetVTablePtr(This, VTableGlobal->getType(), Vptr.VTableClass);
   llvm::Value *Cmp =
   Builder.CreateICmpEQ(VPtrValue, VTableGlobal, "cmp.vtables");
   Builder.CreateAssumption(Cmp);
@@ -2306,7 +2308,10 @@ void CodeGenFunction::InitializeVTablePo
   VTableAddressPoint = Builder.CreateBitCast(VTableAddressPoint, VTablePtrTy);
 
   llvm::StoreInst *Store = Builder.CreateStore(VTableAddressPoint, 
VTableField);
-  CGM.DecorateInstruction(Store, CGM.getTBAAInfoForVTablePtr());
+  CGM.DecorateInstructionWithTBAA(Store, CGM.getTBAAInfoForVTablePtr());
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
+CGM.DecorateInstructionWithInvariantGroup(Store, Vptr.VTableClass);
 }
 
 CodeGenFunction::VPtrsVector
@@ -2393,10 +2398,16 @@ void CodeGenFunction::InitializeVTablePo
 }
 
 llvm::Value *CodeGenFunction::GetVTablePtr(Address This,
-   llvm::Type *Ty) {
-  Address VTablePtrSrc = Builder.CreateElementBitCast(This, Ty);
+   llvm::Type *VTableTy,
+   const CXXRecordDecl *RD) {
+  Address VTablePtrSrc = Builder.CreateElementBitCast(This, VTableTy);
   llvm::Instruction *VTable = Builder.CreateLoad(VTablePtrSrc, "vtable");
-  CGM.DecorateInstruction(VTable, CGM.getTBAAInfoForVTablePtr());
+  CGM.DecorateInstructionWithTBAA(VTable, CGM.getTBAAInfoForVTablePtr());
+
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
+CGM.DecorateInstructionWithInvariantGroup(VTable, RD);
+
   return VTable;
 }
 
@@ -2481,7 +2492,8 @@ void CodeGenFunction::EmitVTablePtrCheck
   }
 
   llvm::Value *VTable =
-GetVTablePtr(Address(Derived, getPointerAlign()), Int8PtrTy);
+GetVTablePtr(Address(Derived, getPointerAlign()), Int8PtrTy, ClassDecl);
+
   EmitVTablePtrCheck(ClassDecl, VTable, TCK, Loc);
 
   if (MayBeNull) {

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=247725&r1=247724&r2=247725&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Sep 15 16:46:55 2015
@@ -1277,7 +1277,8 @@ llvm:

r247724 - Added llvm.module flag for strict vtable pointers

2015-09-15 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Tue Sep 15 16:46:50 2015
New Revision: 247724

URL: http://llvm.org/viewvc/llvm-project?rev=247724&view=rev
Log:
Added llvm.module flag for strict vtable pointers

It is dangerous to do LTO on code with strict-vtable-pointers, because
one module has invariant.group.barriers, and the other one not.

In the future I want to just strip all invariant.group metadata from
vptrs loads/stores and get rid of invariant.group.barrier calls.

http://reviews.llvm.org/D12580

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=247724&r1=247723&r2=247724&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Sep 15 16:46:50 2015
@@ -398,6 +398,22 @@ void CodeGenModule::Release() {
 // Indicate that we want CodeView in the metadata.
 getModule().addModuleFlag(llvm::Module::Warning, "CodeView", 1);
   }
+  if (CodeGenOpts.OptimizationLevel > 0 && CodeGenOpts.StrictVTablePointers) {
+// We don't support LTO with 2 with different StrictVTablePointers
+// FIXME: we could support it by stripping all the information introduced
+// by StrictVTablePointers.
+
+getModule().addModuleFlag(llvm::Module::Error, "StrictVTablePointers",1);
+
+llvm::Metadata *Ops[2] = {
+  llvm::MDString::get(VMContext, "StrictVTablePointers"),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  llvm::Type::getInt32Ty(VMContext), 1))};
+
+getModule().addModuleFlag(llvm::Module::Require,
+  "StrictVTablePointersRequirement",
+  llvm::MDNode::get(VMContext, Ops));
+  }
   if (DebugInfo)
 // We support a single version in the linked module. The LLVM
 // parser will drop debug info with a different version number

Modified: cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp?rev=247724&r1=247723&r2=247724&view=diff
==
--- cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp Tue Sep 15 16:46:50 
2015
@@ -2,6 +2,7 @@
 // RUN: FileCheck --check-prefix=CHECK-CTORS %s < %t.ll
 // RUN: FileCheck --check-prefix=CHECK-NEW %s < %t.ll
 // RUN: FileCheck --check-prefix=CHECK-DTORS %s < %t.ll
+// RUN: FileCheck --check-prefix=CHECK-LINK-REQ %s < %t.ll
 
 typedef __typeof__(sizeof(0)) size_t;
 void *operator new(size_t, void*) throw();
@@ -191,3 +192,11 @@ struct DynamicFromStatic;
 // CHECK-DTORS-LABEL: define linkonce_odr void @_ZN14DynamicDerivedD2Ev
 // CHECK-DTORS-NOT: call i8* @llvm.invariant.group.barrier(
 // CHECK-DTORS-LABEL: }
+
+
+// CHECK-LINK-REQ: !llvm.module.flags = !{![[FIRST:.*]], ![[SEC:.*]]{{.*}}}
+
+// CHECK-LINK-REQ: ![[FIRST]] = !{i32 1, !"StrictVTablePointers", i32 1}
+// CHECK-LINK-REQ: ![[SEC]] = !{i32 3, !"StrictVTablePointersRequirement", 
![[META:.*]]}
+// CHECK-LINK-REQ: ![[META]] = !{!"StrictVTablePointers", i32 1}
+


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


r247723 - Emiting llvm.invariant.group.barrier when dynamic type changes

2015-09-15 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Tue Sep 15 16:46:47 2015
New Revision: 247723

URL: http://llvm.org/viewvc/llvm-project?rev=247723&view=rev
Log:
Emiting llvm.invariant.group.barrier when dynamic type changes

For more goto:
http://lists.llvm.org/pipermail/cfe-dev/2015-July/044227.html

http://reviews.llvm.org/D12312

Added:
cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=247723&r1=247722&r2=247723&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Sep 15 16:46:47 2015
@@ -862,6 +862,8 @@ def fno_strict_aliasing : Flag<["-"], "f
 def fstruct_path_tbaa : Flag<["-"], "fstruct-path-tbaa">, Group;
 def fno_struct_path_tbaa : Flag<["-"], "fno-struct-path-tbaa">, Group;
 def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group;
+def fno_strict_vtable_pointers: Flag<["-"], "fno-strict-vtable-pointers">, 
+  Group;
 def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group;
 def fno_threadsafe_statics : Flag<["-"], "fno-threadsafe-statics">, 
Group,
   Flags<[CC1Option]>, HelpText<"Do not emit code to make initialization of 
local statics thread safe">;
@@ -990,6 +992,10 @@ def fstrict_aliasing : Flag<["-"], "fstr
 def fstrict_enums : Flag<["-"], "fstrict-enums">, Group, 
Flags<[CC1Option]>,
   HelpText<"Enable optimizations based on the strict definition of an enum's "
"value range">;
+def fstrict_vtable_pointers: Flag<["-"], "fstrict-vtable-pointers">, 
+  Group, Flags<[CC1Option]>,
+  HelpText<"Enable optimizations based on the strict rules for overwriting "
+ "polymorphic C++ objects">;
 def fstrict_overflow : Flag<["-"], "fstrict-overflow">, Group;
 def fsyntax_only : Flag<["-"], "fsyntax-only">,
   Flags<[DriverOption,CoreOption,CC1Option]>, Group;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=247723&r1=247722&r2=247723&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Sep 15 16:46:47 2015
@@ -132,6 +132,7 @@ CODEGENOPT(SanitizeCoverage8bitCounters,
 CODEGENOPT(SimplifyLibCalls  , 1, 1) ///< Set when -fbuiltin is enabled.
 CODEGENOPT(SoftFloat , 1, 0) ///< -soft-float.
 CODEGENOPT(StrictEnums   , 1, 0) ///< Optimize based on strict enum 
definition.
+CODEGENOPT(StrictVTablePointers, 1, 0) ///< Optimize based on the strict 
vtable pointers
 CODEGENOPT(TimePasses, 1, 0) ///< Set when -ftime-report is enabled.
 CODEGENOPT(UnitAtATime   , 1, 1) ///< Unused. For mirroring GCC 
optimization
  ///< selection.

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=247723&r1=247722&r2=247723&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Tue Sep 15 16:46:47 2015
@@ -1344,6 +1344,13 @@ namespace {
 
 }
 
+static bool isInitializerOfDynamicClass(const CXXCtorInitializer *BaseInit) {
+  const Type *BaseType = BaseInit->getBaseClass();
+  const auto *BaseClassDecl =
+  cast(BaseType->getAs()->getDecl());
+  return BaseClassDecl->isDynamicClass();
+}
+
 /// EmitCtorPrologue - This routine generates necessary code to initialize
 /// base classes and non-static data members belonging to this constructor.
 void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD,
@@ -1367,9 +1374,13 @@ void CodeGenFunction::EmitCtorPrologue(c
 assert(BaseCtorContinueBB);
   }
 
+  bool BaseVPtrsInitialized = false;
   // Virtual base initializers first.
   for (; B != E && (*B)->isBaseInitializer() && (*B)->isBaseVirtual(); B++) {
+CXXCtorInitializer *BaseInit = *B;
 EmitBaseInitializer(*this, ClassDecl, *B, CtorType);
+BaseVPtrsInitialized |= BaseInitializerUsesThis(getContext(),
+BaseInit->getInit());
   }
 
   if (BaseCtorContinueBB) {
@@ -1382,8 +1393,15 @@ void CodeGenFunction::EmitCtorPrologue(c
   for (; B != E && (*B)->isBaseInitializer(); B++) {
 assert(!(*B)->isBaseVirtual());
 EmitBaseInitializer(*this, ClassDecl, *B, CtorType);
+BaseVPtrsInitialized |= isInitializerOfDynamicClass(*B);
   }
 
+  // Pointer to this requ

r247733 - invariant.group-for-vptrs test fix

2015-09-15 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Tue Sep 15 18:04:47 2015
New Revision: 247733

URL: http://llvm.org/viewvc/llvm-project?rev=247733&view=rev
Log:
invariant.group-for-vptrs test fix

Modified:
cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp

Modified: cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp?rev=247733&r1=247732&r2=247733&view=diff
==
--- cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp Tue Sep 15 18:04:47 
2015
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm %s 
-fstrict-vtable-pointers -O1 -o - -disable-llvm-optzns | FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -emit-llvm %s 
-fstrict-vtable-pointers -O1 -o - -disable-llvm-optzns | FileCheck %s
 
 struct A {
   virtual void foo();


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


[PATCH] D12927: Using MD_invariant_group

2015-09-17 Thread Piotr Padlewski via cfe-commits
Prazek created this revision.
Prazek added reviewers: rsmith, nlewycky, majnemer.
Prazek added a subscriber: cfe-commits.

Using changes from http://reviews.llvm.org/D12926

http://reviews.llvm.org/D12927

Files:
  lib/CodeGen/CodeGenModule.cpp

Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -524,7 +524,7 @@
   // Check if we have to wrap MDString in MDNode.
   if (!MetaDataNode)
 MetaDataNode = llvm::MDNode::get(getLLVMContext(), MD);
-  I->setMetadata("invariant.group", MetaDataNode);
+  I->setMetadata(llvm::LLVMContext::MD_invariant_group, MetaDataNode);
 }
 
 void CodeGenModule::Error(SourceLocation loc, StringRef message) {


Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -524,7 +524,7 @@
   // Check if we have to wrap MDString in MDNode.
   if (!MetaDataNode)
 MetaDataNode = llvm::MDNode::get(getLLVMContext(), MD);
-  I->setMetadata("invariant.group", MetaDataNode);
+  I->setMetadata(llvm::LLVMContext::MD_invariant_group, MetaDataNode);
 }
 
 void CodeGenModule::Error(SourceLocation loc, StringRef message) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r247933 - Using MD_invariant_group

2015-09-17 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Thu Sep 17 15:25:46 2015
New Revision: 247933

URL: http://llvm.org/viewvc/llvm-project?rev=247933&view=rev
Log:
Using MD_invariant_group

http://reviews.llvm.org/D12927

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=247933&r1=247932&r2=247933&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Sep 17 15:25:46 2015
@@ -524,7 +524,7 @@ void CodeGenModule::DecorateInstructionW
   // Check if we have to wrap MDString in MDNode.
   if (!MetaDataNode)
 MetaDataNode = llvm::MDNode::get(getLLVMContext(), MD);
-  I->setMetadata("invariant.group", MetaDataNode);
+  I->setMetadata(llvm::LLVMContext::MD_invariant_group, MetaDataNode);
 }
 
 void CodeGenModule::Error(SourceLocation loc, StringRef message) {


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


[PATCH] D13223: Generate assume loads only with -fstrict-vtable-pointers

2015-09-28 Thread Piotr Padlewski via cfe-commits
Prazek created this revision.
Prazek added reviewers: rsmith, samsonov, majnemer.
Prazek added a subscriber: cfe-commits.

Temporary fix till InstCombine and other possible passes will be efficient to 
handle multiple assumes.

http://reviews.llvm.org/D13223

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenCXX/vtable-assume-load.cpp

Index: test/CodeGenCXX/vtable-assume-load.cpp
===
--- test/CodeGenCXX/vtable-assume-load.cpp
+++ test/CodeGenCXX/vtable-assume-load.cpp
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 
-disable-llvm-optzns -fms-extensions
-// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 
-disable-llvm-optzns -fms-extensions
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 
-disable-llvm-optzns -fms-extensions -fstrict-vtable-pointers
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 
-disable-llvm-optzns -fms-extensions -fstrict-vtable-pointers
+// FIXME: Assume load should not require -fstrict-vtable-pointers
 
 // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t.ll %s
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -2107,9 +2107,12 @@
   // FIXME: If vtable is used by ctor/dtor, or if vtable is external and we are
   // sure that definition of vtable is not hidden,
   // then we are always safe to refer to it.
+  // FIXME: It looks like InstCombine is very inefficient on dealing with
+  // assumes. Assumption loads requires -fstrict-vtable-pointers temporary.
   if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
   ClassDecl->isDynamicClass() && Type != Ctor_Base &&
-  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl))
+  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl) &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
 EmitVTableAssumptionLoads(ClassDecl, This);
 }
 


Index: test/CodeGenCXX/vtable-assume-load.cpp
===
--- test/CodeGenCXX/vtable-assume-load.cpp
+++ test/CodeGenCXX/vtable-assume-load.cpp
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 -disable-llvm-optzns -fms-extensions
-// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 -disable-llvm-optzns -fms-extensions
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 -disable-llvm-optzns -fms-extensions -fstrict-vtable-pointers
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 -disable-llvm-optzns -fms-extensions -fstrict-vtable-pointers
+// FIXME: Assume load should not require -fstrict-vtable-pointers
 
 // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t.ll %s
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -2107,9 +2107,12 @@
   // FIXME: If vtable is used by ctor/dtor, or if vtable is external and we are
   // sure that definition of vtable is not hidden,
   // then we are always safe to refer to it.
+  // FIXME: It looks like InstCombine is very inefficient on dealing with
+  // assumes. Assumption loads requires -fstrict-vtable-pointers temporary.
   if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
   ClassDecl->isDynamicClass() && Type != Ctor_Base &&
-  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl))
+  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl) &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
 EmitVTableAssumptionLoads(ClassDecl, This);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r248734 - Generate assume loads only with -fstrict-vtable-pointers

2015-09-28 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Mon Sep 28 15:30:22 2015
New Revision: 248734

URL: http://llvm.org/viewvc/llvm-project?rev=248734&view=rev
Log:
Generate assume loads only with -fstrict-vtable-pointers

Temporary fix till InstCombine and other possible passes will be
efficient to handle multiple assumes.

Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=248734&r1=248733&r2=248734&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon Sep 28 15:30:22 2015
@@ -2107,9 +2107,12 @@ void CodeGenFunction::EmitCXXConstructor
   // FIXME: If vtable is used by ctor/dtor, or if vtable is external and we are
   // sure that definition of vtable is not hidden,
   // then we are always safe to refer to it.
+  // FIXME: It looks like InstCombine is very inefficient on dealing with
+  // assumes. Make assumption loads require -fstrict-vtable-pointers 
temporarily.
   if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
   ClassDecl->isDynamicClass() && Type != Ctor_Base &&
-  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl))
+  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl) &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
 EmitVTableAssumptionLoads(ClassDecl, This);
 }
 

Modified: cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp?rev=248734&r1=248733&r2=248734&view=diff
==
--- cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp Mon Sep 28 15:30:22 2015
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 
-disable-llvm-optzns -fms-extensions
-// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 
-disable-llvm-optzns -fms-extensions
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 
-disable-llvm-optzns -fms-extensions -fstrict-vtable-pointers
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 
-disable-llvm-optzns -fms-extensions -fstrict-vtable-pointers
+// FIXME: Assume load should not require -fstrict-vtable-pointers
 
 // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t.ll %s


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


[PATCH] D13279: Decorating virtual functions load with invariant.load

2015-09-29 Thread Piotr Padlewski via cfe-commits
Prazek created this revision.
Prazek added reviewers: rsmith, majnemer, nlewycky, rjmccall.
Prazek added a subscriber: cfe-commits.

http://reviews.llvm.org/D13279

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/virtual-function-calls.cpp

Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - 
-fstrict-vtable-pointers | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load 
![[EMPTY_NODE:[0-9]]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1609,7 +1609,15 @@
   uint64_t VTableIndex = 
CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+  // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+  // would not help in devirtualization.
+  if (CGM.getCodeGenOpts().StrictVTablePointers)
+Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+  return Inst;
 }
 
 llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(


Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - -fstrict-vtable-pointers | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load ![[EMPTY_NODE:[0-9]]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1609,7 +1609,15 @@
   uint64_t VTableIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+  // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+  // would not help in devirtualization.
+  if (CGM.getCodeGenOpts().StrictVTablePointers)
+Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+  return Inst;
 }
 
 llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13279: Decorating virtual functions load with invariant.load

2015-09-30 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 36125.

http://reviews.llvm.org/D13279

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/virtual-function-calls.cpp

Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - 
-fstrict-vtable-pointers | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load 
![[EMPTY_NODE:[0-9]]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1609,7 +1609,16 @@
   uint64_t VTableIndex = 
CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+  // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+  // would not help in devirtualization.
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
+Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+  return Inst;
 }
 
 llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(


Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - -fstrict-vtable-pointers | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load ![[EMPTY_NODE:[0-9]]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1609,7 +1609,16 @@
   uint64_t VTableIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+  // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+  // would not help in devirtualization.
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
+Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+  return Inst;
 }
 
 llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13279: Decorating virtual functions load with invariant.load

2015-09-30 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 36130.

http://reviews.llvm.org/D13279

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/virtual-function-calls.cpp

Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - 
-fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load 
![[EMPTY_NODE:[0-9]]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1609,7 +1609,16 @@
   uint64_t VTableIndex = 
CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+  // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+  // would not help in devirtualization.
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
+Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+  return Inst;
 }
 
 llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(


Index: test/CodeGenCXX/virtual-function-calls.cpp
===
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - -fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load ![[EMPTY_NODE:[0-9]]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1609,7 +1609,16 @@
   uint64_t VTableIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+  // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+  // would not help in devirtualization.
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
+Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+  return Inst;
 }
 
 llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r248982 - Decorating virtual functions load with invariant.load

2015-09-30 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Wed Sep 30 22:50:41 2015
New Revision: 248982

URL: http://llvm.org/viewvc/llvm-project?rev=248982&view=rev
Log:
Decorating virtual functions load with invariant.load

http://reviews.llvm.org/D13279

Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=248982&r1=248981&r2=248982&view=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Wed Sep 30 22:50:41 2015
@@ -1609,7 +1609,16 @@ llvm::Value *ItaniumCXXABI::getVirtualFu
   uint64_t VTableIndex = 
CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFuncPtr =
   CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+  // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+  // would not help in devirtualization.
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+  CGM.getCodeGenOpts().StrictVTablePointers)
+Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+  llvm::MDNode::get(CGM.getLLVMContext(),
+llvm::ArrayRef()));
+  return Inst;
 }
 
 llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(

Modified: cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp?rev=248982&r1=248981&r2=248982&view=diff
==
--- cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp Wed Sep 30 22:50:41 
2015
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - 
-fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
 
 // PR5021
 namespace PR5021 {
@@ -42,10 +43,14 @@ namespace VirtualNoreturn {
 [[noreturn]] virtual void f();
   };
 
-  // CHECK: @_ZN15VirtualNoreturn1f
+  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
   void f(A *p) {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
+// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load 
![[EMPTY_NODE:[0-9]]]
   }
 }
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}


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


r248984 - Test fix

2015-09-30 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Wed Sep 30 23:19:45 2015
New Revision: 248984

URL: http://llvm.org/viewvc/llvm-project?rev=248984&view=rev
Log:
Test fix

Modified:
cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp

Modified: cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp?rev=248984&r1=248983&r2=248984&view=diff
==
--- cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp Wed Sep 30 23:19:45 
2015
@@ -49,7 +49,7 @@ namespace VirtualNoreturn {
 p->f();
 // CHECK: call {{.*}}void %{{[^#]*$}}
 // CHECK-NOT: unreachable
-// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load 
![[EMPTY_NODE:[0-9]]]
+// CHECK-INVARIANT: load {{.*}} !invariant.load ![[EMPTY_NODE:[0-9]]]
   }
 }
 


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


Re: r248982 - Decorating virtual functions load with invariant.load

2015-10-01 Thread Piotr Padlewski via cfe-commits
I added !invariant.load to virtual functions load, so when optimizer see
case like this

%vtable = load ...
%1 = load (...) %vtable, !invariant.load !0
call %1(...)
%2 = load (...) %vtable, !invariant.load !0
call %2(...)


can merge the 2 virtual functions load into one like this:

%vtable = load ...
%1 = load (...) %vtable, !invariant.load !0
call %1(...)
call %1(...)

This change requires -fstrict-vtable-pointers because without
!invariant.group optimizer will not merge vtable load into one load,
and because of it !invariant.load will be useless.



On Wed, Sep 30, 2015 at 9:28 PM, Chandler Carruth 
wrote:

> On Wed, Sep 30, 2015 at 8:52 PM Piotr Padlewski via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: prazek
>> Date: Wed Sep 30 22:50:41 2015
>> New Revision: 248982
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=248982&view=rev
>> Log:
>> Decorating virtual functions load with invariant.load
>>
>
> This change description really doesn't tell me anything about what this
> change does. Could you try to write more detailed and explanatory change
> logs?
>
> Imagine a reader that has little or no context reading the change log to
> gain the context necessary to read the actual patch and understand what is
> going on with it.
>
>
>>
>> http://reviews.llvm.org/D13279
>>
>> Modified:
>> cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
>> cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
>>
>> Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=248982&r1=248981&r2=248982&view=diff
>>
>> ==
>> --- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Wed Sep 30 22:50:41 2015
>> @@ -1609,7 +1609,16 @@ llvm::Value *ItaniumCXXABI::getVirtualFu
>>uint64_t VTableIndex =
>> CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
>>llvm::Value *VFuncPtr =
>>CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
>> -  return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
>> +  auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr,
>> CGF.getPointerAlign());
>> +
>> +  // It's safe to add "invariant.load" without -fstrict-vtable-pointers,
>> but it
>> +  // would not help in devirtualization.
>> +  if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
>> +  CGM.getCodeGenOpts().StrictVTablePointers)
>> +Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
>> +  llvm::MDNode::get(CGM.getLLVMContext(),
>> +llvm::ArrayRef> *>()));
>> +  return Inst;
>>  }
>>
>>  llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(
>>
>> Modified: cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp?rev=248982&r1=248981&r2=248982&view=diff
>>
>> ==
>> --- cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp (original)
>> +++ cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp Wed Sep 30
>> 22:50:41 2015
>> @@ -1,4 +1,5 @@
>>  // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm
>> -o - | FileCheck %s
>> +// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm
>> -o - -fstrict-vtable-pointers -O1 | FileCheck
>> --check-prefix=CHECK-INVARIANT %s
>>
>>  // PR5021
>>  namespace PR5021 {
>> @@ -42,10 +43,14 @@ namespace VirtualNoreturn {
>>  [[noreturn]] virtual void f();
>>};
>>
>> -  // CHECK: @_ZN15VirtualNoreturn1f
>> +  // CHECK-LABEL: @_ZN15VirtualNoreturn1f
>> +  // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
>>void f(A *p) {
>>  p->f();
>>  // CHECK: call {{.*}}void %{{[^#]*$}}
>>  // CHECK-NOT: unreachable
>> +// CHECK-INVARIANT: load {{.*}} align 8, !invariant.load
>> ![[EMPTY_NODE:[0-9]]]
>>}
>>  }
>> +
>> +// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D13373: Emiting invariant.group.barrier for ctors bugfix

2015-10-01 Thread Piotr Padlewski via cfe-commits
Prazek created this revision.
Prazek added reviewers: rsmith, nlewycky, rjmccall, majnemer.
Prazek added a subscriber: cfe-commits.

Please review asap

http://reviews.llvm.org/D13373

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenCXX/invariant.group-for-vptrs.cpp
  test/CodeGenCXX/strict-vtable-pointers.cpp

Index: test/CodeGenCXX/strict-vtable-pointers.cpp
===
--- test/CodeGenCXX/strict-vtable-pointers.cpp
+++ test/CodeGenCXX/strict-vtable-pointers.cpp
@@ -136,26 +136,43 @@
 
 
 struct DynamicDerived;
+
 // CHECK-CTORS-LABEL: define linkonce_odr void @_ZN14DynamicDerivedC2Ev(
-// CHECK-CTORS: call void @_ZN12DynamicBase1C2Ev(
-// CHECK-CTORS: %[[THIS1:.*]] = bitcast %[[DynamicDerived:.*]]* %[[THIS0:.*]] to i8*
+// CHECK-CTORS: %[[THIS0:.*]] = load %[[DynamicDerived:.*]]*, %[[DynamicDerived]]** {{.*}}
+// CHECK-CTORS: %[[THIS1:.*]] = bitcast %[[DynamicDerived:.*]]* %[[THIS0]] to i8*
 // CHECK-CTORS: %[[THIS2:.*]] = call i8* @llvm.invariant.group.barrier(i8* %[[THIS1:.*]])
-// CHECK-CTORS: %[[THIS3:.*]] = bitcast i8* %[[THIS2:.*]] to %[[DynamicDerived]]*
-// CHECK-CTORS: %[[THIS4:.*]] = bitcast %struct.DynamicDerived* %[[THIS3:.*]] to i32 (...)***
-// CHECK-CTORS: store {{.*}} %[[THIS4:.*]]
+// CHECK-CTORS: %[[THIS3:.*]] = bitcast i8* %[[THIS2]] to %[[DynamicDerived]]*
+// CHECK-CTORS: %[[THIS4:.*]] = bitcast %[[DynamicDerived]]* %2 to %[[DynamicBase:.*]]*
+// CHECK-CTORS: call void @_ZN12DynamicBase1C2Ev(%[[DynamicBase]]* %[[THIS4]])
+
+// CHECK-CTORS: %[[THIS5:.*]] = bitcast %struct.DynamicDerived* %[[THIS0]] to i32 (...)***
+// CHECK-CTORS: store {{.*}} %[[THIS5]]
 // CHECK-CTORS-LABEL: }
 
 struct DynamicDerivedMultiple;
-// CHECK-CTORS-LABEL: define linkonce_odr void @_ZN22DynamicDerivedMultipleC2Ev
-// CHECK-CTORS: call void @_ZN12DynamicBase1C2Ev(
+// CHECK-CTORS-LABEL: define linkonce_odr void @_ZN22DynamicDerivedMultipleC2Ev(
+
+// CHECK-CTORS: %[[THIS0:.*]] = load %[[CLASS:.*]]*, %[[CLASS]]** {{.*}}
+// CHECK-CTORS: %[[THIS1:.*]] = bitcast %[[CLASS:.*]]* %[[THIS0]] to i8*
+// CHECK-CTORS: %[[THIS2:.*]] = call i8* @llvm.invariant.group.barrier(i8* %[[THIS1]])
+// CHECK-CTORS: %[[THIS3:.*]] = bitcast i8* %[[THIS2]] to %[[CLASS]]*
+// CHECK-CTORS: %[[THIS4:.*]] = bitcast %[[CLASS]]* %[[THIS3]] to %[[BASE_CLASS:.*]]*
+// CHECK-CTORS: call void @_ZN12DynamicBase1C2Ev(%[[BASE_CLASS]]* %[[THIS4]])
+
+// CHECK-CTORS: call i8* @llvm.invariant.group.barrier(
+
+// CHECK-CTORS: call void @_ZN12DynamicBase2C2Ev(
 // CHECK-CTORS-NOT: @llvm.invariant.group.barrier
-// CHECK-CTORS-LABEL: call void @_ZN12DynamicBase2C2Ev(
-// CHECK-CTORS: %[[THIS1:.*]] = bitcast %[[CLASS:.*]]* %[[THIS0:.*]] to i8*
-// CHECK-CTORS: %[[THIS2:.*]] = call i8* @llvm.invariant.group.barrier(i8* %[[THIS1:.*]])
-// CHECK-CTORS: %[[THIS3:.*]] = bitcast i8* %[[THIS2:.*]] to %[[CLASS]]*
-// CHECK-CTORS-NOT: invariant.group.barrier
-// CHECK-CTORS: store {{.*}} @_ZTV22DynamicDerivedMultiple, i64 0, i64 2)
-// CHECK-CTORS: store {{.*}} @_ZTV22DynamicDerivedMultiple, i64 0, i64 6)
+
+
+// CHECK-CTORS: %[[THIS10:.*]] = bitcast %struct.DynamicDerivedMultiple* %[[THIS0]] to i32 (...)***
+// CHECK-CTORS: store {{.*}} @_ZTV22DynamicDerivedMultiple, i64 0, i64 2) {{.*}} %[[THIS10]]
+// CHECK-CTORS: %[[THIS11:.*]] = bitcast %struct.DynamicDerivedMultiple* %[[THIS0]] to i8*
+// CHECK-CTORS: %[[THIS_ADD:.*]] = getelementptr inbounds i8, i8* %[[THIS11]], i64 16
+// CHECK-CTORS: %[[THIS12:.*]]  = bitcast i8* %[[THIS_ADD]] to i32 (...)***
+
+
+// CHECK-CTORS: store {{.*}} @_ZTV22DynamicDerivedMultiple, i64 0, i64 6) {{.*}} %[[THIS12]]
 // CHECK-CTORS-LABEL: }
 
 struct DynamicFromStatic;
Index: test/CodeGenCXX/invariant.group-for-vptrs.cpp
===
--- test/CodeGenCXX/invariant.group-for-vptrs.cpp
+++ test/CodeGenCXX/invariant.group-for-vptrs.cpp
@@ -56,9 +56,8 @@
 
 // Checking D::D()
 // CHECK-LABEL: define linkonce_odr void @_ZN1DC2Ev(
-
-// CHECK:  call void @_ZN1AC2Ev(%struct.A*
 // CHECK:  = call i8* @llvm.invariant.group.barrier(i8*
+// CHECK:  call void @_ZN1AC2Ev(%struct.A*
 // CHECK: store {{.*}} !invariant.group ![[D_MD]]
 
 // Checking B::B()
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -1375,13 +1375,15 @@
 assert(BaseCtorContinueBB);
   }
 
-  bool BaseVPtrsInitialized = false;
+  llvm::Value* const OldThis = CXXThisValue;
   // Virtual base initializers first.
   for (; B != E && (*B)->isBaseInitializer() && (*B)->isBaseVirtual(); B++) {
-CXXCtorInitializer *BaseInit = *B;
+
+if (CGM.getCodeGenOpts().StrictVTablePointers &&
+CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+isInitializerOfDynamicClass(*B))
+  CXXThisValue = Builder.CreateInvariantGroupBarrier(LoadCXXThis());
 EmitBaseInitializer(*this, ClassDecl, *B, CtorType);
-BaseVPtrsInitialized |= BaseInitializerUse

Re: [PATCH] D13373: Emiting invariant.group.barrier for ctors bugfix

2015-10-02 Thread Piotr Padlewski via cfe-commits
Prazek updated the summary for this revision.
Prazek updated this revision to Diff 36382.
Prazek marked an inline comment as done.

http://reviews.llvm.org/D13373

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenCXX/invariant.group-for-vptrs.cpp
  test/CodeGenCXX/strict-vtable-pointers.cpp

Index: test/CodeGenCXX/strict-vtable-pointers.cpp
===
--- test/CodeGenCXX/strict-vtable-pointers.cpp
+++ test/CodeGenCXX/strict-vtable-pointers.cpp
@@ -136,26 +136,43 @@
 
 
 struct DynamicDerived;
+
 // CHECK-CTORS-LABEL: define linkonce_odr void @_ZN14DynamicDerivedC2Ev(
-// CHECK-CTORS: call void @_ZN12DynamicBase1C2Ev(
-// CHECK-CTORS: %[[THIS1:.*]] = bitcast %[[DynamicDerived:.*]]* %[[THIS0:.*]] to i8*
+// CHECK-CTORS: %[[THIS0:.*]] = load %[[DynamicDerived:.*]]*, %[[DynamicDerived]]** {{.*}}
+// CHECK-CTORS: %[[THIS1:.*]] = bitcast %[[DynamicDerived:.*]]* %[[THIS0]] to i8*
 // CHECK-CTORS: %[[THIS2:.*]] = call i8* @llvm.invariant.group.barrier(i8* %[[THIS1:.*]])
-// CHECK-CTORS: %[[THIS3:.*]] = bitcast i8* %[[THIS2:.*]] to %[[DynamicDerived]]*
-// CHECK-CTORS: %[[THIS4:.*]] = bitcast %struct.DynamicDerived* %[[THIS3:.*]] to i32 (...)***
-// CHECK-CTORS: store {{.*}} %[[THIS4:.*]]
+// CHECK-CTORS: %[[THIS3:.*]] = bitcast i8* %[[THIS2]] to %[[DynamicDerived]]*
+// CHECK-CTORS: %[[THIS4:.*]] = bitcast %[[DynamicDerived]]* %2 to %[[DynamicBase:.*]]*
+// CHECK-CTORS: call void @_ZN12DynamicBase1C2Ev(%[[DynamicBase]]* %[[THIS4]])
+
+// CHECK-CTORS: %[[THIS5:.*]] = bitcast %struct.DynamicDerived* %[[THIS0]] to i32 (...)***
+// CHECK-CTORS: store {{.*}} %[[THIS5]]
 // CHECK-CTORS-LABEL: }
 
 struct DynamicDerivedMultiple;
-// CHECK-CTORS-LABEL: define linkonce_odr void @_ZN22DynamicDerivedMultipleC2Ev
-// CHECK-CTORS: call void @_ZN12DynamicBase1C2Ev(
+// CHECK-CTORS-LABEL: define linkonce_odr void @_ZN22DynamicDerivedMultipleC2Ev(
+
+// CHECK-CTORS: %[[THIS0:.*]] = load %[[CLASS:.*]]*, %[[CLASS]]** {{.*}}
+// CHECK-CTORS: %[[THIS1:.*]] = bitcast %[[CLASS:.*]]* %[[THIS0]] to i8*
+// CHECK-CTORS: %[[THIS2:.*]] = call i8* @llvm.invariant.group.barrier(i8* %[[THIS1]])
+// CHECK-CTORS: %[[THIS3:.*]] = bitcast i8* %[[THIS2]] to %[[CLASS]]*
+// CHECK-CTORS: %[[THIS4:.*]] = bitcast %[[CLASS]]* %[[THIS3]] to %[[BASE_CLASS:.*]]*
+// CHECK-CTORS: call void @_ZN12DynamicBase1C2Ev(%[[BASE_CLASS]]* %[[THIS4]])
+
+// CHECK-CTORS: call i8* @llvm.invariant.group.barrier(
+
+// CHECK-CTORS: call void @_ZN12DynamicBase2C2Ev(
 // CHECK-CTORS-NOT: @llvm.invariant.group.barrier
-// CHECK-CTORS-LABEL: call void @_ZN12DynamicBase2C2Ev(
-// CHECK-CTORS: %[[THIS1:.*]] = bitcast %[[CLASS:.*]]* %[[THIS0:.*]] to i8*
-// CHECK-CTORS: %[[THIS2:.*]] = call i8* @llvm.invariant.group.barrier(i8* %[[THIS1:.*]])
-// CHECK-CTORS: %[[THIS3:.*]] = bitcast i8* %[[THIS2:.*]] to %[[CLASS]]*
-// CHECK-CTORS-NOT: invariant.group.barrier
-// CHECK-CTORS: store {{.*}} @_ZTV22DynamicDerivedMultiple, i64 0, i64 2)
-// CHECK-CTORS: store {{.*}} @_ZTV22DynamicDerivedMultiple, i64 0, i64 6)
+
+
+// CHECK-CTORS: %[[THIS10:.*]] = bitcast %struct.DynamicDerivedMultiple* %[[THIS0]] to i32 (...)***
+// CHECK-CTORS: store {{.*}} @_ZTV22DynamicDerivedMultiple, i64 0, i64 2) {{.*}} %[[THIS10]]
+// CHECK-CTORS: %[[THIS11:.*]] = bitcast %struct.DynamicDerivedMultiple* %[[THIS0]] to i8*
+// CHECK-CTORS: %[[THIS_ADD:.*]] = getelementptr inbounds i8, i8* %[[THIS11]], i64 16
+// CHECK-CTORS: %[[THIS12:.*]]  = bitcast i8* %[[THIS_ADD]] to i32 (...)***
+
+
+// CHECK-CTORS: store {{.*}} @_ZTV22DynamicDerivedMultiple, i64 0, i64 6) {{.*}} %[[THIS12]]
 // CHECK-CTORS-LABEL: }
 
 struct DynamicFromStatic;
Index: test/CodeGenCXX/invariant.group-for-vptrs.cpp
===
--- test/CodeGenCXX/invariant.group-for-vptrs.cpp
+++ test/CodeGenCXX/invariant.group-for-vptrs.cpp
@@ -56,9 +56,8 @@
 
 // Checking D::D()
 // CHECK-LABEL: define linkonce_odr void @_ZN1DC2Ev(
-
-// CHECK:  call void @_ZN1AC2Ev(%struct.A*
 // CHECK:  = call i8* @llvm.invariant.group.barrier(i8*
+// CHECK:  call void @_ZN1AC2Ev(%struct.A*
 // CHECK: store {{.*}} !invariant.group ![[D_MD]]
 
 // Checking B::B()
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -1375,13 +1375,14 @@
 assert(BaseCtorContinueBB);
   }
 
-  bool BaseVPtrsInitialized = false;
+  llvm::Value *const OldThis = CXXThisValue;
   // Virtual base initializers first.
   for (; B != E && (*B)->isBaseInitializer() && (*B)->isBaseVirtual(); B++) {
-CXXCtorInitializer *BaseInit = *B;
+if (CGM.getCodeGenOpts().StrictVTablePointers &&
+CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+isInitializerOfDynamicClass(*B))
+  CXXThisValue = Builder.CreateInvariantGroupBarrier(LoadCXXThis());
 EmitBaseInitializer(*this, ClassDecl, *B, CtorType);
-BaseVPtrsInitialized |= BaseInitializerUsesThis(getContext(),
-  

r249197 - Emiting invariant.group.barrier for ctors bugfix

2015-10-02 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Fri Oct  2 17:12:40 2015
New Revision: 249197

URL: http://llvm.org/viewvc/llvm-project?rev=249197&view=rev
Log:
Emiting invariant.group.barrier for ctors bugfix

Ensure that the vptr store in the most-derived constructor is not behind
an invariant group barrier. Previously, the base-most vptr store would
be the one behind no barrier, and that could result in the creator of
the object thinking it had the base-most vtable.
This bug caused clang call pure virtual functions when called from
constructor body.

http://reviews.llvm.org/D13373

Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=249197&r1=249196&r2=249197&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Fri Oct  2 17:12:40 2015
@@ -1375,13 +1375,14 @@ void CodeGenFunction::EmitCtorPrologue(c
 assert(BaseCtorContinueBB);
   }
 
-  bool BaseVPtrsInitialized = false;
+  llvm::Value *const OldThis = CXXThisValue;
   // Virtual base initializers first.
   for (; B != E && (*B)->isBaseInitializer() && (*B)->isBaseVirtual(); B++) {
-CXXCtorInitializer *BaseInit = *B;
+if (CGM.getCodeGenOpts().StrictVTablePointers &&
+CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+isInitializerOfDynamicClass(*B))
+  CXXThisValue = Builder.CreateInvariantGroupBarrier(LoadCXXThis());
 EmitBaseInitializer(*this, ClassDecl, *B, CtorType);
-BaseVPtrsInitialized |= BaseInitializerUsesThis(getContext(),
-BaseInit->getInit());
   }
 
   if (BaseCtorContinueBB) {
@@ -1393,15 +1394,15 @@ void CodeGenFunction::EmitCtorPrologue(c
   // Then, non-virtual base initializers.
   for (; B != E && (*B)->isBaseInitializer(); B++) {
 assert(!(*B)->isBaseVirtual());
+
+if (CGM.getCodeGenOpts().StrictVTablePointers &&
+CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+isInitializerOfDynamicClass(*B))
+  CXXThisValue = Builder.CreateInvariantGroupBarrier(LoadCXXThis());
 EmitBaseInitializer(*this, ClassDecl, *B, CtorType);
-BaseVPtrsInitialized |= isInitializerOfDynamicClass(*B);
   }
 
-  // Pointer to this requires to be passed through invariant.group.barrier
-  // only if we've initialized any base vptrs.
-  if (CGM.getCodeGenOpts().StrictVTablePointers &&
-  CGM.getCodeGenOpts().OptimizationLevel > 0 && BaseVPtrsInitialized)
-CXXThisValue = Builder.CreateInvariantGroupBarrier(LoadCXXThis());
+  CXXThisValue = OldThis;
 
   InitializeVTablePointers(ClassDecl);
 

Modified: cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp?rev=249197&r1=249196&r2=249197&view=diff
==
--- cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp Fri Oct  2 17:12:40 
2015
@@ -56,9 +56,8 @@ void testInternallyVisible(bool p) {
 
 // Checking D::D()
 // CHECK-LABEL: define linkonce_odr void @_ZN1DC2Ev(
-
-// CHECK:  call void @_ZN1AC2Ev(%struct.A*
 // CHECK:  = call i8* @llvm.invariant.group.barrier(i8*
+// CHECK:  call void @_ZN1AC2Ev(%struct.A*
 // CHECK: store {{.*}} !invariant.group ![[D_MD]]
 
 // Checking B::B()

Modified: cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp?rev=249197&r1=249196&r2=249197&view=diff
==
--- cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp Fri Oct  2 17:12:40 
2015
@@ -136,26 +136,43 @@ struct DynamicBase1;
 
 
 struct DynamicDerived;
+
 // CHECK-CTORS-LABEL: define linkonce_odr void @_ZN14DynamicDerivedC2Ev(
-// CHECK-CTORS: call void @_ZN12DynamicBase1C2Ev(
-// CHECK-CTORS: %[[THIS1:.*]] = bitcast %[[DynamicDerived:.*]]* %[[THIS0:.*]] 
to i8*
+// CHECK-CTORS: %[[THIS0:.*]] = load %[[DynamicDerived:.*]]*, 
%[[DynamicDerived]]** {{.*}}
+// CHECK-CTORS: %[[THIS1:.*]] = bitcast %[[DynamicDerived:.*]]* %[[THIS0]] to 
i8*
 // CHECK-CTORS: %[[THIS2:.*]] = call i8* @llvm.invariant.group.barrier(i8* 
%[[THIS1:.*]])
-// CHECK-CTORS: %[[THIS3:.*]] = bitcast i8* %[[THIS2:.*]] to 
%[[DynamicDerived]]*
-// CHECK-CTORS: %[[THIS4:.*]] = bitcast %struct.DynamicDerived* %[[THIS3:.*]] 
to i32 (...)***
-// CHECK-CTORS: store {{.*}} %[[THIS4:.*]]
+// CHECK-CTORS: %[[THIS3:.*]] = bitcast i8* %[[THIS2]] to %[[DynamicDerived]]*
+// CHECK-CTORS: %[[THIS4:.*]] = bitcast %[[DynamicDerived]]* %2 to 
%[[DynamicB

  1   2   3   4   >