r331137 - Fix printing of reference-to-reference types.

2018-04-28 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Sat Apr 28 22:33:38 2018
New Revision: 331137

URL: http://llvm.org/viewvc/llvm-project?rev=331137&view=rev
Log:
Fix printing of reference-to-reference types.

Previously we would sometimes print these as 'T &&&' or even 'T '.

Modified:
cfe/trunk/lib/AST/TypePrinter.cpp
cfe/trunk/test/SemaCXX/references.cpp

Modified: cfe/trunk/lib/AST/TypePrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=331137&r1=331136&r2=331137&view=diff
==
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)
+++ cfe/trunk/lib/AST/TypePrinter.cpp Sat Apr 28 22:33:38 2018
@@ -385,14 +385,23 @@ void TypePrinter::printBlockPointerAfter
   printAfter(T->getPointeeType(), OS);
 }
 
+// When printing a reference, the referenced type might also be a reference.
+// If so, we want to skip that before printing the inner type.
+static QualType skipTopLevelReferences(QualType T) {
+  if (auto *Ref = T->getAs())
+return skipTopLevelReferences(Ref->getPointeeTypeAsWritten());
+  return T;
+}
+
 void TypePrinter::printLValueReferenceBefore(const LValueReferenceType *T,
  raw_ostream &OS) {
   IncludeStrongLifetimeRAII Strong(Policy);
   SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
-  printBefore(T->getPointeeTypeAsWritten(), OS);
+  QualType Inner = skipTopLevelReferences(T->getPointeeTypeAsWritten());
+  printBefore(Inner, OS);
   // Handle things like 'int (&A)[4];' correctly.
   // FIXME: this should include vectors, but vectors use attributes I guess.
-  if (isa(T->getPointeeTypeAsWritten()))
+  if (isa(Inner))
 OS << '(';
   OS << '&';
 }
@@ -401,21 +410,23 @@ void TypePrinter::printLValueReferenceAf
 raw_ostream &OS) {
   IncludeStrongLifetimeRAII Strong(Policy);
   SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
+  QualType Inner = skipTopLevelReferences(T->getPointeeTypeAsWritten());
   // Handle things like 'int (&A)[4];' correctly.
   // FIXME: this should include vectors, but vectors use attributes I guess.
-  if (isa(T->getPointeeTypeAsWritten()))
+  if (isa(Inner))
 OS << ')';
-  printAfter(T->getPointeeTypeAsWritten(), OS);
+  printAfter(Inner, OS);
 }
 
 void TypePrinter::printRValueReferenceBefore(const RValueReferenceType *T,
  raw_ostream &OS) {
   IncludeStrongLifetimeRAII Strong(Policy);
   SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
-  printBefore(T->getPointeeTypeAsWritten(), OS);
+  QualType Inner = skipTopLevelReferences(T->getPointeeTypeAsWritten());
+  printBefore(Inner, OS);
   // Handle things like 'int (&&A)[4];' correctly.
   // FIXME: this should include vectors, but vectors use attributes I guess.
-  if (isa(T->getPointeeTypeAsWritten()))
+  if (isa(Inner))
 OS << '(';
   OS << "&&";
 }
@@ -424,11 +435,12 @@ void TypePrinter::printRValueReferenceAf
 raw_ostream &OS) {
   IncludeStrongLifetimeRAII Strong(Policy);
   SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
+  QualType Inner = skipTopLevelReferences(T->getPointeeTypeAsWritten());
   // Handle things like 'int (&&A)[4];' correctly.
   // FIXME: this should include vectors, but vectors use attributes I guess.
-  if (isa(T->getPointeeTypeAsWritten()))
+  if (isa(Inner))
 OS << ')';
-  printAfter(T->getPointeeTypeAsWritten(), OS);
+  printAfter(Inner, OS);
 }
 
 void TypePrinter::printMemberPointerBefore(const MemberPointerType *T, 

Modified: cfe/trunk/test/SemaCXX/references.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/references.cpp?rev=331137&r1=331136&r2=331137&view=diff
==
--- cfe/trunk/test/SemaCXX/references.cpp (original)
+++ cfe/trunk/test/SemaCXX/references.cpp Sat Apr 28 22:33:38 2018
@@ -154,3 +154,31 @@ namespace ExplicitRefInit {
   struct A { explicit A(int); };
   const A &a(0); // expected-error {{reference to type 'const 
ExplicitRefInit::A' could not bind to an rvalue of type 'int'}}
 }
+
+namespace RefCollapseTypePrinting {
+  template void add_lref() {
+using X = int(T); // expected-note 4{{previous}}
+using X = const volatile T&;
+// expected-error@-1 {{'int &' vs 'int (int &)'}}
+// expected-error@-2 {{'int &' vs 'int (int &&)'}}
+// expected-error@-3 {{'const int &' vs 'int (const int &)'}}
+// expected-error@-4 {{'const int &' vs 'int (const int &&)'}}
+  }
+  template void add_lref(); // expected-note {{instantiation of}}
+  template void add_lref(); // expected-note {{instantiation of}}
+  template void add_lref(); // expected-note {{instantiation of}}
+  template void add_lref(); // expected-note {{instantiation of}}
+
+  template void add_rref() {
+using X = int(T); // expected-note 4{{previous}}
+using X = const volatile T&&;
+// ex

[PATCH] D46218: PR37275 packed attribute should not apply to base classes

2018-04-28 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D46218#1081933, @rjmccall wrote:

> Have you checked whether we do the right thing with `#pragma pack` on MSVC?


Great question, I hadn't. Both MSVC and GCC treat `#pragma pack` as applying to 
base classes, which is what we do with/without this patch. I'll add some tests 
to cover that.


Repository:
  rC Clang

https://reviews.llvm.org/D46218



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


[PATCH] D46218: PR37275 packed attribute should not apply to base classes

2018-04-28 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331136: PR37275 packed attribute should not apply to base 
classes (authored by rsmith, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46218?vs=144415&id=144469#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46218

Files:
  cfe/trunk/docs/ReleaseNotes.rst
  cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
  cfe/trunk/test/CodeGenCXX/alignment.cpp
  cfe/trunk/test/SemaCXX/class-layout.cpp

Index: cfe/trunk/docs/ReleaseNotes.rst
===
--- cfe/trunk/docs/ReleaseNotes.rst
+++ cfe/trunk/docs/ReleaseNotes.rst
@@ -78,6 +78,12 @@
   standard-layout if all base classes and the first data member (or bit-field)
   can be laid out at offset zero.
 
+- Clang's handling of the GCC ``packed`` class attribute in C++ has been fixed
+  to apply only to non-static data members and not to base classes. This fixes
+  an ABI difference between Clang and GCC, but creates an ABI difference between
+  Clang 7 and earlier versions. The old behavior can be restored by setting
+  ``-fclang-abi-compat`` to ``6`` or earlier.
+
 - ...
 
 New Compiler Flags
Index: cfe/trunk/test/CodeGenCXX/alignment.cpp
===
--- cfe/trunk/test/CodeGenCXX/alignment.cpp
+++ cfe/trunk/test/CodeGenCXX/alignment.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-apple-darwin10 | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-apple-darwin10 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOCOMPAT
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-apple-darwin10 -fclang-abi-compat=6.0 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-V6COMPAT
 
 extern int int_source();
 extern void int_sink(int x);
@@ -54,19 +55,22 @@
 // CHECK: [[B_P:%.*]] = bitcast i8* [[T1]] to [[B]]*
 // CHECK: [[FIELD_P:%.*]] = bitcast [[B]]* [[B_P]] to i8*
 // CHECK: [[TRUNC:%.*]] = trunc i32 [[CALL]] to i8
-// CHECK: [[OLD_VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 2
+// CHECK-V6COMPAT: [[OLD_VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 2
+// CHECK-NOCOMPAT: [[OLD_VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 4
 // CHECK: [[T0:%.*]] = and i8 [[TRUNC]], 3
 // CHECK: [[T1:%.*]] = and i8 [[OLD_VALUE]], -4
 // CHECK: [[T2:%.*]] = or i8 [[T1]], [[T0]]
-// CHECK: store i8 [[T2]], i8* [[FIELD_P]], align 2
+// CHECK-V6COMPAT: store i8 [[T2]], i8* [[FIELD_P]], align 2
+// CHECK-NOCOMPAT: store i8 [[T2]], i8* [[FIELD_P]], align 4
 c.onebit = int_source();
 
 // CHECK: [[C_P:%.*]] = load [[C]]*, [[C]]**
 // CHECK: [[T0:%.*]] = bitcast [[C]]* [[C_P]] to i8*
 // CHECK: [[T1:%.*]] = getelementptr inbounds i8, i8* [[T0]], i64 8
 // CHECK: [[B_P:%.*]] = bitcast i8* [[T1]] to [[B]]*
 // CHECK: [[FIELD_P:%.*]] = bitcast [[B]]* [[B_P]] to i8*
-// CHECK: [[VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 2
+// CHECK-V6COMPAT: [[VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 2
+// CHECK-NOCOMPAT: [[VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 4
 // CHECK: [[T0:%.*]] = shl i8 [[VALUE]], 6
 // CHECK: [[T1:%.*]] = ashr i8 [[T0]], 6
 // CHECK: [[T2:%.*]] = sext i8 [[T1]] to i32
@@ -83,19 +87,22 @@
 // CHECK: [[B_P:%.*]] = bitcast i8* [[T1]] to [[B]]*
 // CHECK: [[FIELD_P:%.*]] = bitcast [[B]]* [[B_P]] to i8*
 // CHECK: [[TRUNC:%.*]] = trunc i32 [[CALL]] to i8
-// CHECK: [[OLD_VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 2
+// CHECK-V6COMPAT: [[OLD_VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 2
+// CHECK-NOCOMPAT: [[OLD_VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 4
 // CHECK: [[T0:%.*]] = and i8 [[TRUNC]], 3
 // CHECK: [[T1:%.*]] = and i8 [[OLD_VALUE]], -4
 // CHECK: [[T2:%.*]] = or i8 [[T1]], [[T0]]
-// CHECK: store i8 [[T2]], i8* [[FIELD_P]], align 2
+// CHECK-V6COMPAT: store i8 [[T2]], i8* [[FIELD_P]], align 2
+// CHECK-NOCOMPAT: store i8 [[T2]], i8* [[FIELD_P]], align 4
 c->onebit = int_source();
 
 // CHECK: [[C_P:%.*]] = load [[C:%.*]]*, [[C]]**
 // CHECK: [[T0:%.*]] = bitcast [[C]]* [[C_P]] to i8*
 // CHECK: [[T1:%.*]] = getelementptr inbounds i8, i8* [[T0]], i64 8
 // CHECK: [[B_P:%.*]] = bitcast i8* [[T1]] to [[B:%.*]]*
 // CHECK: [[FIELD_P:%.*]] = bitcast [[B]]* [[B_P]] to i8*
-// CHECK: [[VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 2
+// CHECK-V6COMPAT: [[VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 2
+// CHECK-NOCOMPAT: [[VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 4
 // CHECK: [[T0:%.*]] = shl i8 [[VALUE]], 6
 // CHECK: [[T1:%.*]] = ashr i8 [[T0]], 6
 // CHECK: [[T2:%.*]] = sext i8 [[T1]] to i32
@@ -107,27 +114,31 @@
   // in an alignment-2 variable.
   // CHECK-LABEL: @_ZN5test01dEv
   void d() {
-// CHECK: [[C_P:%.*]] = alloca [[C:%.*]], align 2
+// CHEC

r331136 - PR37275 packed attribute should not apply to base classes

2018-04-28 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Sat Apr 28 21:55:46 2018
New Revision: 331136

URL: http://llvm.org/viewvc/llvm-project?rev=331136&view=rev
Log:
PR37275 packed attribute should not apply to base classes

Clang incorrectly applied the packed attribute to base classes. Per GCC's
documentation and as can be observed from its behavior, packed only applies to
members, not base classes.

This change is conditioned behind -fclang-abi-compat so that an ABI break can
be avoided by users if desired.

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

Modified:
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/test/CodeGenCXX/alignment.cpp
cfe/trunk/test/SemaCXX/class-layout.cpp

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=331136&r1=331135&r2=331136&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Sat Apr 28 21:55:46 2018
@@ -78,6 +78,12 @@ Non-comprehensive list of changes in thi
   standard-layout if all base classes and the first data member (or bit-field)
   can be laid out at offset zero.
 
+- Clang's handling of the GCC ``packed`` class attribute in C++ has been fixed
+  to apply only to non-static data members and not to base classes. This fixes
+  an ABI difference between Clang and GCC, but creates an ABI difference 
between
+  Clang 7 and earlier versions. The old behavior can be restored by setting
+  ``-fclang-abi-compat`` to ``6`` or earlier.
+
 - ...
 
 New Compiler Flags

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=331136&r1=331135&r2=331136&view=diff
==
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Sat Apr 28 21:55:46 2018
@@ -967,7 +967,7 @@ void ItaniumRecordLayoutBuilder::Compute
 
 void ItaniumRecordLayoutBuilder::EnsureVTablePointerAlignment(
 CharUnits UnpackedBaseAlign) {
-  CharUnits BaseAlign = (Packed) ? CharUnits::One() : UnpackedBaseAlign;
+  CharUnits BaseAlign = Packed ? CharUnits::One() : UnpackedBaseAlign;
 
   // The maximum field alignment overrides base align.
   if (!MaxFieldAlignment.isZero()) {
@@ -1175,9 +1175,14 @@ ItaniumRecordLayoutBuilder::LayoutBase(c
   HasExternalLayout = External.getExternalVBaseOffset(Base->Class, Offset);
   }
   
+  // Clang <= 6 incorrectly applied the 'packed' attribute to base classes.
+  // Per GCC's documentation, it only applies to non-static data members.
   CharUnits UnpackedBaseAlign = Layout.getNonVirtualAlignment();
-  CharUnits BaseAlign = (Packed) ? CharUnits::One() : UnpackedBaseAlign;
- 
+  CharUnits BaseAlign = (Packed && Context.getLangOpts().getClangABICompat() <=
+   LangOptions::ClangABI::Ver6)
+? CharUnits::One()
+: UnpackedBaseAlign;
+
   // If we have an empty base class, try to place it at offset 0.
   if (Base->Class->isEmpty() &&
   (!HasExternalLayout || Offset == CharUnits::Zero()) &&

Modified: cfe/trunk/test/CodeGenCXX/alignment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/alignment.cpp?rev=331136&r1=331135&r2=331136&view=diff
==
--- cfe/trunk/test/CodeGenCXX/alignment.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/alignment.cpp Sat Apr 28 21:55:46 2018
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-apple-darwin10 | 
FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-apple-darwin10 | 
FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOCOMPAT
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-apple-darwin10 
-fclang-abi-compat=6.0 | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-V6COMPAT
 
 extern int int_source();
 extern void int_sink(int x);
@@ -54,11 +55,13 @@ namespace test0 {
 // CHECK: [[B_P:%.*]] = bitcast i8* [[T1]] to [[B]]*
 // CHECK: [[FIELD_P:%.*]] = bitcast [[B]]* [[B_P]] to i8*
 // CHECK: [[TRUNC:%.*]] = trunc i32 [[CALL]] to i8
-// CHECK: [[OLD_VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 2
+// CHECK-V6COMPAT: [[OLD_VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 2
+// CHECK-NOCOMPAT: [[OLD_VALUE:%.*]] = load i8, i8* [[FIELD_P]], align 4
 // CHECK: [[T0:%.*]] = and i8 [[TRUNC]], 3
 // CHECK: [[T1:%.*]] = and i8 [[OLD_VALUE]], -4
 // CHECK: [[T2:%.*]] = or i8 [[T1]], [[T0]]
-// CHECK: store i8 [[T2]], i8* [[FIELD_P]], align 2
+// CHECK-V6COMPAT: store i8 [[T2]], i8* [[FIELD_P]], align 2
+// CHECK-NOCOMPAT: store i8 [[T2]], i8* [[FIELD_P]], align 4
 c.onebit = int_source();
 
 // CHECK: [[C_P:%.*]] = load [[C]]*, [[C]]**
@@ -66,7 +69,8

[PATCH] D46230: For x86_64, gcc 7.2 under Amazon Linux AMI sets its paths to x86_64-amazon-linux

2018-04-28 Thread Jiading Gai via Phabricator via cfe-commits
gaijiading created this revision.
gaijiading added a reviewer: rsmith.
gaijiading added a project: clang.
Herald added a subscriber: cfe-commits.

For x86_64, gcc 7.2 under Amazon Linux AMI sets its paths to x86_64-amazon-linux

gcc 7.2 under Amazon Linux AMI sets its paths to x86_64-amazon-linux. Adding 
this triple to the list of search.

The patch fixes the following bug in bugzilla:

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


Repository:
  rC Clang

https://reviews.llvm.org/D46230

Files:
  lib/Driver/ToolChains/Gnu.cpp


Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -1839,7 +1839,8 @@
   "x86_64-pc-linux-gnu","x86_64-redhat-linux6E",
   "x86_64-redhat-linux","x86_64-suse-linux",
   "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
-  "x86_64-slackware-linux", "x86_64-unknown-linux"};
+  "x86_64-slackware-linux", "x86_64-unknown-linux",
+  "x86_64-amazon-linux"};
   static const char *const X32LibDirs[] = {"/libx32"};
   static const char *const X86LibDirs[] = {"/lib32", "/lib"};
   static const char *const X86Triples[] = {


Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -1839,7 +1839,8 @@
   "x86_64-pc-linux-gnu","x86_64-redhat-linux6E",
   "x86_64-redhat-linux","x86_64-suse-linux",
   "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
-  "x86_64-slackware-linux", "x86_64-unknown-linux"};
+  "x86_64-slackware-linux", "x86_64-unknown-linux",
+  "x86_64-amazon-linux"};
   static const char *const X32LibDirs[] = {"/libx32"};
   static const char *const X86LibDirs[] = {"/lib32", "/lib"};
   static const char *const X86Triples[] = {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r331124 - Remove unused includes of clang/Config/config.h

2018-04-28 Thread Nico Weber via cfe-commits
Author: nico
Date: Sat Apr 28 16:48:36 2018
New Revision: 331124

URL: http://llvm.org/viewvc/llvm-project?rev=331124&view=rev
Log:
Remove unused includes of clang/Config/config.h

Found by opening config.h.cmake in vim, finding all defined macros with

  /define\(01\)\? \zs[A-Za-z0-9_]*
  :%s//\=setreg('A', submatch(0), 'V')/gn
  :put A

and then joining them all with |, and passing that to

  git grep -E that_pattern 'clang/*.h' 'clang/*.cpp' 'clang/*.c'

and diffing that output with the result of

  git grep Config/config.h 'clang/*.h' 'clang/*.cpp' 'clang/*.c'

No intended behavior change.

Modified:
cfe/trunk/lib/Driver/ToolChains/Ananas.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Driver/ToolChains/CloudABI.cpp
cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp
cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Ananas.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Ananas.cpp?rev=331124&r1=331123&r2=331124&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Ananas.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Ananas.cpp Sat Apr 28 16:48:36 2018
@@ -10,7 +10,6 @@
 #include "Ananas.h"
 #include "InputInfo.h"
 #include "CommonArgs.h"
-#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/Options.h"

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=331124&r1=331123&r2=331124&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Sat Apr 28 16:48:36 2018
@@ -25,7 +25,6 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/ObjCRuntime.h"
 #include "clang/Basic/Version.h"
-#include "clang/Config/config.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"

Modified: cfe/trunk/lib/Driver/ToolChains/CloudABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CloudABI.cpp?rev=331124&r1=331123&r2=331124&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/CloudABI.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/CloudABI.cpp Sat Apr 28 16:48:36 2018
@@ -10,7 +10,6 @@
 #include "CloudABI.h"
 #include "InputInfo.h"
 #include "CommonArgs.h"
-#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/Options.h"

Modified: cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp?rev=331124&r1=331123&r2=331124&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp Sat Apr 28 16:48:36 2018
@@ -11,7 +11,6 @@
 #include "InputInfo.h"
 #include "CommonArgs.h"
 #include "clang/Basic/VirtualFileSystem.h"
-#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"

Modified: cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp?rev=331124&r1=331123&r2=331124&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp Sat Apr 28 16:48:36 2018
@@ -10,7 +10,6 @@
 #include "MipsLinux.h"
 #include "Arch/Mips.h"
 #include "CommonArgs.h"
-#include "clang/Config/config.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"


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


Re: r331077 - Revert r329698 (and r329702).

2018-04-28 Thread Nico Weber via cfe-commits
Looks like this helped :-/

http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/10262

On Fri, Apr 27, 2018, 4:33 PM Nico Weber via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: nico
> Date: Fri Apr 27 13:29:57 2018
> New Revision: 331077
>
> URL: http://llvm.org/viewvc/llvm-project?rev=331077&view=rev
> Log:
> Revert r329698 (and r329702).
>
> Speculative. ClangMoveTests started failing on
> http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/9958
> after this change. I can't reproduce on my machine, let's see
> if it was due to this change.
>
> Modified:
> cfe/trunk/lib/Basic/FileManager.cpp
> cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
>
> Modified: cfe/trunk/lib/Basic/FileManager.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=331077&r1=331076&r2=331077&view=diff
>
> ==
> --- cfe/trunk/lib/Basic/FileManager.cpp (original)
> +++ cfe/trunk/lib/Basic/FileManager.cpp Fri Apr 27 13:29:57 2018
> @@ -534,9 +534,23 @@ StringRef FileManager::getCanonicalName(
>
>StringRef CanonicalName(Dir->getName());
>
> -  SmallString<256> CanonicalNameBuf;
> -  if (!llvm::sys::fs::real_path(Dir->getName(), CanonicalNameBuf))
> +#ifdef LLVM_ON_UNIX
> +  char CanonicalNameBuf[PATH_MAX];
> +  if (realpath(Dir->getName().str().c_str(), CanonicalNameBuf))
>  CanonicalName =
> StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
> +#else
> +  SmallString<256> CanonicalNameBuf(CanonicalName);
> +  llvm::sys::fs::make_absolute(CanonicalNameBuf);
> +  llvm::sys::path::native(CanonicalNameBuf);
> +  // We've run into needing to remove '..' here in the wild though, so
> +  // remove it.
> +  // On Windows, symlinks are significantly less prevalent, so removing
> +  // '..' is pretty safe.
> +  // Ideally we'd have an equivalent of `realpath` and could implement
> +  // sys::fs::canonical across all the platforms.
> +  llvm::sys::path::remove_dots(CanonicalNameBuf, /* remove_dot_dot */
> true);
> +  CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
> +#endif
>
>CanonicalDirNames.insert(std::make_pair(Dir, CanonicalName));
>return CanonicalName;
>
> Modified: cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp?rev=331077&r1=331076&r2=331077&view=diff
>
> ==
> --- cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp (original)
> +++ cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp Fri Apr 27
> 13:29:57 2018
> @@ -97,6 +97,24 @@ struct ModuleDependencyMMCallbacks : pub
>
>  }
>
> +// TODO: move this to Support/Path.h and check for HAVE_REALPATH?
> +static bool real_path(StringRef SrcPath, SmallVectorImpl &RealPath)
> {
> +#ifdef LLVM_ON_UNIX
> +  char CanonicalPath[PATH_MAX];
> +
> +  // TODO: emit a warning in case this fails...?
> +  if (!realpath(SrcPath.str().c_str(), CanonicalPath))
> +return false;
> +
> +  SmallString<256> RPath(CanonicalPath);
> +  RealPath.swap(RPath);
> +  return true;
> +#else
> +  // FIXME: Add support for systems without realpath.
> +  return false;
> +#endif
> +}
> +
>  void ModuleDependencyCollector::attachToASTReader(ASTReader &R) {
>R.addListener(llvm::make_unique(*this));
>  }
> @@ -111,7 +129,7 @@ void ModuleDependencyCollector::attachTo
>  static bool isCaseSensitivePath(StringRef Path) {
>SmallString<256> TmpDest = Path, UpperDest, RealDest;
>// Remove component traversals, links, etc.
> -  if (llvm::sys::fs::real_path(Path, TmpDest))
> +  if (!real_path(Path, TmpDest))
>  return true; // Current default value in vfs.yaml
>Path = TmpDest;
>
> @@ -121,7 +139,7 @@ static bool isCaseSensitivePath(StringRe
>// already expects when sensitivity isn't setup.
>for (auto &C : Path)
>  UpperDest.push_back(toUppercase(C));
> -  if (!llvm::sys::fs::real_path(UpperDest, RealDest) &&
> Path.equals(RealDest))
> +  if (real_path(UpperDest, RealDest) && Path.equals(RealDest))
>  return false;
>return true;
>  }
> @@ -171,7 +189,7 @@ bool ModuleDependencyCollector::getRealP
>// Computing the real path is expensive, cache the search through the
>// parent path directory.
>if (DirWithSymLink == SymLinkMap.end()) {
> -if (llvm::sys::fs::real_path(Dir, RealPath))
> +if (!real_path(Dir, RealPath))
>return false;
>  SymLinkMap[Dir] = RealPath.str();
>} else {
>
>
> ___
> 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] D44609: [Clang-Format] New option BreakBeforeLambdaBody to manage lambda line break inside function parameter call

2018-04-28 Thread Francois JEAN via Phabricator via cfe-commits
Wawha updated this revision to Diff 144460.
Wawha added a reviewer: klimek.
Wawha added a comment.

Hi klimek,
I upload a new patch with the modifications you proposed.
The option is now enable by default in Allman style. So I move the option to 
the BraceWrappingFlags struct, which make more sense.

I also make the second modification you propose to avoid parsing the complete 
line.
Tell me if it's fit your remarks.


Repository:
  rC Clang

https://reviews.llvm.org/D44609

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  lib/Format/TokenAnnotator.h
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -10461,6 +10461,7 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterExternBlock);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse);
+  CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeLambdaBody);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord);
@@ -11403,6 +11404,49 @@
   "> {\n"
   "  //\n"
   "});");
+
+  // Check option "BraceWrapping.BeforeLambdaBody"
+  FormatStyle LLVMWithBeforeLambdaBody = getLLVMStyle();
+  LLVMWithBeforeLambdaBody.BreakBeforeBraces = FormatStyle::BS_Custom;
+  LLVMWithBeforeLambdaBody.BraceWrapping.BeforeLambdaBody = true;
+  verifyFormat("FunctionWithOneParam(\n"
+   "[]()\n"
+   "{\n"
+   "  // A cool function...\n"
+   "  return 43;\n"
+   "},\n"
+   "87);",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FunctionWithTwoParams(\n"
+   "[]()\n"
+   "{\n"
+   "  // A cool function...\n"
+   "  return 43;\n"
+   "},\n"
+   "87);",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("FunctionWithOneNestedLambdas(\n"
+   "[]()\n"
+   "{\n"
+   "  return 17;\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("TwoNestedLambdas(\n"
+   "[]()\n"
+   "{\n"
+   "  return Call(\n"
+   "  []()\n"
+   "  {\n"
+   "return 17;\n"
+   "  });\n"
+   "});",
+   LLVMWithBeforeLambdaBody);
+  verifyFormat("auto array = {[]()\n"
+   "  {\n"
+   "return 43;\n"
+   "  },\n"
+   "  MyFunctor};",
+   LLVMWithBeforeLambdaBody);
 }
 
 TEST_F(FormatTest, EmptyLinesInLambdas) {
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1404,6 +1404,7 @@
   return true;
 }
   }
+  FormatTok->Type = TT_LambdaLBrace;
   LSquare.Type = TT_LambdaLSquare;
   parseChildBlock();
   return true;
Index: lib/Format/TokenAnnotator.h
===
--- lib/Format/TokenAnnotator.h
+++ lib/Format/TokenAnnotator.h
@@ -95,6 +95,17 @@
   template  bool endsWith(Ts... Tokens) const {
 return Last && Last->endsSequence(Tokens...);
   }
+  /// \c true if this line, starting at token 'Start', contains the given tokens in order,
+  /// ignoring comments.
+  template  bool containsAfter(const FormatToken& Start, Ts... Tokens) const {
+const FormatToken *Tok = &Start;
+while (Tok) {
+if(Tok->startsSequence(Tokens...))
+return true;
+Tok = Tok->Next;
+}
+return false;
+  }
 
   /// \c true if this line looks like a function definition instead of a
   /// function declaration. Asserts MightBeFunctionDecl.
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1108,11 +1108,11 @@
 
 // Reset token type in case we have already looked at it and then
 // recovered from an error (e.g. failure to find the matching >).
-if (!CurrentToken->isOneOf(TT_LambdaLSquare, TT_ForEachMacro,
-   TT_FunctionLBrace, TT_ImplicitStringLiteral,
-   TT_InlineASMBrace, TT_JsFatArrow, TT_LambdaArrow,
-   TT_OverloadedOperator, TT_RegexLiteral,
-   TT_T

Re: If I want to disable certain attributes, such as "swiftcall", is there any way to do it now?

2018-04-28 Thread Aaron Ballman via cfe-commits
On Fri, Apr 27, 2018 at 11:23 PM, 朴素 via cfe-commits
 wrote:
>As the title says,thanks.

You could build a custom clang with specific attributes removed, but
there are no compiler flags that allow you to disable arbitrary
attributes like swiftcall.

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


[PATCH] D45444: [clang-tidy] WIP: implement new check for const-correctness

2018-04-28 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 144458.
JonasToth added a comment.

- [Feature] use new statefull const checker
- [Test] add more tests finding false positives


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45444

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/ConstCheck.cpp
  clang-tidy/cppcoreguidelines/ConstCheck.h
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/utils/CMakeLists.txt
  clang-tidy/utils/ExprMutationAnalyzer.cpp
  clang-tidy/utils/ExprMutationAnalyzer.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-const.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-const-pointers-as-values.cpp
  test/clang-tidy/cppcoreguidelines-const-values.cpp
  unittests/clang-tidy/CMakeLists.txt
  unittests/clang-tidy/ExprMutationAnalyzerTest.cpp

Index: unittests/clang-tidy/ExprMutationAnalyzerTest.cpp
===
--- /dev/null
+++ unittests/clang-tidy/ExprMutationAnalyzerTest.cpp
@@ -0,0 +1,528 @@
+//===-- ExprMutationAnalyzerTest.cpp - clang-tidy -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../clang-tidy/utils/ExprMutationAnalyzer.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace tidy {
+namespace test {
+
+using namespace clang::ast_matchers;
+using ::testing::ElementsAre;
+using ::testing::IsEmpty;
+using ::testing::ResultOf;
+using ::testing::StartsWith;
+using ::testing::Values;
+
+namespace {
+
+using ExprMatcher = internal::Matcher;
+using StmtMatcher = internal::Matcher;
+
+ExprMatcher declRefTo(StringRef Name) {
+  return declRefExpr(to(namedDecl(hasName(Name;
+}
+
+StmtMatcher withEnclosingCompound(ExprMatcher Matcher) {
+  return expr(Matcher, hasAncestor(compoundStmt().bind("stmt"))).bind("expr");
+}
+
+bool isMutated(const SmallVectorImpl &Results, ASTUnit *AST) {
+  const auto *const S = selectFirst("stmt", Results);
+  const auto *const E = selectFirst("expr", Results);
+  return utils::ExprMutationAnalyzer(S, &AST->getASTContext()).isMutated(E);
+}
+
+SmallVector
+mutatedBy(const SmallVectorImpl &Results, ASTUnit *AST) {
+  const auto *const S = selectFirst("stmt", Results);
+  SmallVector Chain;
+  utils::ExprMutationAnalyzer Analyzer(S, &AST->getASTContext());
+  for (const auto *E = selectFirst("expr", Results); E != nullptr;) {
+const Stmt *By = Analyzer.findMutation(E);
+std::string buffer;
+llvm::raw_string_ostream stream(buffer);
+By->printPretty(stream, nullptr, AST->getASTContext().getPrintingPolicy());
+Chain.push_back(StringRef(stream.str()).trim().str());
+E = dyn_cast(By);
+  }
+  return Chain;
+}
+
+std::string removeSpace(std::string s) {
+  s.erase(std::remove_if(s.begin(), s.end(),
+ [](char c) { return std::isspace(c); }),
+  s.end());
+  return s;
+}
+
+} // namespace
+
+TEST(ExprMutationAnalyzerTest, Trivial) {
+  const auto AST = tooling::buildASTFromCode("void f() { int x; x; }");
+  const auto Results =
+  match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_FALSE(isMutated(Results, AST.get()));
+}
+
+class AssignmentTest : public ::testing::TestWithParam {};
+
+TEST_P(AssignmentTest, AssignmentModifies) {
+  const std::string ModExpr = "x " + GetParam() + " 10";
+  const auto AST =
+  tooling::buildASTFromCode("void f() { int x; " + ModExpr + "; }");
+  const auto Results =
+  match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre(ModExpr));
+}
+
+INSTANTIATE_TEST_CASE_P(AllAssignmentOperators, AssignmentTest,
+Values("=", "+=", "-=", "*=", "/=", "%=", "&=", "|=",
+   "^=", "<<=", ">>="), );
+
+class IncDecTest : public ::testing::TestWithParam {};
+
+TEST_P(IncDecTest, IncDecModifies) {
+  const std::string ModExpr = GetParam();
+  const auto AST =
+  tooling::buildASTFromCode("void f() { int x; " + ModExpr + "; }");
+  const auto Results =
+  match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre(ModExpr));
+}
+
+INSTANTIATE_TEST_CASE_P(AllIncDecOperators, IncDecTest,
+Values("++x", "--x", "x++", "x--"), );
+
+TEST(ExprMutationAnalyzerTest, NonConstMemberFunc) {
+  const auto AST = tooling::buildASTFromCode(
+  "void f() { struct Foo { void mf(); }; Foo x; x.mf(); }");
+  const auto Results =
+  match(withEnclosingCompound(declRefTo("x

[PATCH] D45679: [clang-tidy] Add a helper function isModified, that checks whether an expression is modified within a statement.

2018-04-28 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

There is a false positive with the reference checking. Could you please take a 
look at it? I could not find the reason from inspecting your code.

  void false_positive() {
  // FIXME False positive
  int np_local0 = 42;   
  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'np_local0' of type 'int' 
can be declared const
  const int &r0_np_local0 = np_local0;
  int &r1_np_local0 = np_local0;
  r1_np_local0 = 43;
  }


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45679



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


[PATCH] D21852: [Driver][OpenMP] Update actions builder to create bundling action when necessary.

2018-04-28 Thread Json Lee via Phabricator via cfe-commits
lijiansong added a comment.

hello, 
if I want to compile device-only device code, e.g. clang foo.mlu a.cpp -o bar,
I want to get the following action graph:
for foo.mlu:
input -> preprocess->compile->backend->assemble ,
Then i will get foo.o,
for a.cpp:
input -> preprocess->compile->backend->assemble
then I will get a.o
i want to link foo.o with a.o to get bar, a.cpp is the main, while foo.mlu has 
the device computation logic.

How can I manage it with offload?


https://reviews.llvm.org/D21852



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


[PATCH] D21852: [Driver][OpenMP] Update actions builder to create bundling action when necessary.

2018-04-28 Thread Json Lee via Phabricator via cfe-commits
lijiansong added inline comments.
Herald added a subscriber: guansong.



Comment at: lib/Driver/Driver.cpp:2113-2124
+// the resulting list. Otherwise, just append the device actions.
+if (CanUseBundler && !OffloadAL.empty()) {
+  // Add the host action to the list in order to create the bundling 
action.
+  OffloadAL.push_back(HostAction);
+
+  // We expect that the host action was just appended to the action list
+  // before this method was called.

hello, 
if I want to compile device-only device code, e.g. clang foo.mlu a.cpp -o bar,
I want to get the following action graph:
for foo.mlu:
input -> preprocess->compile->backend->assemble ,
Then i will get foo.o,
for a.cpp:
input -> preprocess->compile->backend->assemble
then I will get a.o
i want to link foo.o with a.o to get bar, a.cpp is the main, while foo.mlu has 
the device computation logic.

How can I manage it with offload?


https://reviews.llvm.org/D21852



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


[PATCH] D46052: GNUstep Objective-C ABI version 2

2018-04-28 Thread David Chisnall via Phabricator via cfe-commits
theraven added inline comments.



Comment at: lib/CodeGen/CGObjCGNU.cpp:977
+if ((CGM.getTarget().getPointerWidth(0) == 64) &&
+(SL->getLength() < 9) && !isNonASCII) {
+  // Tiny strings are (roughly):

rjmccall wrote:
> Please hoist `SL->getLength()` into a variable.
> 
> Also, consider breaking this bit of code (maybe just building a `uint64_t`?) 
> into a separate function.
I don't think separating it would simplify the code much.  It's 8 lines of 
non-comment code and you'd probably need at least three of them in the caller.



Comment at: lib/CodeGen/CGObjCGNU.cpp:1077
+std::replace(StringName.begin(), StringName.end(),
+  '@', '\1');
+auto *ObjCStrGV =

rjmccall wrote:
> Is `@` really the only illegal character in ELF symbol names?  Surely at 
> least `\0` as well.  And your mangling will collide strings if they contain 
> `\1`.
> 
> I think you should probably just have this use internal linkage (and a 
> meaningless symbol name) for strings containing bad characters.
No, I copied the mangling for selectors without engaging my brain.  I've now 
replaced it with something much more conservative.  I might tweak it a bit 
before the next release, but this seems to give pretty good coverage.


Repository:
  rC Clang

https://reviews.llvm.org/D46052



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


[PATCH] D45532: [StaticAnalyzer] Checker to find uninitialized fields after a constructor call

2018-04-28 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 10.
Szelethus added a comment.

Forgot to rename the system header simulator file. Sorry about the spam :)


https://reviews.llvm.org/D45532

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/Inputs/system-header-simulator-for-cxx-uninitialized-object.h
  test/Analysis/cxx-uninitialized-object-inheritance.cpp
  test/Analysis/cxx-uninitialized-object.cpp

Index: test/Analysis/cxx-uninitialized-object.cpp
===
--- /dev/null
+++ test/Analysis/cxx-uninitialized-object.cpp
@@ -0,0 +1,1449 @@
+//RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.uninitialized.UninitializedObject -analyzer-config cplusplus.uninitialized.UninitializedObject:Pedantic=true -std=c++11 -DPEDANTIC -verify %s
+
+//RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.uninitialized.UninitializedObject -std=c++11 -verify %s
+
+//===--===//
+// Default constructor test.
+//===--===//
+
+class CompilerGeneratedConstructorTest {
+  int a, b, c, d, e, f, g, h, i, j;
+
+public:
+  CompilerGeneratedConstructorTest() = default;
+};
+
+void f000() {
+  CompilerGeneratedConstructorTest();
+}
+
+#ifdef PEDANTIC
+class DefaultConstructorTest {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+
+public:
+  DefaultConstructorTest();
+};
+
+DefaultConstructorTest::DefaultConstructorTest() = default;
+
+void f00() {
+  DefaultConstructorTest(); // expected-warning{{1 uninitialized field}}
+}
+#else
+class DefaultConstructorTest {
+  int a;
+
+public:
+  DefaultConstructorTest();
+};
+
+DefaultConstructorTest::DefaultConstructorTest() = default;
+
+void f00() {
+  DefaultConstructorTest();
+}
+#endif // PEDANTIC
+
+//===--===//
+// Initializer list test.
+//===--===//
+
+class InitListTest1 {
+  int a;
+  int b;
+
+public:
+  InitListTest1()
+  : a(1),
+b(2) {
+// All good!
+  }
+};
+
+void f01() {
+  InitListTest1();
+}
+
+class InitListTest2 {
+  int a;
+  int b; // expected-note{{uninitialized field 'this->b'}}
+
+public:
+  InitListTest2()
+  : a(3) {} // expected-warning{{1 uninitialized field}}
+};
+
+void f02() {
+  InitListTest2();
+}
+
+class InitListTest3 {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+  int b;
+
+public:
+  InitListTest3()
+  : b(4) {} // expected-warning{{1 uninitialized field}}
+};
+
+void f03() {
+  InitListTest3();
+}
+
+//===--===//
+// Constructor body test.
+//===--===//
+
+class CtorBodyTest1 {
+  int a, b;
+
+public:
+  CtorBodyTest1() {
+a = 5;
+b = 6;
+// All good!
+  }
+};
+
+void f04() {
+  CtorBodyTest1();
+}
+
+class CtorBodyTest2 {
+  int a;
+  int b; // expected-note{{uninitialized field 'this->b'}}
+
+public:
+  CtorBodyTest2() {
+a = 7; // expected-warning{{1 uninitialized field}}
+  }
+};
+
+void f05() {
+  CtorBodyTest2();
+}
+
+class CtorBodyTest3 {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+  int b;
+
+public:
+  CtorBodyTest3() {
+b = 8; // expected-warning{{1 uninitialized field}}
+  }
+};
+
+void f06() {
+  CtorBodyTest3();
+}
+
+#ifdef PEDANTIC
+class CtorBodyTest4 {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+  int b; // expected-note{{uninitialized field 'this->b'}}
+
+public:
+  CtorBodyTest4() {}
+};
+
+void f07() {
+  CtorBodyTest4(); // expected-warning{{2 uninitialized fields}}
+}
+#else
+class CtorBodyTest4 {
+  int a;
+  int b;
+
+public:
+  CtorBodyTest4() {}
+};
+
+void f07() {
+  CtorBodyTest4();
+}
+#endif
+
+//===--===//
+// Constructor delegation test.
+//===--===//
+
+class CtorDelegationTest1 {
+  int a;
+  int b;
+
+public:
+  CtorDelegationTest1(int)
+  : a(9) {
+// leaves 'b' unintialized, but we'll never check this function
+  }
+
+  CtorDelegationTest1()
+  : CtorDelegationTest1(int{}) { // Initializing 'a'
+b = 10;
+// All good!
+  }
+};
+
+void f08() {
+  CtorDelegationTest1();
+}
+
+class CtorDelegationTest2 {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+  int b;
+
+public:
+  CtorDelegationTest2(int)
+  : b(11) {
+// leaves 'a' unintialized, but we'll never check this function
+  }
+
+  CtorDelegationTest2()
+  : CtorDelegationTest2(int{}) { // expected-warning{{1 uninitialized field}}
+  }
+};
+
+void f09() {
+  CtorDelegationTest2();
+}
+
+//===--

[PATCH] D45532: [StaticAnalyzer] Checker to find uninitialized fields after a constructor call

2018-04-28 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus marked an inline comment as done.
Szelethus added inline comments.



Comment at: test/Analysis/cxx-uninitialized-object.cpp:526
+
+void f23p5() {
+  void *vptr = malloc(sizeof(int));

I haven't marked @a.sidorin's comment as done, but it disappeared because I 
renamed the file, so here it is:
> Could you please explain what is the logic of test naming?
To which I replied:
> The test files follow the strict structure that for each test case we'll 
> define a structure type and then call its constructor(s) in a function right 
> after it (functions are used to avoid zero initializations).
>
>To be honest, there is no real logic behind the naming of the functions, it is 
>only to keep the ODR. I used numbers in an increasing order, however I later 
>added there cases, so in between `f23` and `f24` I used `f23p5` and so on.
>
>I figured that the strict structure of the test files would avoid confusion. 
>Do you find it distracting?


https://reviews.llvm.org/D45532



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


[PATCH] D45532: [StaticAnalyzer] Checker to find uninitialized fields after a constructor call

2018-04-28 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 144439.
Szelethus marked an inline comment as done.
Szelethus added a comment.

Renamed the checker to `cplusplus.uninitialized.UninitializedObject`.

I've read your comments regarding the category this should be in thoroughly, 
and should the clang-tidy category naming not be an issue, `cplusplus.bugprone` 
would've probably been the best option. However, since it is a concern, I did 
find many checkers in the core in the `uninitialized` subcategory, so I thought 
I'll place it in `cplusplus.uninitialized` for now. This could be a little too 
specific though, as I don't think many other checkers could be implemented that 
would reside in there.

What do you guys think?


https://reviews.llvm.org/D45532

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/Inputs/system-header-simulator-ctor-uninitialized-member.h
  test/Analysis/cxx-uninitialized-object-inheritance.cpp
  test/Analysis/cxx-uninitialized-object.cpp

Index: test/Analysis/cxx-uninitialized-object.cpp
===
--- /dev/null
+++ test/Analysis/cxx-uninitialized-object.cpp
@@ -0,0 +1,1449 @@
+//RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.uninitialized.UninitializedObject -analyzer-config cplusplus.uninitialized.UninitializedObject:Pedantic=true -std=c++11 -DPEDANTIC -verify %s
+
+//RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.uninitialized.UninitializedObject -std=c++11 -verify %s
+
+//===--===//
+// Default constructor test.
+//===--===//
+
+class CompilerGeneratedConstructorTest {
+  int a, b, c, d, e, f, g, h, i, j;
+
+public:
+  CompilerGeneratedConstructorTest() = default;
+};
+
+void f000() {
+  CompilerGeneratedConstructorTest();
+}
+
+#ifdef PEDANTIC
+class DefaultConstructorTest {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+
+public:
+  DefaultConstructorTest();
+};
+
+DefaultConstructorTest::DefaultConstructorTest() = default;
+
+void f00() {
+  DefaultConstructorTest(); // expected-warning{{1 uninitialized field}}
+}
+#else
+class DefaultConstructorTest {
+  int a;
+
+public:
+  DefaultConstructorTest();
+};
+
+DefaultConstructorTest::DefaultConstructorTest() = default;
+
+void f00() {
+  DefaultConstructorTest();
+}
+#endif // PEDANTIC
+
+//===--===//
+// Initializer list test.
+//===--===//
+
+class InitListTest1 {
+  int a;
+  int b;
+
+public:
+  InitListTest1()
+  : a(1),
+b(2) {
+// All good!
+  }
+};
+
+void f01() {
+  InitListTest1();
+}
+
+class InitListTest2 {
+  int a;
+  int b; // expected-note{{uninitialized field 'this->b'}}
+
+public:
+  InitListTest2()
+  : a(3) {} // expected-warning{{1 uninitialized field}}
+};
+
+void f02() {
+  InitListTest2();
+}
+
+class InitListTest3 {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+  int b;
+
+public:
+  InitListTest3()
+  : b(4) {} // expected-warning{{1 uninitialized field}}
+};
+
+void f03() {
+  InitListTest3();
+}
+
+//===--===//
+// Constructor body test.
+//===--===//
+
+class CtorBodyTest1 {
+  int a, b;
+
+public:
+  CtorBodyTest1() {
+a = 5;
+b = 6;
+// All good!
+  }
+};
+
+void f04() {
+  CtorBodyTest1();
+}
+
+class CtorBodyTest2 {
+  int a;
+  int b; // expected-note{{uninitialized field 'this->b'}}
+
+public:
+  CtorBodyTest2() {
+a = 7; // expected-warning{{1 uninitialized field}}
+  }
+};
+
+void f05() {
+  CtorBodyTest2();
+}
+
+class CtorBodyTest3 {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+  int b;
+
+public:
+  CtorBodyTest3() {
+b = 8; // expected-warning{{1 uninitialized field}}
+  }
+};
+
+void f06() {
+  CtorBodyTest3();
+}
+
+#ifdef PEDANTIC
+class CtorBodyTest4 {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+  int b; // expected-note{{uninitialized field 'this->b'}}
+
+public:
+  CtorBodyTest4() {}
+};
+
+void f07() {
+  CtorBodyTest4(); // expected-warning{{2 uninitialized fields}}
+}
+#else
+class CtorBodyTest4 {
+  int a;
+  int b;
+
+public:
+  CtorBodyTest4() {}
+};
+
+void f07() {
+  CtorBodyTest4();
+}
+#endif
+
+//===--===//
+// Constructor delegation test.
+//===--===//
+
+class CtorDelegationTest1 {
+  int a;
+  int b;
+
+public:
+  CtorDelegationTest1(int)
+  : a(9) {
+// leaves 'b' unintialized, but we'll never check this function
+  }
+
+  CtorD