[PATCH] D12722: cortex-r5f and cortex-m4f are unknown names for clang

2015-09-09 Thread Alexandros Lamprineas via cfe-commits
labrinea created this revision.
labrinea added reviewers: rengolin, richard.barton.arm.
labrinea added a subscriber: cfe-commits.

Tests are currently passing but warning messages are suppressed.

http://reviews.llvm.org/D12722

Files:
  test/CodeGen/arm-target-features.c

Index: test/CodeGen/arm-target-features.c
===
--- test/CodeGen/arm-target-features.c
+++ test/CodeGen/arm-target-features.c
@@ -28,7 +28,7 @@
 // CHECK-BASIC-V8: 
"target-features"="+crc,+crypto,+fp-armv8,+hwdiv,+hwdiv-arm,+neon"
 
 
-// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-r5f 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP3-D16-DIV
+// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-r5 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP3-D16-DIV
 // CHECK-VFP3-D16-DIV: "target-features"="+d16,+hwdiv,+hwdiv-arm,+vfp3"
 
 
@@ -40,21 +40,16 @@
 // CHECK-VFP3-D16-FP16-DIV: 
"target-features"="+d16,+fp16,+hwdiv,+hwdiv-arm,+vfp3"
 
 
-// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-m4f 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP4-D16-SP-THUMB-DIV
+// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-m4 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP4-D16-SP-THUMB-DIV
 // CHECK-VFP4-D16-SP-THUMB-DIV: 
"target-features"="+d16,+fp-only-sp,+hwdiv,+vfp4"
 
 
 // RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-m7 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP5-D16-THUMB-DIV
 // CHECK-VFP5-D16-THUMB-DIV: "target-features"="+d16,+fp-armv8,+hwdiv"
 
 
-// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-r5 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-DIV
-// CHECK-DIV: "target-features"="+hwdiv,+hwdiv-arm"
-
-
 // RUN: %clang_cc1 -triple armv7-linux-gnueabi -target-cpu cortex-r4 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-THUMB-DIV
 // RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-m3 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-THUMB-DIV
-// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-m4 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-THUMB-DIV
 // CHECK-THUMB-DIV: "target-features"="+hwdiv"
 
 


Index: test/CodeGen/arm-target-features.c
===
--- test/CodeGen/arm-target-features.c
+++ test/CodeGen/arm-target-features.c
@@ -28,7 +28,7 @@
 // CHECK-BASIC-V8: "target-features"="+crc,+crypto,+fp-armv8,+hwdiv,+hwdiv-arm,+neon"
 
 
-// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-r5f -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP3-D16-DIV
+// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-r5 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP3-D16-DIV
 // CHECK-VFP3-D16-DIV: "target-features"="+d16,+hwdiv,+hwdiv-arm,+vfp3"
 
 
@@ -40,21 +40,16 @@
 // CHECK-VFP3-D16-FP16-DIV: "target-features"="+d16,+fp16,+hwdiv,+hwdiv-arm,+vfp3"
 
 
-// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-m4f -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP4-D16-SP-THUMB-DIV
+// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-m4 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP4-D16-SP-THUMB-DIV
 // CHECK-VFP4-D16-SP-THUMB-DIV: "target-features"="+d16,+fp-only-sp,+hwdiv,+vfp4"
 
 
 // RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-m7 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP5-D16-THUMB-DIV
 // CHECK-VFP5-D16-THUMB-DIV: "target-features"="+d16,+fp-armv8,+hwdiv"
 
 
-// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-r5 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-DIV
-// CHECK-DIV: "target-features"="+hwdiv,+hwdiv-arm"
-
-
 // RUN: %clang_cc1 -triple armv7-linux-gnueabi -target-cpu cortex-r4 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-THUMB-DIV
 // RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-m3 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-THUMB-DIV
-// RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-m4 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-THUMB-DIV
 // CHECK-THUMB-DIV: "target-features"="+hwdiv"
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12722: cortex-r5f and cortex-m4f are unknown names for clang

2015-09-09 Thread Renato Golin via cfe-commits
rengolin accepted this revision.
rengolin added a comment.
This revision is now accepted and ready to land.

As required by http://reviews.llvm.org/D12692. LGTM, thanks!


http://reviews.llvm.org/D12722



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


Re: [PATCH] D12633: Implement ACLE 2.0 macros of chapters 6.6 and 6.7 for [ARM] and [Aarch64] targets

2015-09-09 Thread Alexandros Lamprineas via cfe-commits
labrinea added a comment.

Ping


http://reviews.llvm.org/D12633



___
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-09 Thread Sanjoy Das via cfe-commits
sanjoy added a comment.

I don't think this is an infinite loop (Piotr, can you please verify
this?), it is probably an O(n!) recursion where n == number of the
assumptions.

ScalarEvolution::isImpliedCond already guards for infinite loops via
MarkPendingLoopPredicate.  However, if you have

assume_0()
 assume_1()
 assume_2()
 assume_3()

then the recursive call to isImpliedCond(assume_2, X) may end up
calling isImpliedCond(assume_1, Y) and that may end up calling
isImpliedCond(assume_0, Y) and that may end up calling
isImpliedCond(assume_3, Y).  This way, even though we're protected
against full on infinite recursion, we'll still explore all 4! = 24
possibilities.

I think the check with LoopContinuePredicate is fine since it only
calls isImpliedCond if there is exactly one latch in the loop.  This
means that the above n! possibility is really only a 1! = 1
possibility for LoopContinuePredicate.

But this from memory, so please double check.


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-09 Thread Sanjoy Das via cfe-commits
> Both tests are protected by there being exactly one latch in the loop (we
> exit early if there's not one latch). I'm not sure what makes the
> LoopContinuePredicate check safer?

You can have a loop with a single latch but an arbitrary number of
assumes (= n).  In such a loop, you'll still end up calling
isImpliedCond O(n!) times because of the assumes (and the guard
on there being only one latch won't help).

OTOH if the loop has multiple latches = m > 1, then we exit early we
won't recurse at all, we'll just bail early from
isLoopBackedgeGuardedByCond because of the check you mention (not
ideal, but safe).

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


Re: [PATCH] D12725: [analyzer] A fix for substraction of an integer from a pointer.

2015-09-09 Thread Artem Dergachev via cfe-commits
NoQ updated this revision to Diff 34320.

http://reviews.llvm.org/D12725

Files:
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  test/Analysis/ptr-arith.c

Index: test/Analysis/ptr-arith.c
===
--- test/Analysis/ptr-arith.c
+++ test/Analysis/ptr-arith.c
@@ -296,3 +296,16 @@
   clang_analyzer_eval([i].x < [i].y);// expected-warning{{TRUE}}
 }
 
+void negativeIndex(char *str) {
+  char *ptr = str + 1;
+  *ptr = 'a';
+  ptr = str - 1;
+  clang_analyzer_eval(*ptr); // expected-warning{{UNKNOWN}}
+  ptr = str;
+  ptr -= 1;
+  clang_analyzer_eval(*ptr); // expected-warning{{UNKNOWN}}
+  ptr = str;
+  --ptr;
+  clang_analyzer_eval(*ptr); // expected-warning{{UNKNOWN}}
+}
+
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -911,8 +911,9 @@
   elementType = elemReg->getElementType();
 }
 else if (isa(region)) {
+  assert(op == BO_Add || op == BO_Sub);
+  index = (op == BO_Add) ? rhs : evalMinus(rhs);
   superR = region;
-  index = rhs;
   if (resultTy->isAnyPointerType())
 elementType = resultTy->getPointeeType();
 }


Index: test/Analysis/ptr-arith.c
===
--- test/Analysis/ptr-arith.c
+++ test/Analysis/ptr-arith.c
@@ -296,3 +296,16 @@
   clang_analyzer_eval([i].x < [i].y);// expected-warning{{TRUE}}
 }
 
+void negativeIndex(char *str) {
+  char *ptr = str + 1;
+  *ptr = 'a';
+  ptr = str - 1;
+  clang_analyzer_eval(*ptr); // expected-warning{{UNKNOWN}}
+  ptr = str;
+  ptr -= 1;
+  clang_analyzer_eval(*ptr); // expected-warning{{UNKNOWN}}
+  ptr = str;
+  --ptr;
+  clang_analyzer_eval(*ptr); // expected-warning{{UNKNOWN}}
+}
+
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -911,8 +911,9 @@
   elementType = elemReg->getElementType();
 }
 else if (isa(region)) {
+  assert(op == BO_Add || op == BO_Sub);
+  index = (op == BO_Add) ? rhs : evalMinus(rhs);
   superR = region;
-  index = rhs;
   if (resultTy->isAnyPointerType())
 elementType = resultTy->getPointeeType();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12633: Implement ACLE 2.0 macros of chapters 6.6 and 6.7 for [ARM] and [Aarch64] targets

2015-09-09 Thread Renato Golin via cfe-commits
rengolin added inline comments.


Comment at: lib/Basic/Targets.cpp:4785
@@ +4784,3 @@
+if (Opts.C99 && !Opts.Freestanding) {
+  Builder.defineMacro("__ARM_FP_FENV_ROUNDING", "1");
+  Builder.defineMacro("__STDC_IEC_559__", "1");

I'm not convinced by the runtime rounding being depending on C99, or why it's 
not possible in freestanding environments.


Comment at: lib/Basic/Targets.cpp:4790
@@ -4779,1 +4789,3 @@
+if (!Opts.C11)
+  Builder.defineMacro("__SUPPORT_SNAN__", "1");
   }

Er, well, the ACLE doc says it wasn't adopted in C11, but that doesn't mean 
that it was present in all others, just that there is a proposal for C11 which 
wasn't accepted.

I think this macro needs some other mechanism to be set, and unless Clang/LLVM 
supports signaling NANs unconditionally, we shouldn't add it.


Comment at: lib/Basic/Targets.cpp:5270
@@ +5269,3 @@
+if (Opts.C99 && !Opts.Freestanding) {
+  Builder.defineMacro("__ARM_FP_FENV_ROUNDING", "1");
+  Builder.defineMacro("__STDC_IEC_559__", "1");

same comments as above.


http://reviews.llvm.org/D12633



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


Re: [PATCH] D12633: Implement ACLE 2.0 macros of chapters 6.6 and 6.7 for [ARM] and [Aarch64] targets

2015-09-09 Thread Alexandros Lamprineas via cfe-commits
labrinea added inline comments.


Comment at: lib/Basic/Targets.cpp:4785
@@ +4784,3 @@
+if (Opts.C99 && !Opts.Freestanding) {
+  Builder.defineMacro("__ARM_FP_FENV_ROUNDING", "1");
+  Builder.defineMacro("__STDC_IEC_559__", "1");

rengolin wrote:
> I'm not convinced by the runtime rounding being depending on C99, or why it's 
> not possible in freestanding environments.
I copied the same logic from AArch64.


Comment at: lib/Basic/Targets.cpp:4786
@@ +4785,3 @@
+  Builder.defineMacro("__ARM_FP_FENV_ROUNDING", "1");
+  Builder.defineMacro("__STDC_IEC_559__", "1");
+}

Shall we define this unconditionally?


Comment at: lib/Basic/Targets.cpp:4790
@@ -4779,1 +4789,3 @@
+if (!Opts.C11)
+  Builder.defineMacro("__SUPPORT_SNAN__", "1");
   }

rengolin wrote:
> Er, well, the ACLE doc says it wasn't adopted in C11, but that doesn't mean 
> that it was present in all others, just that there is a proposal for C11 
> which wasn't accepted.
> 
> I think this macro needs some other mechanism to be set, and unless 
> Clang/LLVM supports signaling NANs unconditionally, we shouldn't add it.
Maybe we could skip this macro in this patch? @richard.barton.arm


Comment at: lib/Basic/Targets.cpp:5270
@@ +5269,3 @@
+if (Opts.C99 && !Opts.Freestanding) {
+  Builder.defineMacro("__ARM_FP_FENV_ROUNDING", "1");
+  Builder.defineMacro("__STDC_IEC_559__", "1");

rengolin wrote:
> same comments as above.
This was present already.


http://reviews.llvm.org/D12633



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


r247144 - [Solaris] Use the GCC Installation detector to add the C++ include paths.

2015-09-09 Thread Rafael Espindola via cfe-commits
Author: rafael
Date: Wed Sep  9 08:36:00 2015
New Revision: 247144

URL: http://llvm.org/viewvc/llvm-project?rev=247144=rev
Log:
[Solaris] Use the GCC Installation detector to add the C++ include paths.

Patch by Xan López!

Added:
cfe/trunk/test/Driver/solaris-header-search.cpp
Modified:
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/lib/Frontend/InitHeaderSearch.cpp

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=247144=247143=247144=diff
==
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Wed Sep  9 08:36:00 2015
@@ -2962,6 +2962,31 @@ Tool *Solaris::buildAssembler() const {
 
 Tool *Solaris::buildLinker() const { return new tools::solaris::Linker(*this); 
}
 
+void Solaris::AddClangCXXStdlibIncludeArgs(const ArgList ,
+   ArgStringList ) const {
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
+  DriverArgs.hasArg(options::OPT_nostdincxx))
+return;
+
+  // Include the support directory for things like xlocale and fudged system
+  // headers.
+  addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/v1/support/solaris");
+
+  if (GCCInstallation.isValid()) {
+GCCVersion Version = GCCInstallation.getVersion();
+addSystemInclude(DriverArgs, CC1Args,
+ getDriver().SysRoot + "/usr/gcc/" +
+ Version.MajorStr + "." +
+ Version.MinorStr +
+ "/include/c++/" + Version.Text);
+addSystemInclude(DriverArgs, CC1Args,
+ getDriver().SysRoot + "/usr/gcc/" + Version.MajorStr +
+ "." + Version.MinorStr + "/include/c++/" +
+ Version.Text + "/" +
+ GCCInstallation.getTriple().str());
+  }
+}
+
 /// Distribution (very bare-bones at the moment).
 
 enum Distro {

Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=247144=247143=247144=diff
==
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Wed Sep  9 08:36:00 2015
@@ -527,6 +527,10 @@ public:
 
   bool IsIntegratedAssemblerDefault() const override { return true; }
 
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;

Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=247144=247143=247144=diff
==
--- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)
+++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Wed Sep  9 08:36:00 2015
@@ -404,10 +404,6 @@ AddDefaultCPlusPlusIncludePaths(const ll
 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
 "", "", "", triple);
 break;
-  case llvm::Triple::Solaris:
-AddGnuCPlusPlusIncludePaths("/usr/gcc/4.5/include/c++/4.5.2/",
-"i386-pc-solaris2.11", "", "", triple);
-break;
   default:
 break;
   }
@@ -453,11 +449,6 @@ void InitHeaderSearch::AddDefaultInclude
   AddUnmappedPath(P, CXXSystem, false);
 }
   }
-  // On Solaris, include the support directory for things like xlocale and
-  // fudged system headers.
-  if (triple.getOS() == llvm::Triple::Solaris) 
-AddPath("/usr/include/c++/v1/support/solaris", CXXSystem, false);
-  
   AddPath("/usr/include/c++/v1", CXXSystem, false);
 } else {
   AddDefaultCPlusPlusIncludePaths(triple, HSOpts);

Added: cfe/trunk/test/Driver/solaris-header-search.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/solaris-header-search.cpp?rev=247144=auto
==
--- cfe/trunk/test/Driver/solaris-header-search.cpp (added)
+++ cfe/trunk/test/Driver/solaris-header-search.cpp Wed Sep  9 08:36:00 2015
@@ -0,0 +1,11 @@
+// Test that the C++ headers are found.
+//
+// RUN: %clang -no-canonical-prefixes %s -### 2>&1 \
+// RUN: --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/sparc-sun-solaris2.11 \
+// RUN:   | FileCheck %s
+// CHECK: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
+// CHECK: "-internal-isystem" "{{.*}}/usr/include/c++/v1/support/solaris"
+// CHECK: "-internal-isystem" "{{.*}}/usr/gcc/4.8/include/c++/4.8.2"
+// CHECK: "-internal-isystem" 
"{{.*}}/usr/gcc/4.8/include/c++/4.8.2/sparc-sun-solaris2.11"


___

MPI-Checker patch for Clang Static Analyzer

2015-09-09 Thread Alexander Droste via cfe-commits

Hi,

this is a patch to add static analysis functionality for MPI code
written in C, in form of a checker to Clang's Static Analyzer. In comparison
to the code currently published on GitHub https://github.com/0ax1/MPI-Checker
I excluded the

unmatched point-to-point call check,
unreachable call check &
collective call in rank branch check

as I do not consider them to be solid enough, to be included
in the patch. These will be rewritten. I'm aware that the
invalid argument type, checking for expressions that evaluate to
a non-integer type, in some way is redundant to the compiler warning
produced by -Wfloat-conversion. My thought about this is that
it might be nice to get informed about this in context of other
MPI related bugs. Further, the -Wfloat-conversion flag seems a little bit
hidden as it is neither included in -Wall nor in -Wextra which is
why some users might not have enabled it by default.

The patch consists of three parts: The actual code for static analysis
contained in tools/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/,
unit tests in tools/clang/unittests/StaticAnalyzer/MPI-Checker/
and the integration tests I put into tools/clang/test/Analysis/MPIChecker.c.

Best regards,
Alex



Index: tools/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
===
--- tools/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt  (revision 
247122)
+++ tools/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt  (working copy)
@@ -45,6 +45,13 @@
   MallocChecker.cpp
   MallocOverflowSecurityChecker.cpp
   MallocSizeofChecker.cpp
+  MPI-Checker/MPIBugReporter.cpp
+  MPI-Checker/MPIChecker.cpp
+  MPI-Checker/MPICheckerAST.cpp
+  MPI-Checker/MPICheckerPathSensitive.cpp
+  MPI-Checker/MPIFunctionClassifier.cpp
+  MPI-Checker/TranslationUnitVisitor.cpp
+  MPI-Checker/Utility.cpp
   NSAutoreleasePoolChecker.cpp
   NSErrorChecker.cpp
   NoReturnFunctionChecker.cpp
Index: tools/clang/lib/StaticAnalyzer/Checkers/Checkers.td
===
--- tools/clang/lib/StaticAnalyzer/Checkers/Checkers.td (revision 247122)
+++ tools/clang/lib/StaticAnalyzer/Checkers/Checkers.td (working copy)
@@ -27,6 +27,8 @@
 def DeadCode : Package<"deadcode">;
 def DeadCodeAlpha : Package<"deadcode">, InPackage, Hidden;
 
+def MPI : Package<"mpi">;
+
 def Security : Package <"security">;
 def InsecureAPI : Package<"insecureAPI">, InPackage;
 def SecurityAlpha : Package<"security">, InPackage, Hidden;
@@ -516,6 +518,13 @@
   DescFile<"ObjCContainersChecker.cpp">;
 
 }
+
+let ParentPackage = MPI in {
+def MPIChecker : Checker<"MPI-Checker">,
+  HelpText<"Checks MPI code written in C">,
+  DescFile<"MPIChecker.cpp">;
+} // end "MPI"
+
 
//===--===//
 // Checkers for LLVM development.
 
//===--===//
Index: tools/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/Container.hpp
===
--- tools/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/Container.hpp   
(revision 0)
+++ tools/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/Container.hpp   
(working copy)
@@ -0,0 +1,166 @@
+//===-- Container.hpp - convenience templates for containers *- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+/// Convenience templates for C++ container classes.
+///
+//===--===//
+
+#ifndef CONTAINER_HPP_XM1FDRVJ
+#define CONTAINER_HPP_XM1FDRVJ
+
+#include 
+
+namespace cont {
+
+/// \brief Check if given element is contained.
+///
+/// \param container
+/// \param elementToCheck
+///
+/// \returns true if element contained
+template 
+bool isContained(const T , const E ) {
+  return std::find(container.begin(), container.end(), elementToCheck) !=
+ container.end();
+}
+
+/// \brief Check if given element is contained.
+///
+/// \param container
+/// \param elementToCheck
+///
+/// \returns true if element that matched predicate is contained
+template 
+bool isContainedPred(const T , P predicate) {
+  return std::find_if(container.begin(), container.end(), predicate) !=
+ container.end();
+}
+
+/// \brief Deletes first appearance of given element.
+///
+/// \param container
+/// \param elementToErase
+template  void erase(T , E ) {
+  auto it = std::find(container.begin(), container.end(), elementToErase);
+  if (it != container.end())
+container.erase(it);
+}
+
+/// \brief Deletes all appearances of given element.
+///
+/// \param container
+/// \param elementToErase
+template 
+void eraseAll(T , E ) {
+  container.erase(
+  

[PATCH] D12726: [analyzer] A fix for symbolic element region index lifetime.

2015-09-09 Thread Artem Dergachev via cfe-commits
NoQ created this revision.
NoQ added reviewers: zaks.anna, krememek.
NoQ added subscribers: cfe-commits, dergachev.a.

In Clang Static Analyzer, when the symbol is referenced by an index value of an 
element region, it does not prevent garbage collection (reaping) of that 
symbol. Hence, if the element index value is the only place where the symbol is 
stored, the symbol gets reaped, and range information is removed from the 
constraint manager.

It seems that both the store and the environment need to mark the element 
indices of their regions as live.

http://reviews.llvm.org/D12726

Files:
  lib/StaticAnalyzer/Core/Environment.cpp
  lib/StaticAnalyzer/Core/RegionStore.cpp
  test/Analysis/return-ptr-range.cpp

Index: test/Analysis/return-ptr-range.cpp
===
--- test/Analysis/return-ptr-range.cpp
+++ test/Analysis/return-ptr-range.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.security.ReturnPtrRange 
-verify %s
+
+int arr[10];
+int *ptr;
+
+int conjure_index();
+
+int *test_element_index_lifetime() {
+  do {
+int x = conjure_index();
+ptr = arr + x;
+if (x != 20)
+  return arr; // no-warning
+  } while (0);
+  return ptr; // expected-warning{{Returned pointer value points outside the 
original object (potential buffer overflow)}}
+}
+
+int *test_element_index_lifetime_with_local_ptr() {
+  int *local_ptr;
+  do {
+int x = conjure_index();
+local_ptr = arr + x;
+if (x != 20)
+  return arr; // no-warning
+  } while (0);
+  return local_ptr; // expected-warning{{Returned pointer value points outside 
the original object (potential buffer overflow)}}
+}
Index: lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- lib/StaticAnalyzer/Core/RegionStore.cpp
+++ lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2260,6 +2260,16 @@
   if (const MemRegion *R = V.getAsRegion()) {
 AddToWorkList(R);
 
+// Element index of an element region is live.
+if (const ElementRegion *ER = dyn_cast(R)) {
+  SVal Idx = ER->getIndex();
+  for (SymExpr::symbol_iterator SI = Idx.symbol_begin(),
+SE = Idx.symbol_end();
+   SI != SE; ++SI) {
+SymReaper.markLive(*SI);
+  }
+}
+
 // All regions captured by a block are also live.
 if (const BlockDataRegion *BR = dyn_cast(R)) {
   BlockDataRegion::referenced_vars_iterator I = 
BR->referenced_vars_begin(),
Index: lib/StaticAnalyzer/Core/Environment.cpp
===
--- lib/StaticAnalyzer/Core/Environment.cpp
+++ lib/StaticAnalyzer/Core/Environment.cpp
@@ -171,8 +171,15 @@
   EBMapRef = EBMapRef.add(BlkExpr, X);
 
   // If the block expr's value is a memory region, then mark that region.
-  if (Optional R = X.getAs())
-SymReaper.markLive(R->getRegion());
+  if (Optional R = X.getAs()) {
+const MemRegion *MR = R->getRegion();
+SymReaper.markLive(MR);
+
+// Mark the element index as live.
+if (const ElementRegion *ER = dyn_cast(MR))
+  if (SymbolRef Sym = ER->getIndex().getAsSymbol())
+SymReaper.markLive(Sym);
+  }
 
   // Mark all symbols in the block expr's value live.
   RSScaner.scan(X);


Index: test/Analysis/return-ptr-range.cpp
===
--- test/Analysis/return-ptr-range.cpp
+++ test/Analysis/return-ptr-range.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.security.ReturnPtrRange -verify %s
+
+int arr[10];
+int *ptr;
+
+int conjure_index();
+
+int *test_element_index_lifetime() {
+  do {
+int x = conjure_index();
+ptr = arr + x;
+if (x != 20)
+  return arr; // no-warning
+  } while (0);
+  return ptr; // expected-warning{{Returned pointer value points outside the original object (potential buffer overflow)}}
+}
+
+int *test_element_index_lifetime_with_local_ptr() {
+  int *local_ptr;
+  do {
+int x = conjure_index();
+local_ptr = arr + x;
+if (x != 20)
+  return arr; // no-warning
+  } while (0);
+  return local_ptr; // expected-warning{{Returned pointer value points outside the original object (potential buffer overflow)}}
+}
Index: lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- lib/StaticAnalyzer/Core/RegionStore.cpp
+++ lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2260,6 +2260,16 @@
   if (const MemRegion *R = V.getAsRegion()) {
 AddToWorkList(R);
 
+// Element index of an element region is live.
+if (const ElementRegion *ER = dyn_cast(R)) {
+  SVal Idx = ER->getIndex();
+  for (SymExpr::symbol_iterator SI = Idx.symbol_begin(),
+SE = Idx.symbol_end();
+   SI != SE; ++SI) {
+SymReaper.markLive(*SI);
+  }
+}
+
 // All 

Re: Preventing several replacements on a macro call.

2015-09-09 Thread Angel Garcia via cfe-commits
+cfe-commits

On Tue, Sep 8, 2015 at 6:56 PM, Angel Garcia  wrote:

> Hi Ted,
>
> I was working on a clang-tidy check, and today I discovered that it was
> unable to do several replacements in different arguments of the same macro
> call. At first, I thought it was a bug, and trying to figure out why this
> was happening, I found that the replacements were rejected in
> *lib/Edit/EditedSource.cpp:46*, where there is a comment that says
> "Trying to write in a macro argument input that has already been written
> for another argument of the same macro". This comment means that this
> changes are rejected on purpose.
>
> At the commit history, I saw that you had commited
>  this code (that's why I am asking
> you). Do you think that there is a way around this? I don't really
> understand why there is a particular case for the macros here, and
> understanding it would help me to decide whether I should give up on trying
> to make this work, or try to find a "better" solution.
>
> Thanks and sorry for the inconvenience,
> Angel
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D12732: Add a deprecation notice to the clang-modernize documentation.

2015-09-09 Thread Alexander Kornienko via cfe-commits
alexfh created this revision.
alexfh added reviewers: klimek, revane.
alexfh added a subscriber: cfe-commits.

Add a deprecation notice to the clang-modernize documentation. Remove
the reference to the external JIRA tracker.

http://reviews.llvm.org/D12732

Files:
  docs/clang-modernize.rst

Index: docs/clang-modernize.rst
===
--- docs/clang-modernize.rst
+++ docs/clang-modernize.rst
@@ -1,5 +1,14 @@
 .. index:: clang-modernize
 
+.. note::
+
+   **Deprecation**
+
+   As of September 2015 all :program:`clang-modernize` transforms have been
+   ported to :doc:`clang-tidy/index`. :program:`clang-modernize` is deprecated
+   and is going to be removed soon.
+
+
 ==
 Clang C++ Modernizer User's Manual
 ==
@@ -17,6 +26,7 @@
cpp11-migrate
MigratorUsage
 
+
 :program:`clang-modernize` is a standalone tool used to automatically convert
 C++ code written against old standards to use features of the newest C++
 standard where appropriate.
@@ -81,34 +91,6 @@
 .. _Building LLVM with CMake: http://llvm.org/docs/CMake.html
 .. _Clang Tools Documentation: http://clang.llvm.org/docs/ClangTools.html
 
-Getting Involved
-
-
-If you find a bug
-
-.. raw:: html
-
-  
-  https://cpp11-migrate.atlassian.net/s/en_USpfg3b3-1988229788/6095/34/1.4.0-m2/_/download/batch/com.atlassian.jira.collector.plugin.jira-issue-collector-plugin:issuecollector/com.atlassian.jira.collector.plugin.jira-issue-collector-plugin:issuecollector.js?collectorId=50813874";>
-  window.ATL_JQ_PAGE_PROPS =  {
-"triggerFunction": function(showCollectorDialog) {
-  //Requries that jQuery is available! 
-  jQuery("#logbug").click(function(e) {
-e.preventDefault();
-showCollectorDialog();
-  });
-}};
-  
-
-Bugs and feature development of the Modernizer are tracked at
-http://cpp11-migrate.atlassian.net. If you want to get involved the front page
-shows a list of outstanding issues or you can browse around the project to get
-familiar. To take on issues or contribute feature requests and/or bug reports
-you need to sign up for an account from the `log in page`_. An account also
-lets you sign up for notifications on issues or vote for unassigned issues to
-be completed.
-
-.. _log in page: https://cpp11-migrate.atlassian.net/login
 
 .. _transforms:
 


Index: docs/clang-modernize.rst
===
--- docs/clang-modernize.rst
+++ docs/clang-modernize.rst
@@ -1,5 +1,14 @@
 .. index:: clang-modernize
 
+.. note::
+
+   **Deprecation**
+
+   As of September 2015 all :program:`clang-modernize` transforms have been
+   ported to :doc:`clang-tidy/index`. :program:`clang-modernize` is deprecated
+   and is going to be removed soon.
+
+
 ==
 Clang C++ Modernizer User's Manual
 ==
@@ -17,6 +26,7 @@
cpp11-migrate
MigratorUsage
 
+
 :program:`clang-modernize` is a standalone tool used to automatically convert
 C++ code written against old standards to use features of the newest C++
 standard where appropriate.
@@ -81,34 +91,6 @@
 .. _Building LLVM with CMake: http://llvm.org/docs/CMake.html
 .. _Clang Tools Documentation: http://clang.llvm.org/docs/ClangTools.html
 
-Getting Involved
-
-
-If you find a bug
-
-.. raw:: html
-
-  
-  https://cpp11-migrate.atlassian.net/s/en_USpfg3b3-1988229788/6095/34/1.4.0-m2/_/download/batch/com.atlassian.jira.collector.plugin.jira-issue-collector-plugin:issuecollector/com.atlassian.jira.collector.plugin.jira-issue-collector-plugin:issuecollector.js?collectorId=50813874";>
-  window.ATL_JQ_PAGE_PROPS =  {
-"triggerFunction": function(showCollectorDialog) {
-  //Requries that jQuery is available! 
-  jQuery("#logbug").click(function(e) {
-e.preventDefault();
-showCollectorDialog();
-  });
-}};
-  
-
-Bugs and feature development of the Modernizer are tracked at
-http://cpp11-migrate.atlassian.net. If you want to get involved the front page
-shows a list of outstanding issues or you can browse around the project to get
-familiar. To take on issues or contribute feature requests and/or bug reports
-you need to sign up for an account from the `log in page`_. An account also
-lets you sign up for notifications on issues or vote for unassigned issues to
-be completed.
-
-.. _log in page: https://cpp11-migrate.atlassian.net/login
 
 .. _transforms:
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12633: Implement ACLE 2.0 macros of chapters 6.6 and 6.7 for [ARM] and [Aarch64] targets

2015-09-09 Thread Renato Golin via cfe-commits
rengolin added reviewers: rsmith, t.p.northover.
rengolin added a comment.

Adding Richard Smith, as he was the one choosing C99/!freestanding for runtime 
rounding.



Comment at: lib/Basic/Targets.cpp:4790
@@ -4779,1 +4789,3 @@
+if (!Opts.C11)
+  Builder.defineMacro("__SUPPORT_SNAN__", "1");
   }

labrinea wrote:
> rengolin wrote:
> > Er, well, the ACLE doc says it wasn't adopted in C11, but that doesn't mean 
> > that it was present in all others, just that there is a proposal for C11 
> > which wasn't accepted.
> > 
> > I think this macro needs some other mechanism to be set, and unless 
> > Clang/LLVM supports signaling NANs unconditionally, we shouldn't add it.
> Maybe we could skip this macro in this patch? @richard.barton.arm
If this item sparks controversy, we should keep it out. For now, I'm interested 
in what Tim and Richard(s) have to say.


http://reviews.llvm.org/D12633



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


[PATCH] D12736: [PATCH] AST traversal from types to decls

2015-09-09 Thread Aaron Ballman via cfe-commits
aaron.ballman created this revision.
aaron.ballman added a reviewer: klimek.
aaron.ballman added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

The AST matching code that traverses from types to decls misses a lot of 
possible conversions. This patch adds all of the conversions I could find. 
However, not all of the type->decl conversions can be used from the AST 
matchers yet. For instance, we do not have matcher support for 
ObjCInterfaceDecl. I've added a test case for the one conversion we currently 
support. I feel it's reasonable to have reduced test coverage for the other 
types at this point compared to the difficulty of tracking down why simple 
matchers were failing.

This now allows us to write a matcher like:

varDecl(hasType(namedDecl(hasName("Foo"

that matches code like:

typedef int Foo;
Foo f; // matches f

Previously, the hasType(namedDecl()) matcher would only properly match if the 
type queried was a TagType. Now it can support any type which is traversable to 
a decl.

http://reviews.llvm.org/D12736

Files:
  include/clang/ASTMatchers/ASTMatchersInternal.h
  unittests/ASTMatchers/ASTMatchersTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -924,6 +924,15 @@
varDecl(hasType(namedDecl(hasName("S"));
 }
 
+TEST(TypeMatcher, MatchesDeclTypes) {
+  EXPECT_TRUE(matches("typedef int I; void f(I i);",
+  parmVarDecl(hasType(namedDecl(hasName("I"));
+
+  // FIXME: when we support ObjCInterfaceDecl, and TemplateTypeParmDecl, add
+  // testing code here. Explore whether we should add testing code for
+  // UnresolvedUsingType and InjectedClassNameType.
+}
+
 TEST(Matcher, BindMatchedNodes) {
   DeclarationMatcher ClassX = has(recordDecl(hasName("::X")).bind("x"));
 
Index: include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- include/clang/ASTMatchers/ASTMatchersInternal.h
+++ include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -672,10 +672,22 @@
   /// matcher matches on it.
   bool matchesSpecialized(const QualType , ASTMatchFinder *Finder,
   BoundNodesTreeBuilder *Builder) const {
-/// FIXME: Add other ways to convert...
 if (Node.isNull())
   return false;
-return matchesDecl(Node->getAsTagDecl(), Finder, Builder);
+
+if (auto *TD = Node->getAsTagDecl())
+  return matchesDecl(TD, Finder, Builder);
+else if (auto *TT = Node->getAs())
+  return matchesDecl(TT->getDecl(), Finder, Builder);
+else if (auto *TTP = Node->getAs())
+  return matchesDecl(TTP->getDecl(), Finder, Builder);
+else if (auto *OCIT = Node->getAs())
+  return matchesDecl(OCIT->getDecl(), Finder, Builder);
+else if (auto *UUT = Node->getAs())
+  return matchesDecl(UUT->getDecl(), Finder, Builder);
+else if (auto *ICNT = Node->getAs())
+  return matchesDecl(ICNT->getDecl(), Finder, Builder);
+return false;
   }
 
   /// \brief Gets the TemplateDecl from a TemplateSpecializationType


Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -924,6 +924,15 @@
varDecl(hasType(namedDecl(hasName("S"));
 }
 
+TEST(TypeMatcher, MatchesDeclTypes) {
+  EXPECT_TRUE(matches("typedef int I; void f(I i);",
+  parmVarDecl(hasType(namedDecl(hasName("I"));
+
+  // FIXME: when we support ObjCInterfaceDecl, and TemplateTypeParmDecl, add
+  // testing code here. Explore whether we should add testing code for
+  // UnresolvedUsingType and InjectedClassNameType.
+}
+
 TEST(Matcher, BindMatchedNodes) {
   DeclarationMatcher ClassX = has(recordDecl(hasName("::X")).bind("x"));
 
Index: include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- include/clang/ASTMatchers/ASTMatchersInternal.h
+++ include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -672,10 +672,22 @@
   /// matcher matches on it.
   bool matchesSpecialized(const QualType , ASTMatchFinder *Finder,
   BoundNodesTreeBuilder *Builder) const {
-/// FIXME: Add other ways to convert...
 if (Node.isNull())
   return false;
-return matchesDecl(Node->getAsTagDecl(), Finder, Builder);
+
+if (auto *TD = Node->getAsTagDecl())
+  return matchesDecl(TD, Finder, Builder);
+else if (auto *TT = Node->getAs())
+  return matchesDecl(TT->getDecl(), Finder, Builder);
+else if (auto *TTP = Node->getAs())
+  return matchesDecl(TTP->getDecl(), Finder, Builder);
+else if (auto *OCIT = Node->getAs())
+  return matchesDecl(OCIT->getDecl(), Finder, Builder);
+else if (auto *UUT = 

[PATCH] D12734: Another patch for modernize-loop-convert.

2015-09-09 Thread Angel Garcia via cfe-commits
angelgarcia created this revision.
angelgarcia added a reviewer: klimek.
angelgarcia added subscribers: cfe-commits, alexfh.

1. Avoid converting loops that iterate over the size of a container and don't 
use its elements, as this would result in an unused-result warning.
2. Never capture the elements by value on lambdas, thus avoiding doing 
unnecessary copies and errors with non-copyable types.
3. The 'const auto &' instead of 'auto &' substitution on const containers now 
works on arrays and pseudoarrays as well.
4. The error about multiple replacements in the same macro call is now 
documented in the tests (not solved though).
5. Due to [1], I had to add a dummy usage of the range element (like "(void) 
*It;" or similars) on the tests that had empty loops.
6. I removed the braces from the CHECK comments. I think that there is no need 
for them, and they confuse vim.

http://reviews.llvm.org/D12734

Files:
  clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tidy/modernize/LoopConvertCheck.h
  clang-tidy/modernize/LoopConvertUtils.cpp
  test/clang-tidy/Inputs/modernize-loop-convert/structures.h
  test/clang-tidy/modernize-loop-convert-basic.cpp
  test/clang-tidy/modernize-loop-convert-extra.cpp
  test/clang-tidy/modernize-loop-convert-negative.cpp

Index: test/clang-tidy/modernize-loop-convert-negative.cpp
===
--- test/clang-tidy/modernize-loop-convert-negative.cpp
+++ test/clang-tidy/modernize-loop-convert-negative.cpp
@@ -290,7 +290,6 @@
 dependent v;
 dependent *pv;
 
-transparent cv;
 int Sum = 0;
 
 // Checks for the Index start and end:
@@ -473,3 +472,41 @@
 }
 
 } // namespace NegativeMultiEndCall
+
+namespace NoUsages {
+
+const int N = 6;
+int arr[N] = {1, 2, 3, 4, 5, 6};
+S s;
+dependent v;
+int Count = 0;
+
+void foo();
+
+void f() {
+  for (int I = 0; I < N; ++I) {}
+  for (int I = 0; I < N; ++I)
+printf("Hello world\n");
+  for (int I = 0; I < N; ++I)
+++Count;
+  for (int I = 0; I < N; ++I)
+foo();
+
+  for (S::iterator I = s.begin(), E = s.end(); I != E; ++I) {}
+  for (S::iterator I = s.begin(), E = s.end(); I != E; ++I)
+printf("Hello world\n");
+  for (S::iterator I = s.begin(), E = s.end(); I != E; ++I)
+++Count;
+  for (S::iterator I = s.begin(), E = s.end(); I != E; ++I)
+foo();
+
+  for (int I = 0; I < v.size(); ++I) {}
+  for (int I = 0; I < v.size(); ++I)
+printf("Hello world\n");
+  for (int I = 0; I < v.size(); ++I)
+++Count;
+  for (int I = 0; I < v.size(); ++I)
+foo();
+}
+
+} // namespace NoUsages
Index: test/clang-tidy/modernize-loop-convert-extra.cpp
===
--- test/clang-tidy/modernize-loop-convert-extra.cpp
+++ test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -14,10 +14,9 @@
 int b = arr[i][a];
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : arr) {
+  // CHECK-FIXES: for (auto & elem : arr)
   // CHECK-FIXES-NEXT: int a = 0;
   // CHECK-FIXES-NEXT: int b = elem[a];
-  // CHECK-FIXES-NEXT: }
 
   for (int j = 0; j < M; ++j) {
 int a = 0;
@@ -121,16 +120,16 @@
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto alias : IntArr)
-  // CHECK-FIXES-NEXT: if (alias) {
+  // CHECK-FIXES-NEXT: if (alias)
 
   for (unsigned i = 0; i < N; ++i) {
 while (int alias = IntArr[i]) {
   sideEffect(alias);
 }
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto alias : IntArr)
-  // CHECK-FIXES-NEXT: while (alias) {
+  // CHECK-FIXES-NEXT: while (alias)
 
   for (unsigned i = 0; i < N; ++i) {
 switch (int alias = IntArr[i]) {
@@ -140,32 +139,32 @@
   }
   // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto alias : IntArr)
-  // CHECK-FIXES-NEXT: switch (alias) {
+  // CHECK-FIXES-NEXT: switch (alias)
 
   for (unsigned i = 0; i < N; ++i) {
 for (int alias = IntArr[i]; alias < N; ++alias) {
   sideEffect(alias);
 }
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto alias : IntArr)
-  // CHECK-FIXES-NEXT: for (; alias < N; ++alias) {
+  // CHECK-FIXES-NEXT: for (; alias < N; ++alias)
 
   for (unsigned i = 0; i < N; ++i) {
 for (unsigned j = 0; int alias = IntArr[i]; ++j) {
   sideEffect(alias);
 }
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto alias : IntArr)
-  // CHECK-FIXES-NEXT: for (unsigned j = 0; alias; ++j) {
+  // CHECK-FIXES-NEXT: for (unsigned j = 0; alias; ++j)
 
   struct IntRef { IntRef(const int& i); };
   for (int i = 0; i < N; ++i) {
 IntRef Int(IntArr[i]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem 

Re: [PATCH] D10018: C11 _Bool bitfield diagnostic

2015-09-09 Thread Rachel Craik via cfe-commits
rcraik updated this revision to Diff 34339.
rcraik added a comment.

I've updated the message to make it a bit clearer that this is a portability 
concern. Are there any further concerns with this patch?


http://reviews.llvm.org/D10018

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  test/Misc/warning-flags.c
  test/Sema/c11-bitfield-width.c

Index: test/Sema/c11-bitfield-width.c
===
--- test/Sema/c11-bitfield-width.c
+++ test/Sema/c11-bitfield-width.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c11
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c99
+
+struct A {
+  _Bool : 0;// ok
+  _Bool : 3;// expected-warning {{size of anonymous bit-field (3 bits) exceeds the minimum width required to represent all valid values of that bit-field type}}
+  _Bool : 5;// expected-warning {{size of anonymous bit-field (5 bits) exceeds the minimum width required to represent all valid values of that bit-field type}}
+  _Bool : 7;// expected-warning {{size of anonymous bit-field (7 bits) exceeds the minimum width required to represent all valid values of that bit-field type}}
+  _Bool a : 1;  // ok
+  _Bool b : 2;  // expected-warning {{size of bit-field 'b' (2 bits) exceeds the minimum width required to represent all valid values of that bit-field type}}
+  _Bool c : 4;  // expected-warning {{size of bit-field 'c' (4 bits) exceeds the minimum width required to represent all valid values of that bit-field type}}
+  _Bool d : 8;  // expected-warning {{size of bit-field 'd' (8 bits) exceeds the minimum width required to represent all valid values of that bit-field type}}
+};
Index: test/Misc/warning-flags.c
===
--- test/Misc/warning-flags.c
+++ test/Misc/warning-flags.c
@@ -18,7 +18,7 @@
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (92):
+CHECK: Warnings without flags (90):
 CHECK-NEXT:   ext_excess_initializers
 CHECK-NEXT:   ext_excess_initializers_in_char_array_initializer
 CHECK-NEXT:   ext_expected_semi_decl_list
@@ -44,10 +44,8 @@
 CHECK-NEXT:   pp_pragma_sysheader_in_main_file
 CHECK-NEXT:   w_asm_qualifier_ignored
 CHECK-NEXT:   warn_accessor_property_type_mismatch
-CHECK-NEXT:   warn_anon_bitfield_width_exceeds_type_size
 CHECK-NEXT:   warn_arcmt_nsalloc_realloc
 CHECK-NEXT:   warn_asm_label_on_auto_decl
-CHECK-NEXT:   warn_bitfield_width_exceeds_type_size
 CHECK-NEXT:   warn_c_kext
 CHECK-NEXT:   warn_call_to_pure_virtual_member_function_from_ctor_dtor
 CHECK-NEXT:   warn_call_wrong_number_of_arguments
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -12604,6 +12604,20 @@
 Diag(FieldLoc, diag::warn_anon_bitfield_width_exceeds_type_size)
   << (unsigned)Value.getZExtValue() << (unsigned)TypeSize;
 }
+// C11 6.7.2.1p4 + footnote 122/C99 6.7.2.1p3 - the width of a bitfield
+// of type _Bool may be erroneous if it exceeds 1 bit.
+// Warn about _Bool bitfields > 1 bit as they will not be portable across
+// different platforms
+if ((getLangOpts().C11 || getLangOpts().C99) && 
+FieldTy->isBooleanType() &&
+Value.getZExtValue() > 1) {
+  if (FieldName)
+Diag(FieldLoc, diag::warn_bitfield_width_longer_than_necessary)
+<< FieldName << (unsigned)Value.getZExtValue();
+  else
+Diag(FieldLoc, diag::warn_anon_bitfield_width_longer_than_necessary)
+<< (unsigned)Value.getZExtValue();
+}
   }
 
   return BitWidth;
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -4317,14 +4317,20 @@
   "size of anonymous bit-field (%0 bits) exceeds size of its type (%1 bits)">;
 def err_incorrect_number_of_vector_initializers : Error<
   "number of elements must be either one or match the size of the vector">;
+def warn_bitfield_width_longer_than_necessary : Warning<
+  "size of bit-field %0 (%1 bits) exceeds the minimum width required to "
+  "represent all valid values of that bit-field type">, InGroup;
+def warn_anon_bitfield_width_longer_than_necessary : Warning<
+  "size of anonymous bit-field (%0 bits) exceeds the minimum width required to "
+  "represent all valid values of that bit-field type">, InGroup;
 
 // Used by C++ which allows bit-fields that are wider than the type.
 def warn_bitfield_width_exceeds_type_size: Warning<
   "size of bit-field %0 (%1 bits) exceeds the size of its type; value will be "
-  "truncated to %2 bits">;
+  "truncated to %2 bits">, InGroup;
 def warn_anon_bitfield_width_exceeds_type_size : Warning<
   "size of anonymous 

Re: r247049 - Module Debugging: Emit debug type information into clang modules.

2015-09-09 Thread Adrian Prantl via cfe-commits

> On Sep 8, 2015, at 8:05 PM, David Blaikie  wrote:
> 
> 
> 
> On Tue, Sep 8, 2015 at 12:20 PM, Adrian Prantl via cfe-commits 
> > wrote:
> Author: adrian
> Date: Tue Sep  8 14:20:27 2015
> New Revision: 247049
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=247049=rev 
> 
> Log:
> Module Debugging: Emit debug type information into clang modules.
> 
> When -fmodule-format is set to "obj", emit debug info for all types
> declared in a module or referenced by a declaration into the module's
> object file container.
> 
> This patch adds support for C and C++ types.
> 
> Added:
> cfe/trunk/test/Modules/Inputs/DebugCXX.h
> cfe/trunk/test/Modules/ModuleDebugInfo.cpp
> Modified:
> cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
> cfe/trunk/test/Modules/Inputs/module.map
> 
> Modified: cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp?rev=247049=247048=247049=diff
>  
> 
> ==
> --- cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp (original)
> +++ cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp Tue Sep  8 
> 14:20:27 2015
> @@ -50,6 +50,34 @@ class PCHContainerGenerator : public AST
>raw_pwrite_stream *OS;
>std::shared_ptr Buffer;
> 
> +  /// Visit every type and emit debug info for it.
> +  struct DebugTypeVisitor : public RecursiveASTVisitor {
> +clang::CodeGen::CGDebugInfo 
> +ASTContext 
> +DebugTypeVisitor(clang::CodeGen::CGDebugInfo , ASTContext )
> +: DI(DI), Ctx(Ctx) {}
> +
> +/// Determine whether this type can be represented in DWARF.
> +static bool CanRepresent(const Type *Ty) {
> +  return !Ty->isDependentType() && !Ty->isUndeducedType();
> +}
> +
> +bool VisitTypeDecl(TypeDecl *D) {
> 
> Does this only visit types defined in this module? Or also types otherwise 
> referenced by this module? (does it only visit definitions, or also 
> declarations?)

Currently this does the wrong thing and emits all types referenced by this 
module because the patch that emits fwddecls for external types is not yet 
committed (though expected to land soon).

>  
> +  QualType QualTy = Ctx.getTypeDeclType(D);
> +  if (!QualTy.isNull() && CanRepresent(QualTy.getTypePtr()))
> +DI.getOrCreateStandaloneType(QualTy, D->getLocation());
> +  return true;
> +}
> +
> +bool VisitValueDecl(ValueDecl *D) {
> 
> This seems strange - why would we put this type into the module debug info? 
> (the type may be defined elsewhere, in another module, etc - just because 
> there's a variable of that type defined in the module wouldn't imply that the 
> module should contain a definition of the type, would it? That would seem to 
> result in a lot of duplicate info)

CGDebugInfo eventually will only emit type definitions for types defined in the 
current module, but that said, I think your argument is correct and this can 
safely be removed.

>  
> +  QualType QualTy = D->getType();
> +  if (!QualTy.isNull() && CanRepresent(QualTy.getTypePtr()))
> +DI.getOrCreateStandaloneType(QualTy, D->getLocation());
> +  return true;
> +}
> +
> +  };
> +
>  public:
>PCHContainerGenerator(DiagnosticsEngine ,
>  const HeaderSearchOptions ,
> @@ -82,6 +110,36 @@ public:
>  *Ctx, HeaderSearchOpts, PreprocessorOpts, CodeGenOpts, *M, Diags));
>}
> 
> +  bool HandleTopLevelDecl(DeclGroupRef D) override {
> +if (Diags.hasErrorOccurred() ||
> +(CodeGenOpts.getDebugInfo() == CodeGenOptions::NoDebugInfo))
> +  return true;
> +
> +// Collect debug info for all decls in this group.
> +for (auto *I : D)
> +  if (!I->isFromASTFile()) {
> +DebugTypeVisitor DTV(*Builder->getModuleDebugInfo(), *Ctx);
> +DTV.TraverseDecl(I);
> +  }
> +return true;
> +  }
> +
> +  void HandleTagDeclDefinition(TagDecl *D) override {
> +if (Diags.hasErrorOccurred())
> 
> Is it particularly useful to check for errors here (& in 
> HandleTagDeclRequiredDefinition below)? That seems like a speed optimization 
> for the slow case (we're emitting diagnostics anyway, the speed isn't too 
> important - and we'll still have to be able to discard this work later in 
> case we haven't seen errors yet, but we do see them later/by the end of the 
> module?)

This is not a speed optimization but crash prevention. When compiling source 
with errors clang will still build an AST and continue as far as possible and 
the type system will contain unresolved types which are not handled by 
CGDebugInfo so we need to bail out 

Re: [PATCH] D12505: [X86] Set MaxVectorAlign for non-Darwin targets as well.

2015-09-09 Thread Eric Christopher via cfe-commits
echristo added a comment.

(This ACK btw means "yes we should do this on all platforms", not that it's 
necessarily safe on any platform, see my mail on the original thread).

-eric


http://reviews.llvm.org/D12505



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


Re: [PATCH] D12712: Implementation and testing for poisoning vtable ptr in dtor.

2015-09-09 Thread Naomi Musgrave via cfe-commits
nmusgrave updated this revision to Diff 34373.
nmusgrave added a comment.

- Cleaned up impl.


http://reviews.llvm.org/D12712

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenCXX/sanitize-dtor-derived-class.cpp
  test/CodeGenCXX/sanitize-dtor-vtable.cpp

Index: test/CodeGenCXX/sanitize-dtor-vtable.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-vtable.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+class A {
+ public:
+  int x;
+  A() {}
+  virtual ~A() {}
+};
+A a;
+
+// CHECK-LABEL: define {{.*}}AD2Ev
+// CHECK: call void @__sanitizer_dtor_callback
+// CHECK: call void @__sanitizer_dtor_callback{{.*}}i64 8
+// CHECK-NOT: call void @__sanitizer_dtor_callback
+// CHECK: ret void
Index: test/CodeGenCXX/sanitize-dtor-derived-class.cpp
===
--- test/CodeGenCXX/sanitize-dtor-derived-class.cpp
+++ test/CodeGenCXX/sanitize-dtor-derived-class.cpp
@@ -52,14 +52,17 @@
 // CHECK-NOT: call void @__sanitizer_dtor_callback
 // CHECK: ret void
 
+// Poison member and vtable pointer.
 // CHECK-LABEL: define {{.*}}BaseD2Ev
 // CHECK: call void @__sanitizer_dtor_callback
+// CHECK: call void @__sanitizer_dtor_callback
 // CHECK-NOT: call void @__sanitizer_dtor_callback
 // CHECK: ret void
 
+// Poison member and vtable pointer.
 // CHECK-LABEL: define {{.*}}DerivedD2Ev
 // CHECK: call void @__sanitizer_dtor_callback
 // CHECK-NOT: call void @__sanitizer_dtor_callback
 // CHECK: call void {{.*}}BaseD2Ev
-// CHECK-NOT: call void @__sanitizer_dtor_callback
+// CHECK: call void @__sanitizer_dtor_callback
 // CHECK: ret void
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -1648,11 +1648,15 @@
 }
   };
 
-  class SanitizeDtor final : public EHScopeStack::Cleanup {
+
+ static void Poison(CodeGenFunction , llvm::Value *OffsetPtr,
+CharUnits::QuantityType PoisonSize);
+
+  class SanitizeDtorMembers final : public EHScopeStack::Cleanup {
 const CXXDestructorDecl *Dtor;
 
   public:
-SanitizeDtor(const CXXDestructorDecl *Dtor) : Dtor(Dtor) {}
+SanitizeDtorMembers(const CXXDestructorDecl *Dtor) : Dtor(Dtor) {}
 
 // Generate function call for handling object poisoning.
 // Disables tail call elimination, to prevent the current stack frame
@@ -1684,11 +1688,11 @@
   // Currently on the last field, and it must be poisoned with the
   // current block.
   if (fieldIndex == Layout.getFieldCount() - 1) {
-PoisonBlock(CGF, startIndex, Layout.getFieldCount());
+PoisonMembers(CGF, startIndex, Layout.getFieldCount());
   }
 } else if (startIndex >= 0) {
   // No longer within a block of memory to poison, so poison the block
-  PoisonBlock(CGF, startIndex, fieldIndex);
+  PoisonMembers(CGF, startIndex, fieldIndex);
   // Re-set the start index
   startIndex = -1;
 }
@@ -1701,7 +1705,7 @@
 /// start poisoning (inclusive)
 /// \param layoutEndOffset index of the ASTRecordLayout field to
 /// end poisoning (exclusive)
-void PoisonBlock(CodeGenFunction , unsigned layoutStartOffset,
+void PoisonMembers(CodeGenFunction , unsigned layoutStartOffset,
  unsigned layoutEndOffset) {
   ASTContext  = CGF.getContext();
   const ASTRecordLayout  =
@@ -1732,20 +1736,46 @@
   if (PoisonSize == 0)
 return;
 
-  // Pass in void pointer and size of region as arguments to runtime
-  // function
-  llvm::Value *Args[] = {CGF.Builder.CreateBitCast(OffsetPtr, CGF.VoidPtrTy),
- llvm::ConstantInt::get(CGF.SizeTy, PoisonSize)};
+  Poison(CGF, OffsetPtr, PoisonSize);
+}
+  };
+
+ class SanitizeDtorVTable final : public EHScopeStack::Cleanup {
+const CXXDestructorDecl *Dtor;
 
-  llvm::Type *ArgTypes[] = {CGF.VoidPtrTy, CGF.SizeTy};
+  public:
+SanitizeDtorVTable(const CXXDestructorDecl *Dtor) : Dtor(Dtor) {}
+
+// Generate function call for handling vtable pointer poisoning.
+void Emit(CodeGenFunction , Flags flags) override {
+  assert(Dtor->getParent()->isDynamicClass());
+  ASTContext  = CGF.getContext();
+  // Poison vtable and vtable ptr if they exist for this class.
+  llvm::Value *VTablePtr = CGF.LoadCXXThis();
 
-  llvm::FunctionType *FnType =
-  llvm::FunctionType::get(CGF.VoidTy, ArgTypes, false);
-  llvm::Value *Fn =
-  CGF.CGM.CreateRuntimeFunction(FnType, "__sanitizer_dtor_callback");
-  

r247218 - Fix Clang-tidy misc-use-override warnings, other minor fixes

2015-09-09 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Wed Sep  9 19:24:40 2015
New Revision: 247218

URL: http://llvm.org/viewvc/llvm-project?rev=247218=rev
Log:
Fix Clang-tidy misc-use-override warnings, other minor fixes

Patch by Eugene Zelenko!

Differential Revision: http://reviews.llvm.org/D12741

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/lib/Frontend/PCHContainerOperations.cpp

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=247218=247217=247218=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Sep  9 19:24:40 2015
@@ -30,6 +30,7 @@
 #include "llvm/Support/TargetParser.h"
 #include 
 #include 
+
 using namespace clang;
 
 
//===--===//
@@ -739,7 +740,7 @@ namespace {
 template 
 class WebAssemblyOSTargetInfo : public OSTargetInfo {
   void getOSDefines(const LangOptions , const llvm::Triple ,
-MacroBuilder ) const override final {
+MacroBuilder ) const final {
 // A common platform macro.
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
@@ -749,7 +750,7 @@ class WebAssemblyOSTargetInfo : public O
   }
 
   // As an optimization, group static init code together in a section.
-  const char *getStaticInitSectionSpecifier() const override final {
+  const char *getStaticInitSectionSpecifier() const final {
 return ".text.__startup";
   }
 
@@ -7011,13 +7012,13 @@ private:
   Features["simd128"] = true;
 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
   }
-  bool hasFeature(StringRef Feature) const override final {
+  bool hasFeature(StringRef Feature) const final {
 return llvm::StringSwitch(Feature)
 .Case("simd128", SIMDLevel >= SIMD128)
 .Default(false);
   }
   bool handleTargetFeatures(std::vector ,
-DiagnosticsEngine ) override final {
+DiagnosticsEngine ) final {
 for (const auto  : Features) {
   if (Feature == "+simd128") {
 SIMDLevel = std::max(SIMDLevel, SIMD128);
@@ -7034,7 +7035,7 @@ private:
 }
 return true;
   }
-  bool setCPU(const std::string ) override final {
+  bool setCPU(const std::string ) final {
 return llvm::StringSwitch(Name)
   .Case("mvp",   true)
   .Case("bleeding-edge", true)
@@ -7042,32 +7043,32 @@ private:
   .Default(false);
   }
   void getTargetBuiltins(const Builtin::Info *,
- unsigned ) const override final {
+ unsigned ) const final {
 Records = BuiltinInfo;
 NumRecords = clang::WebAssembly::LastTSBuiltin - Builtin::FirstTSBuiltin;
   }
-  BuiltinVaListKind getBuiltinVaListKind() const override final {
+  BuiltinVaListKind getBuiltinVaListKind() const final {
 // TODO: Implement va_list properly.
 return VoidPtrBuiltinVaList;
   }
   void getGCCRegNames(const char *const *,
-  unsigned ) const override final {
+  unsigned ) const final {
 Names = nullptr;
 NumNames = 0;
   }
   void getGCCRegAliases(const GCCRegAlias *,
-unsigned ) const override final {
+unsigned ) const final {
 Aliases = nullptr;
 NumAliases = 0;
   }
   bool
   validateAsmConstraint(const char *,
-TargetInfo::ConstraintInfo ) const override final 
{
+TargetInfo::ConstraintInfo ) const final {
 return false;
   }
-  const char *getClobbers() const override final { return ""; }
-  bool isCLZForZeroUndef() const override final { return false; }
-  bool hasInt128Type() const override final { return true; }
+  const char *getClobbers() const final { return ""; }
+  bool isCLZForZeroUndef() const final { return false; }
+  bool hasInt128Type() const final { return true; }
 };
 
 const Builtin::Info WebAssemblyTargetInfo::BuiltinInfo[] = {

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=247218=247217=247218=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed Sep  9 19:24:40 2015
@@ -59,7 +59,7 @@ public:
   virtual const VarDecl *getThreadIDVariable() const = 0;
 
   /// \brief Emit the captured statement body.
-  virtual void EmitBody(CodeGenFunction , const Stmt *S) override;
+  void EmitBody(CodeGenFunction , const Stmt *S) override;
 
   /// \brief Get an LValue for the 

Re: [PATCH] D12741: [Clang] Fix Clang-tidy misc-use-override warnings, other minor fixes

2015-09-09 Thread Hans Wennborg via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL247218: Fix Clang-tidy misc-use-override warnings, other 
minor fixes (authored by hans).

Changed prior to commit:
  http://reviews.llvm.org/D12741?vs=34385=34393#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D12741

Files:
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
  cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  cfe/trunk/lib/Driver/ToolChains.h
  cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
  cfe/trunk/lib/Frontend/PCHContainerOperations.cpp

Index: cfe/trunk/lib/Driver/ToolChains.h
===
--- cfe/trunk/lib/Driver/ToolChains.h
+++ cfe/trunk/lib/Driver/ToolChains.h
@@ -923,7 +923,7 @@
  const llvm::opt::ArgList );
   ~SHAVEToolChain() override;
 
-  virtual Tool *SelectTool(const JobAction ) const override;
+  Tool *SelectTool(const JobAction ) const override;
 
 protected:
   Tool *getTool(Action::ActionClass AC) const override;
@@ -960,4 +960,4 @@
 } // end namespace driver
 } // end namespace clang
 
-#endif
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H
Index: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
@@ -606,7 +606,7 @@
 
   /// \brief Puts all tokens into a single line.
   unsigned formatLine(const AnnotatedLine , unsigned FirstIndent,
-  bool DryRun) {
+  bool DryRun) override {
 unsigned Penalty = 0;
 LineState State = Indenter->getInitialState(FirstIndent, , DryRun);
 while (State.NextToken) {
@@ -629,7 +629,7 @@
   /// \brief Formats the line by finding the best line breaks with line lengths
   /// below the column limit.
   unsigned formatLine(const AnnotatedLine , unsigned FirstIndent,
-  bool DryRun) {
+  bool DryRun) override {
 LineState State = Indenter->getInitialState(FirstIndent, , DryRun);
 
 // If the ObjC method declaration does not fit on a line, we should format
@@ -791,7 +791,7 @@
   llvm::SpecificBumpPtrAllocator Allocator;
 };
 
-} // namespace
+} // anonymous namespace
 
 unsigned
 UnwrappedLineFormatter::format(const SmallVectorImpl ,
Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -30,6 +30,7 @@
 #include "llvm/Support/TargetParser.h"
 #include 
 #include 
+
 using namespace clang;
 
 //===--===//
@@ -739,7 +740,7 @@
 template 
 class WebAssemblyOSTargetInfo : public OSTargetInfo {
   void getOSDefines(const LangOptions , const llvm::Triple ,
-MacroBuilder ) const override final {
+MacroBuilder ) const final {
 // A common platform macro.
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
@@ -749,7 +750,7 @@
   }
 
   // As an optimization, group static init code together in a section.
-  const char *getStaticInitSectionSpecifier() const override final {
+  const char *getStaticInitSectionSpecifier() const final {
 return ".text.__startup";
   }
 
@@ -7011,13 +7012,13 @@
   Features["simd128"] = true;
 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
   }
-  bool hasFeature(StringRef Feature) const override final {
+  bool hasFeature(StringRef Feature) const final {
 return llvm::StringSwitch(Feature)
 .Case("simd128", SIMDLevel >= SIMD128)
 .Default(false);
   }
   bool handleTargetFeatures(std::vector ,
-DiagnosticsEngine ) override final {
+DiagnosticsEngine ) final {
 for (const auto  : Features) {
   if (Feature == "+simd128") {
 SIMDLevel = std::max(SIMDLevel, SIMD128);
@@ -7034,40 +7035,40 @@
 }
 return true;
   }
-  bool setCPU(const std::string ) override final {
+  bool setCPU(const std::string ) final {
 return llvm::StringSwitch(Name)
   .Case("mvp",   true)
   .Case("bleeding-edge", true)
   .Case("generic",   true)
   .Default(false);
   }
   void getTargetBuiltins(const Builtin::Info *,
- unsigned ) const override final {
+ unsigned ) const final {
 Records = BuiltinInfo;
 NumRecords = clang::WebAssembly::LastTSBuiltin - Builtin::FirstTSBuiltin;
   }
-  BuiltinVaListKind getBuiltinVaListKind() const override final {
+  BuiltinVaListKind getBuiltinVaListKind() const final {
 // TODO: Implement va_list properly.
 return VoidPtrBuiltinVaList;
   }
   void getGCCRegNames(const char *const *,
-  unsigned ) const override final {
+   

Re: [PATCH] D12471: Correct documentation for numSelectorArgs matcher

2015-09-09 Thread Dave Lee via cfe-commits
kastiglione added a comment.

Thank you @klimek.


http://reviews.llvm.org/D12471



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


Re: [PATCH] D10414: Attach function attribute "arm-restrict-it" instead of passing arm-restrict-it as a backend-option

2015-09-09 Thread Akira Hatanaka via cfe-commits
ahatanak updated this revision to Diff 34379.
ahatanak added a comment.

Based on the feedback from reviewers for the llvm patch 
(http://reviews.llvm.org/D10416), I made changes to fix the handling of 
-mrestrict-it and -mno-restrict-it in the driver. The driver now passes 
subtarget feature "restrict-it"  if the target requires it (target is windows 
or armv8) or -mrestrict-it is on the command line and -mno-restrict-it doesn't 
appear after it. The end-user can no longer use -mno-restrict-it to instruct 
the backend to emit the deprecated (unrestricted) forms of IT blocks when 
targeting windows or armv8.


http://reviews.llvm.org/D10414

Files:
  lib/Driver/Tools.cpp
  test/Driver/arm-restrict-it.c
  test/Driver/woa-restrict-it.c

Index: test/Driver/woa-restrict-it.c
===
--- test/Driver/woa-restrict-it.c
+++ test/Driver/woa-restrict-it.c
@@ -1,4 +1,4 @@
-// RUN: %clang -target armv7-windows -### %s 2>&1 | FileCheck %s
-
-// CHECK: "-backend-option" "-arm-restrict-it"
+// RUN: %clang -target armv7-windows -### %s 2>&1 | FileCheck 
--check-prefix=CHECK-RESTRICTED %s
+// RUN: %clang -target armv7-windows -mno-restrict-it -### %s 2>&1 | FileCheck 
--check-prefix=CHECK-RESTRICTED %s
 
+// CHECK-RESTRICTED: "-target-feature" "+restrict-it"
Index: test/Driver/arm-restrict-it.c
===
--- test/Driver/arm-restrict-it.c
+++ test/Driver/arm-restrict-it.c
@@ -1,15 +1,21 @@
-// RUN: %clang -target arm-none-gnueabi -mrestrict-it -### %s 2> %t
+// RUN: %clang -target arm-none-gnueabi -mno-restrict-it -mrestrict-it -### %s 
2> %t
 // RUN: FileCheck --check-prefix=CHECK-RESTRICTED < %t %s
 
-// RUN: %clang -target armv8a-none-gnueabi -mrestrict-it -### %s 2> %t
+// RUN: %clang -target armv8-none-gnueabi -mno-restrict-it -### %s 2> %t
 // RUN: FileCheck --check-prefix=CHECK-RESTRICTED < %t %s
 
-// CHECK-RESTRICTED: "-backend-option" "-arm-restrict-it"
+// RUN: %clang -target armv8a-none-gnueabi -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-RESTRICTED < %t %s
+
+// RUN: %clang -target armv8a-none-gnueabi -mno-restrict-it -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-RESTRICTED < %t %s
+
+// CHECK-RESTRICTED: "-target-feature" "+restrict-it"
 
 // RUN: %clang -target arm-none-gnueabi -mno-restrict-it -### %s 2> %t
 // RUN: FileCheck --check-prefix=CHECK-NO-RESTRICTED < %t %s
 
-// RUN: %clang -target armv8a-none-gnueabi -mno-restrict-it -### %s 2> %t
+// RUN: %clang -target arm-none-gnueabi -### %s 2> %t
 // RUN: FileCheck --check-prefix=CHECK-NO-RESTRICTED < %t %s
 
-// CHECK-NO-RESTRICTED: "-backend-option" "-arm-no-restrict-it"
+// CHECK-NO-RESTRICTED-NOT: "-target-feature" "+restrict-it"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -795,10 +795,21 @@
   Features.push_back("-crc");
   }
 
-  if (Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v8_1a) {
+  auto SubArch = Triple.getSubArch();
+
+  if (SubArch == llvm::Triple::SubArchType::ARMSubArch_v8_1a) {
 Features.insert(Features.begin(), "+v8.1a");
   }
 
+  // Windows on ARM and ARMv8 expect restricted IT blocks.
+  if (Triple.isOSWindows() ||
+  SubArch == llvm::Triple::SubArchType::ARMSubArch_v8 ||
+  SubArch == llvm::Triple::SubArchType::ARMSubArch_v8_1a)
+Features.push_back("+restrict-it");
+  else if (Args.hasFlag(options::OPT_mrestrict_it, 
options::OPT_mno_restrict_it,
+false))
+Features.push_back("+restrict-it");
+
   // Look for the last occurrence of -mlong-calls or -mno-long-calls. If
   // neither options are specified, see if we are compiling for kernel/kext and
   // decide whether to pass "+long-calls" based on the OS and its version.
@@ -4366,23 +4377,6 @@
 break;
   }
 
-  if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
-   options::OPT_mno_restrict_it)) {
-if (A->getOption().matches(options::OPT_mrestrict_it)) {
-  CmdArgs.push_back("-backend-option");
-  CmdArgs.push_back("-arm-restrict-it");
-} else {
-  CmdArgs.push_back("-backend-option");
-  CmdArgs.push_back("-arm-no-restrict-it");
-}
-  } else if (Triple.isOSWindows() &&
- (Triple.getArch() == llvm::Triple::arm ||
-  Triple.getArch() == llvm::Triple::thumb)) {
-// Windows on ARM expects restricted IT blocks
-CmdArgs.push_back("-backend-option");
-CmdArgs.push_back("-arm-restrict-it");
-  }
-
   // Forward -f options with positive and negative forms; we translate
   // these by hand.
   if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) {


Index: test/Driver/woa-restrict-it.c
===
--- test/Driver/woa-restrict-it.c
+++ test/Driver/woa-restrict-it.c
@@ -1,4 +1,4 @@
-// RUN: %clang -target armv7-windows -### %s 

Re: r246229 - [X86] Conditionalize Darwin MaxVectorAlign on the presence of AVX.

2015-09-09 Thread Eric Christopher via cfe-commits
On Mon, Aug 31, 2015 at 4:03 PM Ahmed Bougacha 
wrote:

> On Thu, Aug 27, 2015 at 7:19 PM, Eric Christopher 
> wrote:
>
>> Hi Ahmed,
>>
>> A quick note: I think this is going to fail in the presence of the target
>> attribute. I.e. if someone decorates a function with
>> __attribute__((target("avx512"))) this is unlikely to catch that.
>>
>
> You're right; any ideas on how to handle this? In particular, has any of
> IRGen (except attributes of course) needed to know about it until know?
> IIRC it's directly lowered to IR function attributes, so this sounds like a
> big change. Worst case we can restore the unconditional max alignment?
>
>

This is harder. I mean, right now we depend ABI based on the command line
options for the whole file which seems reasonable from a calling convention
standpoint. I think right now you could construct an unaligned vector
testcase and use it with a builtin?

I think we can get it to where you can look at a function and get the
proper feature set for it in short order - I'm working on that anyhow,
right now it would be messy though.

What would you like to do about this right now though?


> Also, should we do this for all of the x86 OSes?
>>
>
> I'm not sure: MaxVectorAlign was only set for the Darwin targets, but I
> think it would make sense everywhere.
> Let's see what people say: http://reviews.llvm.org/D12505
>
>
I've ack'd that. Thanks for doing it.

-eric


> Thanks for the comments!
> -Ahmed
>
>
>> -eric
>>
>> On Thu, Aug 27, 2015 at 3:31 PM Ahmed Bougacha via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: ab
>>> Date: Thu Aug 27 17:30:38 2015
>>> New Revision: 246229
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=246229=rev
>>> Log:
>>> [X86] Conditionalize Darwin MaxVectorAlign on the presence of AVX.
>>>
>>> There's no point in using a larger alignment if we have no instructions
>>> that would benefit from it.
>>>
>>> Differential Revision: http://reviews.llvm.org/D12389
>>>
>>> Modified:
>>> cfe/trunk/lib/Basic/Targets.cpp
>>> cfe/trunk/test/CodeGen/vector-alignment.c
>>>
>>> Modified: cfe/trunk/lib/Basic/Targets.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=246229=246228=246229=diff
>>>
>>> ==
>>> --- cfe/trunk/lib/Basic/Targets.cpp (original)
>>> +++ cfe/trunk/lib/Basic/Targets.cpp Thu Aug 27 17:30:38 2015
>>> @@ -3629,13 +3629,21 @@ public:
>>>  LongDoubleWidth = 128;
>>>  LongDoubleAlign = 128;
>>>  SuitableAlign = 128;
>>> -MaxVectorAlign = 256;
>>>  SizeType = UnsignedLong;
>>>  IntPtrType = SignedLong;
>>>  DataLayoutString = "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128";
>>>  HasAlignMac68kSupport = true;
>>>}
>>>
>>> +  bool handleTargetFeatures(std::vector ,
>>> +DiagnosticsEngine ) override {
>>> +if
>>> (!DarwinTargetInfo::handleTargetFeatures(Features,
>>> +
>>> Diags))
>>> +  return false;
>>> +// Now that we know if we have AVX, we can decide how to align
>>> vectors.
>>> +MaxVectorAlign = hasFeature("avx") ? 256 : 128;
>>> +return true;
>>> +  }
>>>  };
>>>
>>>  // x86-32 Windows target
>>> @@ -3986,13 +3994,22 @@ public:
>>>DarwinX86_64TargetInfo(const llvm::Triple )
>>>: DarwinTargetInfo(Triple) {
>>>  Int64Type = SignedLongLong;
>>> -MaxVectorAlign = 256;
>>>  // The 64-bit iOS simulator uses the builtin bool type for
>>> Objective-C.
>>>  llvm::Triple T = llvm::Triple(Triple);
>>>  if (T.isiOS())
>>>UseSignedCharForObjCBool = false;
>>>  DataLayoutString = "e-m:o-i64:64-f80:128-n8:16:32:64-S128";
>>>}
>>> +
>>> +  bool handleTargetFeatures(std::vector ,
>>> +DiagnosticsEngine ) override {
>>> +if
>>> (!DarwinTargetInfo::handleTargetFeatures(Features,
>>> +
>>> Diags))
>>> +  return false;
>>> +// Now that we know if we have AVX, we can decide how to align
>>> vectors.
>>> +MaxVectorAlign = hasFeature("avx") ? 256 : 128;
>>> +return true;
>>> +  }
>>>  };
>>>
>>>  class OpenBSDX86_64TargetInfo : public
>>> OpenBSDTargetInfo {
>>>
>>> Modified: cfe/trunk/test/CodeGen/vector-alignment.c
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vector-alignment.c?rev=246229=246228=246229=diff
>>>
>>> ==
>>> --- cfe/trunk/test/CodeGen/vector-alignment.c (original)
>>> +++ cfe/trunk/test/CodeGen/vector-alignment.c Thu Aug 27 17:30:38 2015
>>> @@ -1,38 +1,51 @@
>>> -// RUN: %clang_cc1 -w -triple x86_64-apple-darwin10 -emit-llvm -o - %s
>>> | FileCheck %s
>>> +// RUN: %clang_cc1 -w -triple x86_64-apple-darwin10 \
>>> +// RUN:  -emit-llvm -o - %s | FileCheck %s --check-prefix=ALL
>>> --check-prefix=SSE
>>> +// RUN: %clang_cc1 -w -triple   i386-apple-darwin10 \
>>> +// RUN:  -emit-llvm -o 

Re: [PATCH] D12462: [PATCH] [clang-tidy] Add inconsistent declaration parameter name check

2015-09-09 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good now. 
Thank you for the hard work! I'll commit the patch for you.


http://reviews.llvm.org/D12462



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


[PATCH] D12743: [CodeGen] Teach SimplifyPersonality about the updated LandingPadInst

2015-09-09 Thread Vedant Kumar via cfe-commits
vsk created this revision.
vsk added reviewers: majnemer, rjmccall.
vsk added a subscriber: cfe-commits.

When personality function references were moved from LandingPadInst to  
 
Function, we forgot to update SimplifyPersonality(). This is an 
 
optimization which replaces personality functions with the default C++  
 
personality if it has only C++-style uses. As a result, some ObjC++ 
 
projects could no longer link against C++ libraries (seeing as the  
 
exception ABI had effectively changed).

http://reviews.llvm.org/D12743

Files:
  lib/CodeGen/CGException.cpp
  test/CodeGenObjCXX/exception-cxx.mm

Index: test/CodeGenObjCXX/exception-cxx.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/exception-cxx.mm
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -emit-llvm -fcxx-exceptions -fexceptions -fobjc-exceptions -o - %s | FileCheck %s
+
+// rdar://problem/22155434
+namespace test0 {
+  void foo() {
+try {
+  throw 0;
+} catch (...) {
+  return;
+}
+  }
+// CHECK: define void @_ZN5test03fooEv() #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+}
Index: lib/CodeGen/CGException.cpp
===
--- lib/CodeGen/CGException.cpp
+++ lib/CodeGen/CGException.cpp
@@ -229,6 +229,36 @@
   return llvm::ConstantExpr::getBitCast(Fn, CGM.Int8PtrTy);
 }
 
+/// Check whether a landingpad instruction uses any non-C++ features.
+static bool LandingPadHasOnlyCXXUses(llvm::LandingPadInst *LPI) {
+  for (unsigned I = 0, E = LPI->getNumClauses(); I != E; ++I) {
+// Look for something that would've been returned by the ObjC
+// runtime's GetEHType() method.
+llvm::Value *Val = LPI->getClause(I)->stripPointerCasts();
+if (LPI->isCatch(I)) {
+  // Check if the catch value has the ObjC prefix.
+  if (llvm::GlobalVariable *GV = dyn_cast(Val))
+// ObjC EH selector entries are always global variables with
+// names starting like this.
+if (GV->getName().startswith("OBJC_EHTYPE"))
+  return false;
+} else {
+  // Check if any of the filter values have the ObjC prefix.
+  llvm::Constant *CVal = cast(Val);
+  for (llvm::User::op_iterator
+  II = CVal->op_begin(), IE = CVal->op_end(); II != IE; ++II) {
+if (llvm::GlobalVariable *GV =
+cast((*II)->stripPointerCasts()))
+  // ObjC EH selector entries are always global variables with
+  // names starting like this.
+  if (GV->getName().startswith("OBJC_EHTYPE"))
+return false;
+  }
+}
+  }
+  return true;
+}
+
 /// Check whether a personality function could reasonably be swapped
 /// for a C++ personality function.
 static bool PersonalityHasOnlyCXXUses(llvm::Constant *Fn) {
@@ -241,34 +271,14 @@
   continue;
 }
 
-// Otherwise, it has to be a landingpad instruction.
-llvm::LandingPadInst *LPI = dyn_cast(U);
-if (!LPI) return false;
-
-for (unsigned I = 0, E = LPI->getNumClauses(); I != E; ++I) {
-  // Look for something that would've been returned by the ObjC
-  // runtime's GetEHType() method.
-  llvm::Value *Val = LPI->getClause(I)->stripPointerCasts();
-  if (LPI->isCatch(I)) {
-// Check if the catch value has the ObjC prefix.
-if (llvm::GlobalVariable *GV = dyn_cast(Val))
-  // ObjC EH selector entries are always global variables with
-  // names starting like this.
-  if (GV->getName().startswith("OBJC_EHTYPE"))
-return false;
-  } else {
-// Check if any of the filter values have the ObjC prefix.
-llvm::Constant *CVal = cast(Val);
-for (llvm::User::op_iterator
-   II = CVal->op_begin(), IE = CVal->op_end(); II != IE; ++II) {
-  if (llvm::GlobalVariable *GV =
-  cast((*II)->stripPointerCasts()))
-// ObjC EH selector entries are always global variables with
-// names starting like this.
-if (GV->getName().startswith("OBJC_EHTYPE"))
-  return false;
-}
-  }
+// Otherwise it must be a function.
+llvm::Function *F = dyn_cast(U);
+if (!U) return false;
+
+for (auto BB = F->begin(), E = F->end(); BB != E; ++BB) {
+  if (BB->isLandingPad())
+if (!LandingPadHasOnlyCXXUses(BB->getLandingPadInst()))
+  return false;
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12505: [X86] Set MaxVectorAlign for non-Darwin targets as well.

2015-09-09 Thread Eric Christopher via cfe-commits
echristo accepted this revision.
echristo added a comment.
This revision is now accepted and ready to land.

This seems reasonable to me, I can't see why it wouldn't be ok.

Thanks!

-eric


http://reviews.llvm.org/D12505



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


[PATCH] D12739: [CUDA] Allow trivial constructors as initializer for __shared__ variables.

2015-09-09 Thread Artem Belevich via cfe-commits
tra created this revision.
tra added reviewers: jingyue, eliben, wengxt, jholewinski.
tra added a subscriber: cfe-commits.

r245786 (D12241) disabled all initializers for __shared__ variables. It also 
prevents placement of records in __shared__ space as they have constructor as 
their initializer.





http://reviews.llvm.org/D12739

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenCUDA/address-spaces.cu

Index: test/CodeGenCUDA/address-spaces.cu
===
--- test/CodeGenCUDA/address-spaces.cu
+++ test/CodeGenCUDA/address-spaces.cu
@@ -25,6 +25,8 @@
 // CHECK: @_ZZ5func3vE1a = internal addrspace(3) global float 0.00e+00
 // CHECK: @_ZZ5func4vE1a = internal addrspace(3) global float 0.00e+00
 // CHECK: @b = addrspace(3) global float undef
+// CHECK: @c = addrspace(3) global %struct.c undef
+// CHECK  @d = addrspace(3) global %struct.d undef
 
 __device__ void foo() {
   // CHECK: load i32, i32* addrspacecast (i32 addrspace(1)* @i to i32*)
@@ -117,3 +119,15 @@
   return t.getData();
 // CHECK: call i32 @_ZN14StructWithCtor7getDataEv(%struct.StructWithCtor* 
addrspacecast (%struct.StructWithCtor addrspace(3)* 
@_ZZ23construct_shared_structvE1t to %struct.StructWithCtor*))
 }
+
+// Make sure we allow __shared__ structures with default or empty constructors.
+struct c {
+  int i;
+};
+__shared__ struct c c;
+
+struct d {
+  int i;
+  d() {}
+};
+__shared__ struct d d;
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2151,8 +2151,10 @@
   if (getLangOpts().CPlusPlus && getLangOpts().CUDAIsDevice
   && D->hasAttr()) {
 if (InitExpr) {
-  Error(D->getLocation(),
-"__shared__ variable cannot have an initialization.");
+  const auto *C = dyn_cast(InitExpr);
+  if (C == nullptr || !C->getConstructor()->hasTrivialBody())
+Error(D->getLocation(),
+  "__shared__ variable cannot have an initialization.");
 }
 Init = llvm::UndefValue::get(getTypes().ConvertType(ASTTy));
   } else if (!InitExpr) {


Index: test/CodeGenCUDA/address-spaces.cu
===
--- test/CodeGenCUDA/address-spaces.cu
+++ test/CodeGenCUDA/address-spaces.cu
@@ -25,6 +25,8 @@
 // CHECK: @_ZZ5func3vE1a = internal addrspace(3) global float 0.00e+00
 // CHECK: @_ZZ5func4vE1a = internal addrspace(3) global float 0.00e+00
 // CHECK: @b = addrspace(3) global float undef
+// CHECK: @c = addrspace(3) global %struct.c undef
+// CHECK  @d = addrspace(3) global %struct.d undef
 
 __device__ void foo() {
   // CHECK: load i32, i32* addrspacecast (i32 addrspace(1)* @i to i32*)
@@ -117,3 +119,15 @@
   return t.getData();
 // CHECK: call i32 @_ZN14StructWithCtor7getDataEv(%struct.StructWithCtor* addrspacecast (%struct.StructWithCtor addrspace(3)* @_ZZ23construct_shared_structvE1t to %struct.StructWithCtor*))
 }
+
+// Make sure we allow __shared__ structures with default or empty constructors.
+struct c {
+  int i;
+};
+__shared__ struct c c;
+
+struct d {
+  int i;
+  d() {}
+};
+__shared__ struct d d;
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2151,8 +2151,10 @@
   if (getLangOpts().CPlusPlus && getLangOpts().CUDAIsDevice
   && D->hasAttr()) {
 if (InitExpr) {
-  Error(D->getLocation(),
-"__shared__ variable cannot have an initialization.");
+  const auto *C = dyn_cast(InitExpr);
+  if (C == nullptr || !C->getConstructor()->hasTrivialBody())
+Error(D->getLocation(),
+  "__shared__ variable cannot have an initialization.");
 }
 Init = llvm::UndefValue::get(getTypes().ConvertType(ASTTy));
   } else if (!InitExpr) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12741: [Clang] Fix Clang-tidy misc-use-override warnings, other minor fixes

2015-09-09 Thread Hans Wennborg via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rL LLVM

http://reviews.llvm.org/D12741



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


r247203 - convert builtin_unpredictable on a switch into metadata for LLVM

2015-09-09 Thread Sanjay Patel via cfe-commits
Author: spatel
Date: Wed Sep  9 17:39:06 2015
New Revision: 247203

URL: http://llvm.org/viewvc/llvm-project?rev=247203=rev
Log:
convert builtin_unpredictable on a switch into metadata for LLVM

Modified:
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/test/CodeGen/builtin-unpredictable.c

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=247203=247202=247203=diff
==
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Wed Sep  9 17:39:06 2015
@@ -16,6 +16,7 @@
 #include "CodeGenModule.h"
 #include "TargetInfo.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/PrettyStackTrace.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Sema/LoopHint.h"
@@ -25,6 +26,8 @@
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/InlineAsm.h"
 #include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/MDBuilder.h"
+
 using namespace clang;
 using namespace CodeGen;
 
@@ -1517,6 +1520,22 @@ void CodeGenFunction::EmitSwitchStmt(con
   EmitBlock(SwitchExit.getBlock(), true);
   incrementProfileCounter();
 
+  // If the switch has a condition wrapped by __builtin_unpredictable,
+  // create metadata that specifies that the switch is unpredictable.
+  // Don't bother if not optimizing because that metadata would not be used.
+  if (CGM.getCodeGenOpts().OptimizationLevel != 0) {
+if (const CallExpr *Call = dyn_cast(S.getCond())) {
+  const Decl *TargetDecl = Call->getCalleeDecl();
+  if (const FunctionDecl *FD = dyn_cast_or_null(TargetDecl)) 
{
+if (FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) {
+  llvm::MDBuilder MDHelper(getLLVMContext());
+  SwitchInsn->setMetadata(llvm::LLVMContext::MD_unpredictable,
+  MDHelper.createUnpredictable());
+}
+  }
+}
+  }
+
   if (SwitchWeights) {
 assert(SwitchWeights->size() == 1 + SwitchInsn->getNumCases() &&
"switch weights do not match switch cases");

Modified: cfe/trunk/test/CodeGen/builtin-unpredictable.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-unpredictable.c?rev=247203=247202=247203=diff
==
--- cfe/trunk/test/CodeGen/builtin-unpredictable.c (original)
+++ cfe/trunk/test/CodeGen/builtin-unpredictable.c Wed Sep  9 17:39:06 2015
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O1 | 
FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm 
-disable-llvm-optzns -o - %s -O1 | FileCheck %s
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O0 | 
FileCheck %s --check-prefix=CHECK_O0
 
 // When optimizing, the builtin should be converted to metadata.
@@ -11,7 +11,6 @@ void branch(int x) {
 
 // CHECK-NOT: builtin_unpredictable
 // CHECK: !unpredictable [[METADATA:.+]]
-// CHECK: [[METADATA]] = !{}
 
 // CHECK_O0-NOT: builtin_unpredictable
 // CHECK_O0-NOT: !unpredictable 
@@ -20,8 +19,15 @@ void branch(int x) {
 foo ();
 }
 
-// TODO: Add metadata for unpredictable switches.
 int unpredictable_switch(int x) {
+// CHECK-LABEL: @unpredictable_switch(
+
+// CHECK-NOT: builtin_unpredictable
+// CHECK: !unpredictable [[METADATA:.+]]
+
+// CHECK_O0-NOT: builtin_unpredictable
+// CHECK_O0-NOT: !unpredictable 
+
   switch(__builtin_unpredictable(x)) {
   default:
 return 0;
@@ -36,3 +42,5 @@ int unpredictable_switch(int x) {
   return 0;
 }
 
+// CHECK: [[METADATA]] = !{}
+


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


r247207 - Fix access control for lookups using the Microsoft __super extension.

2015-09-09 Thread John McCall via cfe-commits
Author: rjmccall
Date: Wed Sep  9 18:04:17 2015
New Revision: 247207

URL: http://llvm.org/viewvc/llvm-project?rev=247207=rev
Log:
Fix access control for lookups using the Microsoft __super extension.

rdar://22464808

Added:
cfe/trunk/test/SemaCXX/microsoft-super.cpp
Modified:
cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=247207=247206=247207=diff
==
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed Sep  9 18:04:17 2015
@@ -2098,17 +2098,30 @@ bool Sema::LookupParsedName(LookupResult
 ///
 /// @returns True if any decls were found (but possibly ambiguous)
 bool Sema::LookupInSuper(LookupResult , CXXRecordDecl *Class) {
+  // The access-control rules we use here are essentially the rules for
+  // doing a lookup in Class that just magically skipped the direct
+  // members of Class itself.  That is, the naming class is Class, and the
+  // access includes the access of the base.
   for (const auto  : Class->bases()) {
 CXXRecordDecl *RD = cast(
 BaseSpec.getType()->castAs()->getDecl());
 LookupResult Result(*this, R.getLookupNameInfo(), R.getLookupKind());
Result.setBaseObjectType(Context.getRecordType(Class));
 LookupQualifiedName(Result, RD);
-for (auto *Decl : Result)
-  R.addDecl(Decl);
+
+// Copy the lookup results into the target, merging the base's access into
+// the path access.
+for (auto I = Result.begin(), E = Result.end(); I != E; ++I) {
+  R.addDecl(I.getDecl(),
+CXXRecordDecl::MergeAccess(BaseSpec.getAccessSpecifier(),
+   I.getAccess()));
+}
+
+Result.suppressDiagnostics();
   }
 
   R.resolveKind();
+  R.setNamingClass(Class);
 
   return !R.empty();
 }

Added: cfe/trunk/test/SemaCXX/microsoft-super.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/microsoft-super.cpp?rev=247207=auto
==
--- cfe/trunk/test/SemaCXX/microsoft-super.cpp (added)
+++ cfe/trunk/test/SemaCXX/microsoft-super.cpp Wed Sep  9 18:04:17 2015
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fms-extensions -verify %s
+
+// rdar://22464808
+
+namespace test0 {
+  class A {
+  private:
+void foo(int*);
+  public:
+void foo(long*);
+  };
+  class B : public A {
+void test() {
+  __super::foo((long*) 0);
+}
+  };
+}
+
+namespace test1 {
+  struct A {
+static void foo(); // expected-note {{member is declared here}}
+  };
+  struct B : private A { // expected-note {{constrained by private inheritance 
here}}
+void test() {
+  __super::foo();
+}
+  };
+  struct C : public B {
+void test() {
+  __super::foo(); // expected-error {{'foo' is a private member of 
'test1::A'}}
+}
+  };
+}
+
+namespace test2 {
+  struct A {
+static void foo();
+  };
+  struct B : public A {
+void test() {
+  __super::foo();
+}
+  };
+  struct C : private B {
+void test() {
+  __super::foo();
+}
+  };
+}


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


r247209 - ARC: Fix the precise-lifetime suppression of returns_inner_pointer

2015-09-09 Thread John McCall via cfe-commits
Author: rjmccall
Date: Wed Sep  9 18:37:17 2015
New Revision: 247209

URL: http://llvm.org/viewvc/llvm-project?rev=247209=rev
Log:
ARC: Fix the precise-lifetime suppression of returns_inner_pointer
receiver extension for message sends via property syntax.

rdar://22172983

Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/test/CodeGenObjC/arc-precise-lifetime.m

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=247209=247208=247209=diff
==
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Wed Sep  9 18:37:17 2015
@@ -273,10 +273,23 @@ shouldExtendReceiverForInnerPointerMessa
   // receiver is loaded from a variable with precise lifetime.
   case ObjCMessageExpr::Instance: {
 const Expr *receiver = message->getInstanceReceiver();
+
+// Look through OVEs.
+if (auto opaque = dyn_cast(receiver)) {
+  if (opaque->getSourceExpr())
+receiver = opaque->getSourceExpr()->IgnoreParens();
+}
+
 const ImplicitCastExpr *ice = dyn_cast(receiver);
 if (!ice || ice->getCastKind() != CK_LValueToRValue) return true;
 receiver = ice->getSubExpr()->IgnoreParens();
 
+// Look through OVEs.
+if (auto opaque = dyn_cast(receiver)) {
+  if (opaque->getSourceExpr())
+receiver = opaque->getSourceExpr()->IgnoreParens();
+}
+
 // Only __strong variables.
 if (receiver->getType().getObjCLifetime() != Qualifiers::OCL_Strong)
   return true;

Modified: cfe/trunk/test/CodeGenObjC/arc-precise-lifetime.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-precise-lifetime.m?rev=247209=247208=247209=diff
==
--- cfe/trunk/test/CodeGenObjC/arc-precise-lifetime.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-precise-lifetime.m Wed Sep  9 18:37:17 2015
@@ -26,7 +26,8 @@ void test0() {
   // CHECK-NEXT: ret void
 }
 
-// rdar://problem/9821110
+// rdar://problem/9821110 - precise lifetime should suppress extension
+// rdar://problem/22172983 - should work for calls via property syntax, too
 @interface Test1
 - (char*) interior __attribute__((objc_returns_inner_pointer));
 // Should we allow this on properties? Yes! see // rdar://14990439
@@ -34,8 +35,8 @@ void test0() {
 @end
 extern Test1 *test1_helper(void);
 
-// CHECK-LABEL: define void @test1a()
-void test1a(void) {
+// CHECK-LABEL: define void @test1a_message()
+void test1a_message(void) {
   // CHECK:  [[PTR:%.*]] = alloca [[PTR_T:%.*]]*, align 8
   // CHECK:  [[C:%.*]] = alloca i8*, align 8
   // CHECK:  [[PTRPTR1:%.*]] = bitcast [[PTR_T]]** [[PTR]] to i8*
@@ -67,8 +68,43 @@ void test1a(void) {
   char *c = [(ptr) interior];
 }
 
-// CHECK-LABEL: define void @test1b()
-void test1b(void) {
+
+// CHECK-LABEL: define void @test1a_property()
+void test1a_property(void) {
+  // CHECK:  [[PTR:%.*]] = alloca [[PTR_T:%.*]]*, align 8
+  // CHECK:  [[C:%.*]] = alloca i8*, align 8
+  // CHECK:  [[PTRPTR1:%.*]] = bitcast [[PTR_T]]** [[PTR]] to i8*
+  // CHECK:  call void @llvm.lifetime.start(i64 8, i8* [[PTRPTR1]])
+  // CHECK:  [[T0:%.*]] = call [[TEST1:%.*]]* @test1_helper()
+  // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST1]]* [[T0]] to i8*
+  // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* 
[[T1]])
+  // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST1]]*
+  // CHECK-NEXT: store [[TEST1]]* [[T3]]
+  // CHECK-NEXT: [[CPTR1:%.*]] = bitcast i8** [[C]] to i8*
+  // CHECK-NEXT: call void @llvm.lifetime.start(i64 8, i8* [[CPTR1]])
+  // CHECK-NEXT: [[T0:%.*]] = load [[TEST1]]*, [[TEST1]]**
+  // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST1]]* [[T0]] to i8*
+  // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutorelease(i8* [[T1]])
+  // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST1]]*
+  // CHECK-NEXT: [[T4:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES_
+  // CHECK-NEXT: [[T5:%.*]] = bitcast [[TEST1]]* [[T3]] to i8*
+  // CHECK-NEXT: [[T6:%.*]] = call i8* bitcast
+  // CHECK-NEXT: store i8* [[T6]], i8**
+  // CHECK-NEXT: [[CPTR2:%.*]] = bitcast i8** [[C]] to i8*
+  // CHECK-NEXT: call void @llvm.lifetime.end(i64 8, i8* [[CPTR2]])
+  // CHECK-NEXT: [[T0:%.*]] = load [[TEST1]]*, [[TEST1]]**
+  // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST1]]* [[T0]] to i8*
+  // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], 
!clang.imprecise_release
+  // CHECK-NEXT: [[PTRPTR2:%.*]] = bitcast [[PTR_T]]** [[PTR]] to i8*
+  // CHECK-NEXT: call void @llvm.lifetime.end(i64 8, i8* [[PTRPTR2]])
+  // CHECK-NEXT: ret void
+  Test1 *ptr = test1_helper();
+  char *c = ptr.interior;
+}
+
+
+// CHECK-LABEL: define void @test1b_message()
+void test1b_message(void) {
   // CHECK:  [[PTR:%.*]] = alloca [[PTR_T:%.*]]*, align 8
   // CHECK:  [[C:%.*]] = alloca i8*, align 8
   // CHECK:  

Re: [PATCH] D12741: [Clang] Fix Clang-tidy misc-use-override warnings, other minor fixes

2015-09-09 Thread Hans Wennborg via cfe-commits
hans added a comment.

In http://reviews.llvm.org/D12741#242907, @hans wrote:

> It seems this broke the build for some reason. I have reverted it in r247222.
>
> Example build breakages: 
> http://lab.llvm.org:8011/builders/perf-x86_64-penryn-O3-polly-fast/builds/11687/steps/compile/logs/stdio,
>  http://lab.llvm.org:8011/builders/clang-x86_64-ubuntu-gdb-75/builds/24926


Sorry, it was probably the LLVM side that broke things. I've reverted that too, 
in r247226.

Someone suggested it's gcc 4.7 that's unhappy about something. I can try to 
take a look tomorrow.


Repository:
  rL LLVM

http://reviews.llvm.org/D12741



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


Re: [PATCH] D11857: CFI: Introduce -fsanitize=cfi-icall flag.

2015-09-09 Thread Kostya Serebryany via cfe-commits
kcc accepted this revision.
kcc added a comment.
This revision is now accepted and ready to land.

LGTM with a nit



Comment at: test/CodeGen/cfi-icall.c:1
@@ +1,2 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall 
-fsanitize-trap=cfi-icall -emit-llvm -o - %s | FileCheck --check-prefix=ITANIUM 
%s
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fsanitize=cfi-icall 
-fsanitize-trap=cfi-icall -emit-llvm -o - %s | FileCheck --check-prefix=MS %s

Add a comment explaining what we are testing here.
same below. 


http://reviews.llvm.org/D11857



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


r247222 - Revert r247218: "Fix Clang-tidy misc-use-override warnings, other minor fixes"

2015-09-09 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Wed Sep  9 19:37:18 2015
New Revision: 247222

URL: http://llvm.org/viewvc/llvm-project?rev=247222=rev
Log:
Revert r247218: "Fix Clang-tidy misc-use-override warnings, other minor fixes"

Seems it broke the Polly build.
From 
http://lab.llvm.org:8011/builders/perf-x86_64-penryn-O3-polly-fast/builds/11687/steps/compile/logs/stdio:

In file included from 
/home/grosser/buildslave/perf-x86_64-penryn-O3-polly-fast/llvm.src/lib/TableGen/Record.cpp:14:0:
/home/grosser/buildslave/perf-x86_64-penryn-O3-polly-fast/llvm.src/include/llvm/TableGen/Record.h:369:3:
 error: looser throw specifier for 'virtual llvm::TypedInit::~TypedInit()'
/home/grosser/buildslave/perf-x86_64-penryn-O3-polly-fast/llvm.src/include/llvm/TableGen/Record.h:270:11:
 error:   overriding 'virtual llvm::Init::~Init() noexcept (true)'

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/lib/Frontend/PCHContainerOperations.cpp

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=247222=247221=247222=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Sep  9 19:37:18 2015
@@ -30,7 +30,6 @@
 #include "llvm/Support/TargetParser.h"
 #include 
 #include 
-
 using namespace clang;
 
 
//===--===//
@@ -740,7 +739,7 @@ namespace {
 template 
 class WebAssemblyOSTargetInfo : public OSTargetInfo {
   void getOSDefines(const LangOptions , const llvm::Triple ,
-MacroBuilder ) const final {
+MacroBuilder ) const override final {
 // A common platform macro.
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
@@ -750,7 +749,7 @@ class WebAssemblyOSTargetInfo : public O
   }
 
   // As an optimization, group static init code together in a section.
-  const char *getStaticInitSectionSpecifier() const final {
+  const char *getStaticInitSectionSpecifier() const override final {
 return ".text.__startup";
   }
 
@@ -7012,13 +7011,13 @@ private:
   Features["simd128"] = true;
 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
   }
-  bool hasFeature(StringRef Feature) const final {
+  bool hasFeature(StringRef Feature) const override final {
 return llvm::StringSwitch(Feature)
 .Case("simd128", SIMDLevel >= SIMD128)
 .Default(false);
   }
   bool handleTargetFeatures(std::vector ,
-DiagnosticsEngine ) final {
+DiagnosticsEngine ) override final {
 for (const auto  : Features) {
   if (Feature == "+simd128") {
 SIMDLevel = std::max(SIMDLevel, SIMD128);
@@ -7035,7 +7034,7 @@ private:
 }
 return true;
   }
-  bool setCPU(const std::string ) final {
+  bool setCPU(const std::string ) override final {
 return llvm::StringSwitch(Name)
   .Case("mvp",   true)
   .Case("bleeding-edge", true)
@@ -7043,32 +7042,32 @@ private:
   .Default(false);
   }
   void getTargetBuiltins(const Builtin::Info *,
- unsigned ) const final {
+ unsigned ) const override final {
 Records = BuiltinInfo;
 NumRecords = clang::WebAssembly::LastTSBuiltin - Builtin::FirstTSBuiltin;
   }
-  BuiltinVaListKind getBuiltinVaListKind() const final {
+  BuiltinVaListKind getBuiltinVaListKind() const override final {
 // TODO: Implement va_list properly.
 return VoidPtrBuiltinVaList;
   }
   void getGCCRegNames(const char *const *,
-  unsigned ) const final {
+  unsigned ) const override final {
 Names = nullptr;
 NumNames = 0;
   }
   void getGCCRegAliases(const GCCRegAlias *,
-unsigned ) const final {
+unsigned ) const override final {
 Aliases = nullptr;
 NumAliases = 0;
   }
   bool
   validateAsmConstraint(const char *,
-TargetInfo::ConstraintInfo ) const final {
+TargetInfo::ConstraintInfo ) const override final 
{
 return false;
   }
-  const char *getClobbers() const final { return ""; }
-  bool isCLZForZeroUndef() const final { return false; }
-  bool hasInt128Type() const final { return true; }
+  const char *getClobbers() const override final { return ""; }
+  bool isCLZForZeroUndef() const override final { return false; }
+  bool hasInt128Type() const override final { return true; }
 };
 
 const Builtin::Info WebAssemblyTargetInfo::BuiltinInfo[] = {

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 

r247233 - EmitRecord* API change: accepts ArrayRef instead of a SmallVector (NFC)

2015-09-09 Thread Mehdi Amini via cfe-commits
Author: mehdi_amini
Date: Wed Sep  9 20:46:39 2015
New Revision: 247233

URL: http://llvm.org/viewvc/llvm-project?rev=247233=rev
Log:
EmitRecord* API change: accepts ArrayRef instead of a SmallVector (NFC)

This reapply a variant commit r247179 after post-commit review from
D.Blaikie.
Hopefully I got it right this time: lifetime of initializer list ends
as with any expression, which make invalid the pattern:

ArrayRef Arr = { 1, 2, 3, 4};

Just like StringRef, ArrayRef shouldn't be used to initialize local
variable but only as function argument.

From: Mehdi Amini 

Modified:
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=247233=247232=247233=diff
==
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Wed Sep  9 20:46:39 2015
@@ -84,6 +84,7 @@ class ASTWriter : public ASTDeserializat
 public:
   typedef SmallVector RecordData;
   typedef SmallVectorImpl RecordDataImpl;
+  typedef ArrayRef RecordDataRef;
 
   friend class ASTDeclWriter;
   friend class ASTStmtWriter;
@@ -756,7 +757,7 @@ public:
   void AddPath(StringRef Path, RecordDataImpl );
 
   /// \brief Emit the current record with the given path as a blob.
-  void EmitRecordWithPath(unsigned Abbrev, RecordDataImpl ,
+  void EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record,
   StringRef Path);
 
   /// \brief Add a version tuple to the given record

Modified: cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp?rev=247233=247232=247233=diff
==
--- cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp Wed Sep  9 20:46:39 
2015
@@ -51,6 +51,7 @@ public:
  
 typedef SmallVector RecordData;
 typedef SmallVectorImpl RecordDataImpl;
+typedef ArrayRef RecordDataRef;
 
 class SDiagsWriter;
   
@@ -393,13 +394,9 @@ unsigned SDiagsWriter::getEmitFile(const
   
   // Lazily generate the record for the file.
   entry = State->Files.size();
-  RecordData Record;
-  Record.push_back(RECORD_FILENAME);
-  Record.push_back(entry);
-  Record.push_back(0); // For legacy.
-  Record.push_back(0); // For legacy.
   StringRef Name(FileName);
-  Record.push_back(Name.size());
+  RecordData::value_type Record[] = {RECORD_FILENAME, entry, 0 /* For legacy 
*/,
+ 0 /* For legacy */, Name.size()};
   State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_FILENAME), Record,
Name);
 
@@ -531,14 +528,11 @@ void SDiagsWriter::EmitBlockInfoBlock()
 
 void SDiagsWriter::EmitMetaBlock() {
   llvm::BitstreamWriter  = State->Stream;
-  RecordData  = State->Record;
   AbbreviationMap  = State->Abbrevs;
 
   Stream.EnterSubblock(BLOCK_META, 3);
-  Record.clear();
-  Record.push_back(RECORD_VERSION);
-  Record.push_back(VersionNumber);
-  Stream.EmitRecordWithAbbrev(Abbrevs.get(RECORD_VERSION), Record);  
+  RecordData::value_type Record[] = {RECORD_VERSION, VersionNumber};
+  Stream.EmitRecordWithAbbrev(Abbrevs.get(RECORD_VERSION), Record);
   Stream.ExitBlock();
 }
 
@@ -548,11 +542,8 @@ unsigned SDiagsWriter::getEmitCategory(u
 
   // We use a local version of 'Record' so that we can be generating
   // another record when we lazily generate one for the category entry.
-  RecordData Record;
-  Record.push_back(RECORD_CATEGORY);
-  Record.push_back(category);
   StringRef catName = DiagnosticIDs::getCategoryNameFromID(category);
-  Record.push_back(catName.size());
+  RecordData::value_type Record[] = {RECORD_CATEGORY, category, 
catName.size()};
   State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_CATEGORY), Record,
catName);
   
@@ -581,10 +572,8 @@ unsigned SDiagsWriter::getEmitDiagnostic
 entry.second = FlagName;
 
 // Lazily emit the string in a separate record.
-RecordData Record;
-Record.push_back(RECORD_DIAG_FLAG);
-Record.push_back(entry.first);
-Record.push_back(FlagName.size());
+RecordData::value_type Record[] = {RECORD_DIAG_FLAG, entry.first,
+   FlagName.size()};
 State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_DIAG_FLAG),
  Record, FlagName);
   }
@@ -844,17 +833,9 @@ std::error_code SDiagsMerger::visitEndOf
 std::error_code
 

Re: r247233 - EmitRecord* API change: accepts ArrayRef instead of a SmallVector (NFC)

2015-09-09 Thread David Blaikie via cfe-commits
On Wed, Sep 9, 2015 at 6:46 PM, Mehdi Amini via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: mehdi_amini
> Date: Wed Sep  9 20:46:39 2015
> New Revision: 247233
>
> URL: http://llvm.org/viewvc/llvm-project?rev=247233=rev
> Log:
> EmitRecord* API change: accepts ArrayRef instead of a SmallVector (NFC)
>
> This reapply a variant commit r247179 after post-commit review from
> D.Blaikie.
> Hopefully I got it right this time: lifetime of initializer list ends
> as with any expression, which make invalid the pattern:
>
> ArrayRef Arr = { 1, 2, 3, 4};
>
> Just like StringRef, ArrayRef shouldn't be used to initialize local
> variable but only as function argument.
>

Looks pretty reasonable - I'll mention it again, just in case: removing the
named variables and just putting the init lists directly in the call might
be as (or more) readable - might be worth giving it a go & running it
through clang-format to see what you think.

- Dave


>
> From: Mehdi Amini 
>
> Modified:
> cfe/trunk/include/clang/Serialization/ASTWriter.h
> cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
> cfe/trunk/lib/Serialization/ASTWriter.cpp
> cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp
>
> Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=247233=247232=247233=diff
>
> ==
> --- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
> +++ cfe/trunk/include/clang/Serialization/ASTWriter.h Wed Sep  9 20:46:39
> 2015
> @@ -84,6 +84,7 @@ class ASTWriter : public ASTDeserializat
>  public:
>typedef SmallVector RecordData;
>typedef SmallVectorImpl RecordDataImpl;
> +  typedef ArrayRef RecordDataRef;
>
>friend class ASTDeclWriter;
>friend class ASTStmtWriter;
> @@ -756,7 +757,7 @@ public:
>void AddPath(StringRef Path, RecordDataImpl );
>
>/// \brief Emit the current record with the given path as a blob.
> -  void EmitRecordWithPath(unsigned Abbrev, RecordDataImpl ,
> +  void EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record,
>StringRef Path);
>
>/// \brief Add a version tuple to the given record
>
> Modified: cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp?rev=247233=247232=247233=diff
>
> ==
> --- cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp (original)
> +++ cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp Wed Sep  9
> 20:46:39 2015
> @@ -51,6 +51,7 @@ public:
>
>  typedef SmallVector RecordData;
>  typedef SmallVectorImpl RecordDataImpl;
> +typedef ArrayRef RecordDataRef;
>
>  class SDiagsWriter;
>
> @@ -393,13 +394,9 @@ unsigned SDiagsWriter::getEmitFile(const
>
>// Lazily generate the record for the file.
>entry = State->Files.size();
> -  RecordData Record;
> -  Record.push_back(RECORD_FILENAME);
> -  Record.push_back(entry);
> -  Record.push_back(0); // For legacy.
> -  Record.push_back(0); // For legacy.
>StringRef Name(FileName);
> -  Record.push_back(Name.size());
> +  RecordData::value_type Record[] = {RECORD_FILENAME, entry, 0 /* For
> legacy */,
> + 0 /* For legacy */, Name.size()};
>State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_FILENAME),
> Record,
> Name);
>
> @@ -531,14 +528,11 @@ void SDiagsWriter::EmitBlockInfoBlock()
>
>  void SDiagsWriter::EmitMetaBlock() {
>llvm::BitstreamWriter  = State->Stream;
> -  RecordData  = State->Record;
>AbbreviationMap  = State->Abbrevs;
>
>Stream.EnterSubblock(BLOCK_META, 3);
> -  Record.clear();
> -  Record.push_back(RECORD_VERSION);
> -  Record.push_back(VersionNumber);
> -  Stream.EmitRecordWithAbbrev(Abbrevs.get(RECORD_VERSION), Record);
> +  RecordData::value_type Record[] = {RECORD_VERSION, VersionNumber};
> +  Stream.EmitRecordWithAbbrev(Abbrevs.get(RECORD_VERSION), Record);
>Stream.ExitBlock();
>  }
>
> @@ -548,11 +542,8 @@ unsigned SDiagsWriter::getEmitCategory(u
>
>// We use a local version of 'Record' so that we can be generating
>// another record when we lazily generate one for the category entry.
> -  RecordData Record;
> -  Record.push_back(RECORD_CATEGORY);
> -  Record.push_back(category);
>StringRef catName = DiagnosticIDs::getCategoryNameFromID(category);
> -  Record.push_back(catName.size());
> +  RecordData::value_type Record[] = {RECORD_CATEGORY, category,
> catName.size()};
>State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_CATEGORY),
> Record,
> catName);
>
> @@ -581,10 +572,8 @@ unsigned SDiagsWriter::getEmitDiagnostic
>  entry.second = FlagName;
>
>  // 

r247228 - Don't crash when emitting a block under returns_nonnull.

2015-09-09 Thread John McCall via cfe-commits
Author: rjmccall
Date: Wed Sep  9 19:57:46 2015
New Revision: 247228

URL: http://llvm.org/viewvc/llvm-project?rev=247228=rev
Log:
Don't crash when emitting a block under returns_nonnull.

rdar://22071955

Added:
cfe/trunk/test/CodeGen/sanitize-blocks.c
Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=247228=247227=247228=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Sep  9 19:57:46 2015
@@ -2440,8 +2440,8 @@ void CodeGenFunction::EmitFunctionEpilog
 
   llvm::Instruction *Ret;
   if (RV) {
-if (SanOpts.has(SanitizerKind::ReturnsNonnullAttribute)) {
-  if (auto RetNNAttr = CurGD.getDecl()->getAttr()) {
+if (CurCodeDecl && SanOpts.has(SanitizerKind::ReturnsNonnullAttribute)) {
+  if (auto RetNNAttr = CurCodeDecl->getAttr()) {
 SanitizerScope SanScope(this);
 llvm::Value *Cond = Builder.CreateICmpNE(
 RV, llvm::Constant::getNullValue(RV->getType()));

Added: cfe/trunk/test/CodeGen/sanitize-blocks.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/sanitize-blocks.c?rev=247228=auto
==
--- cfe/trunk/test/CodeGen/sanitize-blocks.c (added)
+++ cfe/trunk/test/CodeGen/sanitize-blocks.c Wed Sep  9 19:57:46 2015
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsanitize-trap=returns-nonnull-attribute 
-fsanitize=returns-nonnull-attribute -emit-llvm %s -o - -triple 
x86_64-apple-darwin10 -fblocks | FileCheck %s
+
+// Awkward interactions of sanitizers with blocks.
+
+// rdar://22071955
+const char *TheString = "Hello, world!";
+const char *(^getString)(void) = ^{
+  return TheString;
+};
+
+// CHECK-LABEL: define internal i8* @getString_block_invoke
+
+// TODO: Actually support returns_nonnull on blocks.


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


Re: [PATCH] D12743: [CodeGen] Teach SimplifyPersonality about the updated LandingPadInst

2015-09-09 Thread Vedant Kumar via cfe-commits
vsk updated the summary for this revision.
vsk updated this revision to Diff 34408.
vsk added a comment.

Thanks for the review.

- Addressed if (!U) bug.
- Added test which loads a personality function, confirmed that we crash 
without the proper `if (!F)' check.


http://reviews.llvm.org/D12743

Files:
  lib/CodeGen/CGException.cpp
  test/CodeGenObjCXX/exception-cxx.mm
  test/CodeGenObjCXX/personality-abuse.mm

Index: test/CodeGenObjCXX/personality-abuse.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/personality-abuse.mm
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -emit-llvm -fcxx-exceptions -fexceptions -fobjc-exceptions -o - %s | FileCheck %s
+
+extern "C" {
+  int __objc_personality_v0();
+}
+
+void *abuse_personality_func() {
+  return (void *)&__objc_personality_v0;
+}
+
+void foo() {
+  try {
+throw 0;
+  } catch (...) {
+return;
+  }
+}
+
+// CHECK: define void @_Z3foov() #1 personality i8* bitcast (i32 ()* @__objc_personality_v0 to i8*)
Index: test/CodeGenObjCXX/exception-cxx.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/exception-cxx.mm
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -emit-llvm -fcxx-exceptions -fexceptions -fobjc-exceptions -o - %s | FileCheck %s
+
+// rdar://problem/22155434
+namespace test0 {
+  void foo() {
+try {
+  throw 0;
+} catch (...) {
+  return;
+}
+  }
+// CHECK: define void @_ZN5test03fooEv() #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+}
Index: lib/CodeGen/CGException.cpp
===
--- lib/CodeGen/CGException.cpp
+++ lib/CodeGen/CGException.cpp
@@ -229,6 +229,36 @@
   return llvm::ConstantExpr::getBitCast(Fn, CGM.Int8PtrTy);
 }
 
+/// Check whether a landingpad instruction only uses C++ features.
+static bool LandingPadHasOnlyCXXUses(llvm::LandingPadInst *LPI) {
+  for (unsigned I = 0, E = LPI->getNumClauses(); I != E; ++I) {
+// Look for something that would've been returned by the ObjC
+// runtime's GetEHType() method.
+llvm::Value *Val = LPI->getClause(I)->stripPointerCasts();
+if (LPI->isCatch(I)) {
+  // Check if the catch value has the ObjC prefix.
+  if (llvm::GlobalVariable *GV = dyn_cast(Val))
+// ObjC EH selector entries are always global variables with
+// names starting like this.
+if (GV->getName().startswith("OBJC_EHTYPE"))
+  return false;
+} else {
+  // Check if any of the filter values have the ObjC prefix.
+  llvm::Constant *CVal = cast(Val);
+  for (llvm::User::op_iterator
+  II = CVal->op_begin(), IE = CVal->op_end(); II != IE; ++II) {
+if (llvm::GlobalVariable *GV =
+cast((*II)->stripPointerCasts()))
+  // ObjC EH selector entries are always global variables with
+  // names starting like this.
+  if (GV->getName().startswith("OBJC_EHTYPE"))
+return false;
+  }
+}
+  }
+  return true;
+}
+
 /// Check whether a personality function could reasonably be swapped
 /// for a C++ personality function.
 static bool PersonalityHasOnlyCXXUses(llvm::Constant *Fn) {
@@ -241,34 +271,14 @@
   continue;
 }
 
-// Otherwise, it has to be a landingpad instruction.
-llvm::LandingPadInst *LPI = dyn_cast(U);
-if (!LPI) return false;
-
-for (unsigned I = 0, E = LPI->getNumClauses(); I != E; ++I) {
-  // Look for something that would've been returned by the ObjC
-  // runtime's GetEHType() method.
-  llvm::Value *Val = LPI->getClause(I)->stripPointerCasts();
-  if (LPI->isCatch(I)) {
-// Check if the catch value has the ObjC prefix.
-if (llvm::GlobalVariable *GV = dyn_cast(Val))
-  // ObjC EH selector entries are always global variables with
-  // names starting like this.
-  if (GV->getName().startswith("OBJC_EHTYPE"))
-return false;
-  } else {
-// Check if any of the filter values have the ObjC prefix.
-llvm::Constant *CVal = cast(Val);
-for (llvm::User::op_iterator
-   II = CVal->op_begin(), IE = CVal->op_end(); II != IE; ++II) {
-  if (llvm::GlobalVariable *GV =
-  cast((*II)->stripPointerCasts()))
-// ObjC EH selector entries are always global variables with
-// names starting like this.
-if (GV->getName().startswith("OBJC_EHTYPE"))
-  return false;
-}
-  }
+// Otherwise it must be a function.
+llvm::Function *F = dyn_cast(U);
+if (!F) return false;
+
+for (auto BB = F->begin(), E = F->end(); BB != E; ++BB) {
+  if (BB->isLandingPad())
+if (!LandingPadHasOnlyCXXUses(BB->getLandingPadInst()))
+  return false;
 }
   }
 

Re: [PATCH] D11857: CFI: Introduce -fsanitize=cfi-icall flag.

2015-09-09 Thread Peter Collingbourne via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL247238: CFI: Introduce -fsanitize=cfi-icall flag. (authored 
by pcc).

Changed prior to commit:
  http://reviews.llvm.org/D11857?vs=33175=34403#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D11857

Files:
  cfe/trunk/docs/ControlFlowIntegrity.rst
  cfe/trunk/docs/ControlFlowIntegrityDesign.rst
  cfe/trunk/include/clang/AST/Mangle.h
  cfe/trunk/include/clang/Basic/Sanitizers.def
  cfe/trunk/lib/AST/ItaniumMangle.cpp
  cfe/trunk/lib/AST/MicrosoftMangle.cpp
  cfe/trunk/lib/CodeGen/CGClass.cpp
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CGVTables.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/Driver/ToolChain.cpp
  cfe/trunk/lib/Driver/ToolChains.cpp
  cfe/trunk/test/CodeGen/cfi-icall.c
  cfe/trunk/test/CodeGenCXX/cfi-cast.cpp
  cfe/trunk/test/CodeGenCXX/cfi-icall.cpp
  cfe/trunk/test/CodeGenCXX/cfi-ms-rtti.cpp
  cfe/trunk/test/CodeGenCXX/cfi-nvcall.cpp
  cfe/trunk/test/CodeGenCXX/cfi-vcall.cpp
  cfe/trunk/test/Driver/fsanitize.c

Index: cfe/trunk/test/CodeGenCXX/cfi-ms-rtti.cpp
===
--- cfe/trunk/test/CodeGenCXX/cfi-ms-rtti.cpp
+++ cfe/trunk/test/CodeGenCXX/cfi-ms-rtti.cpp
@@ -8,5 +8,5 @@
 
 A::A() {}
 
-// RTTI: !{!"A@@", [2 x i8*]* {{.*}}, i64 8}
-// NO-RTTI: !{!"A@@", [1 x i8*]* {{.*}}, i64 0}
+// RTTI: !{!"?AUA@@", [2 x i8*]* {{.*}}, i64 8}
+// NO-RTTI: !{!"?AUA@@", [1 x i8*]* {{.*}}, i64 0}
Index: cfe/trunk/test/CodeGenCXX/cfi-cast.cpp
===
--- cfe/trunk/test/CodeGenCXX/cfi-cast.cpp
+++ cfe/trunk/test/CodeGenCXX/cfi-cast.cpp
@@ -18,7 +18,7 @@
 
 // CHECK-DCAST-LABEL: define void @_Z3abpP1A
 void abp(A *a) {
-  // CHECK-DCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1B")
+  // CHECK-DCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1B")
   // CHECK-DCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
 
   // CHECK-DCAST: [[TRAPBB]]
@@ -32,7 +32,7 @@
 
 // CHECK-DCAST-LABEL: define void @_Z3abrR1A
 void abr(A ) {
-  // CHECK-DCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1B")
+  // CHECK-DCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1B")
   // CHECK-DCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
 
   // CHECK-DCAST: [[TRAPBB]]
@@ -46,7 +46,7 @@
 
 // CHECK-DCAST-LABEL: define void @_Z4abrrO1A
 void abrr(A &) {
-  // CHECK-DCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1B")
+  // CHECK-DCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1B")
   // CHECK-DCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
 
   // CHECK-DCAST: [[TRAPBB]]
@@ -60,7 +60,7 @@
 
 // CHECK-UCAST-LABEL: define void @_Z3vbpPv
 void vbp(void *p) {
-  // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1B")
+  // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1B")
   // CHECK-UCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
 
   // CHECK-UCAST: [[TRAPBB]]
@@ -74,7 +74,7 @@
 
 // CHECK-UCAST-LABEL: define void @_Z3vbrRc
 void vbr(char ) {
-  // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1B")
+  // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1B")
   // CHECK-UCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
 
   // CHECK-UCAST: [[TRAPBB]]
@@ -88,7 +88,7 @@
 
 // CHECK-UCAST-LABEL: define void @_Z4vbrrOc
 void vbrr(char &) {
-  // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1B")
+  // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1B")
   // CHECK-UCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
 
   // CHECK-UCAST: [[TRAPBB]]
@@ -103,23 +103,23 @@
 // CHECK-UCAST-LABEL: define void @_Z3vcpPv
 // CHECK-UCAST-STRICT-LABEL: define void @_Z3vcpPv
 void vcp(void *p) {
-  // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1A")
-  // CHECK-UCAST-STRICT: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1C")
+  // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1A")
+  // CHECK-UCAST-STRICT: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1C")
   static_cast(p);
 }
 
 // CHECK-UCAST-LABEL: define void @_Z3bcpP1B
 // CHECK-UCAST-STRICT-LABEL: define void @_Z3bcpP1B
 void bcp(B *p) {
-  // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1A")
-  // CHECK-UCAST-STRICT: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1C")
+  // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, 

r247238 - CFI: Introduce -fsanitize=cfi-icall flag.

2015-09-09 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Sep  9 21:17:40 2015
New Revision: 247238

URL: http://llvm.org/viewvc/llvm-project?rev=247238=rev
Log:
CFI: Introduce -fsanitize=cfi-icall flag.

This flag causes the compiler to emit bit set entries for functions as well
as runtime bitset checks at indirect call sites. Depends on the new function
bitset mechanism.

Differential Revision: http://reviews.llvm.org/D11857

Added:
cfe/trunk/test/CodeGen/cfi-icall.c
cfe/trunk/test/CodeGenCXX/cfi-icall.cpp
Modified:
cfe/trunk/docs/ControlFlowIntegrity.rst
cfe/trunk/docs/ControlFlowIntegrityDesign.rst
cfe/trunk/include/clang/AST/Mangle.h
cfe/trunk/include/clang/Basic/Sanitizers.def
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGVTables.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/test/CodeGenCXX/cfi-cast.cpp
cfe/trunk/test/CodeGenCXX/cfi-ms-rtti.cpp
cfe/trunk/test/CodeGenCXX/cfi-nvcall.cpp
cfe/trunk/test/CodeGenCXX/cfi-vcall.cpp
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/docs/ControlFlowIntegrity.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ControlFlowIntegrity.rst?rev=247238=247237=247238=diff
==
--- cfe/trunk/docs/ControlFlowIntegrity.rst (original)
+++ cfe/trunk/docs/ControlFlowIntegrity.rst Wed Sep  9 21:17:40 2015
@@ -20,12 +20,14 @@ program's control flow. These schemes ha
 allowing developers to enable them in release builds.
 
 To enable Clang's available CFI schemes, use the flag ``-fsanitize=cfi``.
-As currently implemented, CFI relies on link-time optimization (LTO); so it is
-required to specify ``-flto``, and the linker used must support LTO, for 
example
-via the `gold plugin`_. To allow the checks to be implemented efficiently,
-the program must be structured such that certain object files are compiled
-with CFI enabled, and are statically linked into the program. This may
-preclude the use of shared libraries in some cases.
+As currently implemented, all of Clang's CFI schemes (``cfi-vcall``,
+``cfi-derived-cast``, ``cfi-unrelated-cast``, ``cfi-nvcall``, ``cfi-icall``)
+rely on link-time optimization (LTO); so it is required to specify
+``-flto``, and the linker used must support LTO, for example via the `gold
+plugin`_. To allow the checks to be implemented efficiently, the program must
+be structured such that certain object files are compiled with CFI enabled,
+and are statically linked into the program. This may preclude the use of
+shared libraries in some cases.
 
 Clang currently implements forward-edge CFI for member function calls and
 bad cast checking. More schemes are under development.
@@ -123,6 +125,54 @@ member functions on class instances with
 most compilers and should not have security implications, so we allow it by
 default. It can be disabled with ``-fsanitize=cfi-cast-strict``.
 
+Indirect Function Call Checking
+---
+
+This scheme checks that function calls take place using a function of the
+correct dynamic type; that is, the dynamic type of the function must match
+the static type used at the call. This CFI scheme can be enabled on its own
+using ``-fsanitize=cfi-icall``.
+
+For this scheme to work, each indirect function call in the program, other
+than calls in :ref:`blacklisted ` functions, must call a
+function which was either compiled with ``-fsanitize=cfi-icall`` enabled,
+or whose address was taken by a function in a translation unit compiled with
+``-fsanitize=cfi-icall``.
+
+If a function in a translation unit compiled with ``-fsanitize=cfi-icall``
+takes the address of a function not compiled with ``-fsanitize=cfi-icall``,
+that address may differ from the address taken by a function in a translation
+unit not compiled with ``-fsanitize=cfi-icall``. This is technically a
+violation of the C and C++ standards, but it should not affect most programs.
+
+Each translation unit compiled with ``-fsanitize=cfi-icall`` must be
+statically linked into the program or shared library, and calls across
+shared library boundaries are handled as if the callee was not compiled with
+``-fsanitize=cfi-icall``.
+
+This scheme is currently only supported on the x86 and x86_64 architectures.
+
+``-fsanitize=cfi-icall`` and ``-fsanitize=function``
+
+
+This tool is similar to ``-fsanitize=function`` in that both tools check
+the types of function calls. However, the two tools occupy different points
+on the design space; ``-fsanitize=function`` is a developer tool designed
+to find bugs in local development builds, whereas ``-fsanitize=cfi-icall``
+is a security hardening mechanism designed to be deployed in release builds.
+
+``-fsanitize=function`` has a 

Re: [PATCH] D11815: Pass subtarget feature "force-align-stack"

2015-09-09 Thread hfin...@anl.gov via cfe-commits
hfinkel added a comment.

In http://reviews.llvm.org/D11815#242616, @ahatanak wrote:

> Hal, do you have any thoughts on the points Vasileios brought up? Currently, 
> many of the targets don't guarantee that the realigned stack is at least as 
> aligned as the default alignment required by the ABI. Is this the behavior 
> end-users expect when they use -mstackrealign on the command line?


I don't think this is expected behavior, and sounds like a bug.

> Fixing this is beyond the initial scope of this patch and probably should be 
> done in a separate patch, but I want to make sure the patch I'll end up 
> committing won't make it harder to fix this problem.


Agreed. I don't see how this makes it harder.


http://reviews.llvm.org/D11815



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


Re: [PATCH] D11815: Pass subtarget feature "force-align-stack"

2015-09-09 Thread Akira Hatanaka via cfe-commits
ahatanak added a comment.

Hal, do you have any thoughts on the points Vasileios brought up? Currently, 
many of the targets don't guarantee that the realigned stack is at least as 
aligned as the default alignment required by the ABI. Is this the behavior 
end-users expect when they use -mstackrealign on the command line?Fixing this 
is beyond the initial scope of this patch and probably should be done in a 
separate patch, but I want to make sure the patch I'll end up committing won't 
make it harder to fix this problem.


http://reviews.llvm.org/D11815



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


r247176 - [libclang] Add missing clang_CompileCommand_* functions in libclang.exports.

2015-09-09 Thread Argyrios Kyrtzidis via cfe-commits
Author: akirtzidis
Date: Wed Sep  9 13:54:16 2015
New Revision: 247176

URL: http://llvm.org/viewvc/llvm-project?rev=247176=rev
Log:
[libclang] Add missing clang_CompileCommand_* functions in libclang.exports.

Modified:
cfe/trunk/tools/libclang/libclang.exports

Modified: cfe/trunk/tools/libclang/libclang.exports
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=247176=247175=247176=diff
==
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Wed Sep  9 13:54:16 2015
@@ -297,6 +297,8 @@ clang_CompileCommands_dispose
 clang_CompileCommands_getSize
 clang_CompileCommands_getCommand
 clang_CompileCommand_getDirectory
+clang_CompileCommand_getMappedSourceContent
+clang_CompileCommand_getMappedSourcePath
 clang_CompileCommand_getNumArgs
 clang_CompileCommand_getArg
 clang_visitChildren


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


Re: [PATCH] D10018: C11 _Bool bitfield diagnostic

2015-09-09 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:4320-4325
@@ -4319,2 +4319,8 @@
   "number of elements must be either one or match the size of the vector">;
+def warn_bitfield_width_longer_than_necessary : Warning<
+  "size of bit-field %0 (%1 bits) exceeds the minimum width required to "
+  "represent all valid values of that bit-field type">, InGroup;
+def warn_anon_bitfield_width_longer_than_necessary : Warning<
+  "size of anonymous bit-field (%0 bits) exceeds the minimum width required to 
"
+  "represent all valid values of that bit-field type">, InGroup;
 

I suppose your argument for the width of `_Bool` being possibly greater than 1 
is that, while `_Bool` is required to be large enough to store the values 0 and 
1 (6.2.5/2), it may theoretically have value bits representing 2, 4, 8, ... 
(even though 6.3.1.2/1 does not allow creation of a value that sets those 
bits). That interpretation seems consistent with C's rules.

However, for Clang, the width of `_Bool` is 1, so this is a constraint 
violation.


Comment at: lib/Sema/SemaDecl.cpp:12586
@@ -12585,3 +12585,3 @@
   if (!FieldTy->isDependentType()) {
 uint64_t TypeSize = Context.getTypeSize(FieldTy);
 if (Value.getZExtValue() > TypeSize) {

I think the right way to fix this is to call `getIntWidth` here instead of 
`getTypeSize`, and finesse our error message to clarify that we're talking 
about the width of the type (the number of value bits) rather than the size of 
the type (the number of storage bits).


Comment at: lib/Sema/SemaDecl.cpp:12611
@@ +12610,3 @@
+// different platforms
+if ((getLangOpts().C11 || getLangOpts().C99) && 
+FieldTy->isBooleanType() &&

This is redundant: `C99` is always set whenever `C11` is (`C99` means "C99 or 
later"). Just test for `C99` here. I also think we should apply this rule to 
C89, where we support `_Bool` as an extension and use the C99 rules for it. The 
above check for !CPlusPlus seems right.


Comment at: lib/Sema/SemaDecl.cpp:12613
@@ +12612,3 @@
+FieldTy->isBooleanType() &&
+Value.getZExtValue() > 1) {
+  if (FieldName)

This will assert if the specified bitfield width doesn't fit in 64 bits. You 
can use `Value.ugt(1)` instead.

The check above for `TypeSize` has the same bug. This testcase causes an 
assertion to fire:

  struct X { int n : 0x * (__int128)0x * 0x; };


http://reviews.llvm.org/D10018



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


Re: [PATCH] D12712: Implementation and testing for poisoning vtable ptr in dtor.

2015-09-09 Thread Naomi Musgrave via cfe-commits
nmusgrave updated this revision to Diff 34357.
nmusgrave added a comment.

- Fixed testing callback emission order to account for vptr. Vptr poisoned 
after all virtual and member destructors are invoked, in order to prevent a 
data race an on the virtual function invoked by a class instance. 
(https://github.com/google/sanitizers/wiki/ThreadSanitizerPopularDataRaces#data-race-on-vptr)


http://reviews.llvm.org/D12712

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenCXX/sanitize-dtor-derived-class.cpp
  test/CodeGenCXX/sanitize-dtor-vtable.cpp

Index: test/CodeGenCXX/sanitize-dtor-vtable.cpp
===
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-vtable.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+class A {
+ public:
+  int x;
+  A() {}
+  virtual ~A() {}
+};
+A a;
+
+// CHECK-LABEL: define {{.*}}AD2Ev
+// CHECK: call void @__sanitizer_dtor_callback
+// CHECK: call void @__sanitizer_dtor_callback{{.*}}i64 8
+// CHECK-NOT: call void @__sanitizer_dtor_callback
+// CHECK: ret void
Index: test/CodeGenCXX/sanitize-dtor-derived-class.cpp
===
--- test/CodeGenCXX/sanitize-dtor-derived-class.cpp
+++ test/CodeGenCXX/sanitize-dtor-derived-class.cpp
@@ -52,14 +52,17 @@
 // CHECK-NOT: call void @__sanitizer_dtor_callback
 // CHECK: ret void
 
+// Poison member and vtable pointer.
 // CHECK-LABEL: define {{.*}}BaseD2Ev
 // CHECK: call void @__sanitizer_dtor_callback
+// CHECK: call void @__sanitizer_dtor_callback
 // CHECK-NOT: call void @__sanitizer_dtor_callback
 // CHECK: ret void
 
+// Poison member and vtable pointer.
 // CHECK-LABEL: define {{.*}}DerivedD2Ev
 // CHECK: call void @__sanitizer_dtor_callback
 // CHECK-NOT: call void @__sanitizer_dtor_callback
 // CHECK: call void {{.*}}BaseD2Ev
-// CHECK-NOT: call void @__sanitizer_dtor_callback
+// CHECK: call void @__sanitizer_dtor_callback
 // CHECK: ret void
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -1648,11 +1648,15 @@
 }
   };
 
-  class SanitizeDtor final : public EHScopeStack::Cleanup {
+
+ static void Poison(CodeGenFunction , llvm::Value *OffsetPtr,
+CharUnits::QuantityType PoisonSize);
+
+  class SanitizeDtorMembers final : public EHScopeStack::Cleanup {
 const CXXDestructorDecl *Dtor;
 
   public:
-SanitizeDtor(const CXXDestructorDecl *Dtor) : Dtor(Dtor) {}
+SanitizeDtorMembers(const CXXDestructorDecl *Dtor) : Dtor(Dtor) {}
 
 // Generate function call for handling object poisoning.
 // Disables tail call elimination, to prevent the current stack frame
@@ -1668,9 +1672,21 @@
   // Prevent the current stack frame from disappearing from the stack trace.
   CGF.CurFn->addFnAttr("disable-tail-calls", "true");
 
+  ASTContext  = CGF.getContext();
+  /*
+  // Poison vtable and vtable ptr if they exist for this class.
+  if (Dtor->getParent()->isDynamicClass()) {
+llvm::Value *VTablePtr = CGF.LoadCXXThis();
+
+CharUnits::QuantityType PoisonSize =
+Context.toCharUnitsFromBits(CGF.PointerWidthInBits).getQuantity();
+// Pass in void pointer and size of region as arguments to runtime
+// function
+Poison(CGF, VTablePtr, PoisonSize);
+  }
+  */
   // Construct pointer to region to begin poisoning, and calculate poison
   // size, so that only members declared in this class are poisoned.
-  ASTContext  = CGF.getContext();
   unsigned fieldIndex = 0;
   int startIndex = -1;
   // RecordDecl::field_iterator Field;
@@ -1684,11 +1700,11 @@
   // Currently on the last field, and it must be poisoned with the
   // current block.
   if (fieldIndex == Layout.getFieldCount() - 1) {
-PoisonBlock(CGF, startIndex, Layout.getFieldCount());
+PoisonMembers(CGF, startIndex, Layout.getFieldCount());
   }
 } else if (startIndex >= 0) {
   // No longer within a block of memory to poison, so poison the block
-  PoisonBlock(CGF, startIndex, fieldIndex);
+  PoisonMembers(CGF, startIndex, fieldIndex);
   // Re-set the start index
   startIndex = -1;
 }
@@ -1701,7 +1717,7 @@
 /// start poisoning (inclusive)
 /// \param layoutEndOffset index of the ASTRecordLayout field to
 /// end poisoning (exclusive)
-void PoisonBlock(CodeGenFunction , unsigned layoutStartOffset,
+void PoisonMembers(CodeGenFunction , unsigned layoutStartOffset,
  unsigned 

Re: [PATCH] D12712: Implementation and testing for poisoning vtable ptr in dtor.

2015-09-09 Thread Naomi Musgrave via cfe-commits
nmusgrave marked an inline comment as done.
nmusgrave added a comment.

http://reviews.llvm.org/D12712



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


Re: r247179 - EmitRecordWith* API change: takes an ArrayRef instead of a SmallVector (NFC)

2015-09-09 Thread Mehdi Amini via cfe-commits
Hi David,

Thanks for the review.


> On Sep 9, 2015, at 1:14 PM, David Blaikie  wrote:
> 
> 
> 
> On Wed, Sep 9, 2015 at 1:08 PM, Mehdi Amini via cfe-commits 
> > wrote:
> Author: mehdi_amini
> Date: Wed Sep  9 15:08:51 2015
> New Revision: 247179
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=247179=rev 
> 
> Log:
> EmitRecordWith* API change: takes an ArrayRef instead of a SmallVector (NFC)
> 
> From: Mehdi Amini >
> 
> Modified:
> cfe/trunk/include/clang/Serialization/ASTWriter.h
> cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
> cfe/trunk/lib/Serialization/ASTWriter.cpp
> cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp
> 
> Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=247179=247178=247179=diff
>  
> 
> ==
> --- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
> +++ cfe/trunk/include/clang/Serialization/ASTWriter.h Wed Sep  9 15:08:51 2015
> @@ -84,6 +84,7 @@ class ASTWriter : public ASTDeserializat
>  public:
>typedef SmallVector RecordData;
>typedef SmallVectorImpl RecordDataImpl;
> +  typedef ArrayRef RecordDataRef;
> 
>friend class ASTDeclWriter;
>friend class ASTStmtWriter;
> @@ -756,7 +757,7 @@ public:
>void AddPath(StringRef Path, RecordDataImpl );
> 
>/// \brief Emit the current record with the given path as a blob.
> -  void EmitRecordWithPath(unsigned Abbrev, RecordDataImpl ,
> +  void EmitRecordWithPath(unsigned Abbrev, const RecordDataRef ,
> 
> ArrayRefs are generally passed by value, like StringRefs.

Good point, will update.


>  
>StringRef Path);
> 
>/// \brief Add a version tuple to the given record
> 
> Modified: cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp?rev=247179=247178=247179=diff
>  
> 
> ==
> --- cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp (original)
> +++ cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp Wed Sep  9 
> 15:08:51 2015
> @@ -51,6 +51,7 @@ public:
> 
>  typedef SmallVector RecordData;
>  typedef SmallVectorImpl RecordDataImpl;
> +typedef ArrayRef RecordDataRef;
> 
>  class SDiagsWriter;
> 
> @@ -393,13 +394,9 @@ unsigned SDiagsWriter::getEmitFile(const
> 
>// Lazily generate the record for the file.
>entry = State->Files.size();
> -  RecordData Record;
> -  Record.push_back(RECORD_FILENAME);
> -  Record.push_back(entry);
> -  Record.push_back(0); // For legacy.
> -  Record.push_back(0); // For legacy.
>StringRef Name(FileName);
> -  Record.push_back(Name.size());
> +  RecordDataRef Record = {RECORD_FILENAME, entry, 0 /* For legacy */,
> +  0 /* For legacy */, Name.size()};
> 
> I imagine this would produce a dangling reference, maybe? (the temporary 
> initializer_list would go out-of-scope at the end of the full expression?) 
> But I don't fully understand initializer_lists, to be fair.

It is possible, my initial patch was initializing a raw array, but it requires 
the makeArrayRef().
I’ll try to look into the details here.

>  
>State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_FILENAME), 
> Record,
> Name);
> 
> @@ -412,7 +409,7 @@ void SDiagsWriter::EmitCharSourceRange(C
>State->Record.push_back(RECORD_SOURCE_RANGE);
>AddCharSourceRangeToRecord(R, State->Record, SM);
>State->Stream.EmitRecordWithAbbrev(State->Abbrevs.get(RECORD_SOURCE_RANGE),
> - State->Record);
> + makeArrayRef(State->Record));
> 
> What type is State->Record & why isn't it implicitly convertible to ArrayRef?

It is a SmallVector, and the explicit conversion is needed because 
EmitRecordWithAbbrev is templated, and the template can’t be deduced if you 
don’t supply an ArrayRef:

  template 
  void EmitRecordWithAbbrev(unsigned Abbrev, const ArrayRef )

An alternative would be to provide an overload for SmallVector, I’ll try to do:

  template 
  void EmitRecordWithAbbrev(unsigned Abbrev, const SmallVectorImpl 
)


>  
>  }
> 
>  /// \brief Emits the preamble of the diagnostics file.
> @@ -531,14 +528,11 @@ void SDiagsWriter::EmitBlockInfoBlock()
> 
>  void SDiagsWriter::EmitMetaBlock() {
>

r247183 - Revert "EmitRecordWith* API change: takes an ArrayRef instead of a SmallVector (NFC)"

2015-09-09 Thread Mehdi Amini via cfe-commits
Author: mehdi_amini
Date: Wed Sep  9 15:35:37 2015
New Revision: 247183

URL: http://llvm.org/viewvc/llvm-project?rev=247183=rev
Log:
Revert "EmitRecordWith* API change: takes an ArrayRef instead of a SmallVector 
(NFC)"

This reverts commit r247179.

From: Mehdi Amini 

Modified:
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=247183=247182=247183=diff
==
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Wed Sep  9 15:35:37 2015
@@ -84,7 +84,6 @@ class ASTWriter : public ASTDeserializat
 public:
   typedef SmallVector RecordData;
   typedef SmallVectorImpl RecordDataImpl;
-  typedef ArrayRef RecordDataRef;
 
   friend class ASTDeclWriter;
   friend class ASTStmtWriter;
@@ -757,7 +756,7 @@ public:
   void AddPath(StringRef Path, RecordDataImpl );
 
   /// \brief Emit the current record with the given path as a blob.
-  void EmitRecordWithPath(unsigned Abbrev, const RecordDataRef ,
+  void EmitRecordWithPath(unsigned Abbrev, RecordDataImpl ,
   StringRef Path);
 
   /// \brief Add a version tuple to the given record

Modified: cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp?rev=247183=247182=247183=diff
==
--- cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp Wed Sep  9 15:35:37 
2015
@@ -51,7 +51,6 @@ public:
  
 typedef SmallVector RecordData;
 typedef SmallVectorImpl RecordDataImpl;
-typedef ArrayRef RecordDataRef;
 
 class SDiagsWriter;
   
@@ -394,9 +393,13 @@ unsigned SDiagsWriter::getEmitFile(const
   
   // Lazily generate the record for the file.
   entry = State->Files.size();
+  RecordData Record;
+  Record.push_back(RECORD_FILENAME);
+  Record.push_back(entry);
+  Record.push_back(0); // For legacy.
+  Record.push_back(0); // For legacy.
   StringRef Name(FileName);
-  RecordDataRef Record = {RECORD_FILENAME, entry, 0 /* For legacy */,
-  0 /* For legacy */, Name.size()};
+  Record.push_back(Name.size());
   State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_FILENAME), Record,
Name);
 
@@ -409,7 +412,7 @@ void SDiagsWriter::EmitCharSourceRange(C
   State->Record.push_back(RECORD_SOURCE_RANGE);
   AddCharSourceRangeToRecord(R, State->Record, SM);
   State->Stream.EmitRecordWithAbbrev(State->Abbrevs.get(RECORD_SOURCE_RANGE),
- makeArrayRef(State->Record));
+ State->Record);
 }
 
 /// \brief Emits the preamble of the diagnostics file.
@@ -528,11 +531,14 @@ void SDiagsWriter::EmitBlockInfoBlock()
 
 void SDiagsWriter::EmitMetaBlock() {
   llvm::BitstreamWriter  = State->Stream;
+  RecordData  = State->Record;
   AbbreviationMap  = State->Abbrevs;
 
   Stream.EnterSubblock(BLOCK_META, 3);
-  RecordDataRef Record = {RECORD_VERSION, VersionNumber};
-  Stream.EmitRecordWithAbbrev(Abbrevs.get(RECORD_VERSION), Record);
+  Record.clear();
+  Record.push_back(RECORD_VERSION);
+  Record.push_back(VersionNumber);
+  Stream.EmitRecordWithAbbrev(Abbrevs.get(RECORD_VERSION), Record);  
   Stream.ExitBlock();
 }
 
@@ -542,8 +548,11 @@ unsigned SDiagsWriter::getEmitCategory(u
 
   // We use a local version of 'Record' so that we can be generating
   // another record when we lazily generate one for the category entry.
+  RecordData Record;
+  Record.push_back(RECORD_CATEGORY);
+  Record.push_back(category);
   StringRef catName = DiagnosticIDs::getCategoryNameFromID(category);
-  RecordDataRef Record = {RECORD_CATEGORY, category, catName.size()};
+  Record.push_back(catName.size());
   State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_CATEGORY), Record,
catName);
   
@@ -572,7 +581,10 @@ unsigned SDiagsWriter::getEmitDiagnostic
 entry.second = FlagName;
 
 // Lazily emit the string in a separate record.
-RecordDataRef Record = {RECORD_DIAG_FLAG, entry.first, FlagName.size()};
+RecordData Record;
+Record.push_back(RECORD_DIAG_FLAG);
+Record.push_back(entry.first);
+Record.push_back(FlagName.size());
 State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_DIAG_FLAG),
  Record, FlagName);
   }
@@ -670,8 +682,7 @@ void SDiagsWriter::EmitDiagnosticMessage
   }
 
   

Re: [PATCH] D12462: [PATCH] [clang-tidy] Add inconsistent declaration parameter name check

2015-09-09 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

Thank you for the fixes. I really like this way of structuring the warnings 
more. We might need to polish the text in the messages a bit, and maybe also 
change the case without definitions, but overall this seems fine. I have a few 
more comments.



Comment at: 
clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp:106
@@ +105,3 @@
+  if (IsTemplateSpecialization) {
+// Template specializations need special handling.
+// What we actually see here is a generated declaration from the main

piotrdz wrote:
> alexfh wrote:
> > I don't see why we couldn't just ignore compiler-generated template 
> > specializations (hand-written ones should probably be handled). It should 
> > be easy to filter them out by adding `unless(isInTemplateInstantiation())` 
> > inside the `functionDecl` matcher.
> Unfortunately, it doesn't work like that. We get this declaration not from 
> matcher, but by iterating redecls().
> 
> In any case, I reconsidered this problem, and I came to conclusion that since 
> we need special code for handling template specializations, we may as well do 
> it properly. The only reason that this version of code works at all, is 
> because of incidental generation of this special declaration appearing in the 
> same place where we have function specialization. This, I think, should be 
> considered a side effect of how AST generation works now, and not how it must 
> necessarily work. It may change or even disappear in the future, making this 
> code brittle.
> 
> To do this correctly, I believe we should retrieve main template declaration 
> by using `getPrimaryTemplate()->getTemplatedDecl()` and process that. This 
> fixes the issue of wrong location reporting, and also makes it clear what is 
> happening to someone reading the code.
> 
> So in the end, partly because of this issue, I ended up rewriting over half 
> of my code, but what we're left with is I think much better.
I see now. Thanks for explaining!


Comment at: 
clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp:271
@@ +270,3 @@
+void InconsistentDeclarationParameterNameCheck::
+formatDiagnosticsInCaseOfOnlyFunctionDeclarationsPresent(
+const FormatDiagnosticContext ) {

The name is too long for my taste. It doesn't look well with 80-columns limit. 
Maybe `formatDiagnosticsForDeclarations` or something like this?


Comment at: 
clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp:275
@@ +274,3 @@
+diag(Context.OriginalDeclaration->getLocation(),
+ "function %q0 has %1 other declaration%s1 with differently named "
+ "parameters")

I'm not a native speaker, but "with differently named parameters" doesn't sound 
well to me. Maybe "with different parameter names"?


Comment at: 
clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp:289
@@ +288,3 @@
+
+formatDifferingParamsDiagnostic(FormatParamsDiagnosticContext{
+InconsistentDeclaration.DeclarationLocation, "other declaration",

I really don't like this idea of introducing a structure for the sole purpose 
of passing three parameters to a function. I don't see what we gain by doing 
so, and I would prefer the usual way to pass parameters. The same argument is 
valid for `formatDiagnosticsInCaseOfOnlyFunctionDeclarationsPresent` and 
`formatDiagnosticsInOtherCases`.


Comment at: 
clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp:290
@@ +289,3 @@
+formatDifferingParamsDiagnostic(FormatParamsDiagnosticContext{
+InconsistentDeclaration.DeclarationLocation, "other declaration",
+InconsistentDeclaration.DifferingParams});

Maybe "the other declaration"?


Comment at: 
clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp:297
@@ +296,3 @@
+
+void InconsistentDeclarationParameterNameCheck::formatDiagnosticsInOtherCases(
+const FormatDiagnosticContext , StringRef FunctionDescription,

The name `formatDiagnosticsInOtherCases` only makes sense when you have the 
other function name in mind 
(`formatDiagnosticsInCaseOfOnlyFunctionDeclarationsPresent`). I don't have a 
good name for it, but even just removing `InOtherCases` would make things 
better.


Comment at: 
clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp:307
@@ +306,3 @@
+
+diag(Context.ParameterSourceDeclaration->getLocation(), "%0 seen here",
+ DiagnosticIDs::Level::Note)

Maybe "the %0 seen here"?


Comment at: 
clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp:326
@@ +325,3 @@
+  diag(Context.Location,
+   "differing parameters are named here: (%0), while in %1: (%2)",
+   DiagnosticIDs::Level::Note)

I'd 

Re: [PATCH] D12627: Fix a small bug in clang where generating some temporary files would have an extra period before the extension.

2015-09-09 Thread Argyrios Kyrtzidis via cfe-commits
Committed in r247160, thanks!

> On Sep 3, 2015, at 10:16 PM, Cameron Esfahani  wrote:
> 
> dirty created this revision.
> dirty added a reviewer: akyrtzi.
> dirty added a subscriber: cfe-commits.
> 
>   Fix a small bug in clang where generating some temporary files would 
> have an extra period before the extension.
> 
> http://reviews.llvm.org/D12627
> 
> Files:
>  lib/ARCMigrate/FileRemapper.cpp
>  lib/ARCMigrate/ObjCMT.cpp
>  lib/Frontend/Rewrite/FrontendActions.cpp
> 
> Index: lib/Frontend/Rewrite/FrontendActions.cpp
> ===
> --- lib/Frontend/Rewrite/FrontendActions.cpp
> +++ lib/Frontend/Rewrite/FrontendActions.cpp
> @@ -78,7 +78,7 @@
>   std::string RewriteFilename(const std::string , int ) override {
> SmallString<128> Path;
> llvm::sys::fs::createTemporaryFile(llvm::sys::path::filename(Filename),
> -   llvm::sys::path::extension(Filename), 
> fd,
> +   
> llvm::sys::path::extension(Filename).drop_front(), fd,
>Path);
> return Path.str();
>   }
> Index: lib/ARCMigrate/ObjCMT.cpp
> ===
> --- lib/ARCMigrate/ObjCMT.cpp
> +++ lib/ARCMigrate/ObjCMT.cpp
> @@ -2218,7 +2218,7 @@
>   SmallString<64> TempPath;
>   int FD;
>   if (fs::createTemporaryFile(path::filename(FE->getName()),
> -  path::extension(FE->getName()), FD,
> +  path::extension(FE->getName()).drop_front(), 
> FD,
>   TempPath)) {
> reportDiag("Could not create file: " + TempPath.str(), Diag);
> return std::string();
> Index: lib/ARCMigrate/FileRemapper.cpp
> ===
> --- lib/ARCMigrate/FileRemapper.cpp
> +++ lib/ARCMigrate/FileRemapper.cpp
> @@ -144,7 +144,7 @@
>   SmallString<64> tempPath;
>   int fd;
>   if (fs::createTemporaryFile(path::filename(origFE->getName()),
> -  path::extension(origFE->getName()), fd,
> +  
> path::extension(origFE->getName()).drop_front(), fd,
>   tempPath))
> return report("Could not create file: " + tempPath.str(), Diag);
> 
> 
> 
> 

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


RE: [PATCH] D12624: Top-level anonymous namespaces are missing import DW_TAG_imported_module and nested anonymous namespaces are not

2015-09-09 Thread Robinson, Paul via cfe-commits
This seems pretty fine-grained for a CodeGenOpt (not that I've looked there, 
perhaps there are examples of similarly fine grained things already there?)- 
I'm curious to understand the preference towards that rather than perhaps the 
more general "Debugger tuning" sort of thing Paul's implemented/could be pushed 
up here.

On the LLVM side, debugger tuning is basically a way to package up settings for 
a variety of rather specific flags. Then the individual flags control their 
respective fine-grained behaviors.  This approach was very clearly favored 
during the whole "what is tuning" design discussion.

So, having an "emit explicit import" flag follows that same design decision and 
makes rather more sense than peppering IRGen with tuning or triple checks.  
Whether the flag goes in CodeGenOpt or somewhere else is a separate question.  
There are other debug-related flags in there, but if they want to be factored 
out into their own DebugInfoOpt that's probably a separate topic/patch.
--paulr

From: David Blaikie [mailto:dblai...@gmail.com]
Sent: Tuesday, September 08, 2015 7:36 PM
To: reviews+d12624+public+25876849b7c59...@reviews.llvm.org; Richard Smith
Cc: Romanova, Katya; Eric Christopher; Robinson, Paul; Adrian Prantl; 
cfe-commits
Subject: Re: [PATCH] D12624: Top-level anonymous namespaces are missing import 
DW_TAG_imported_module and nested anonymous namespaces are not



On Tue, Sep 8, 2015 at 3:51 PM, Richard Smith via cfe-commits 
> wrote:
rsmith added inline comments.


Comment at: lib/CodeGen/CGDebugInfo.cpp:3263-3264
@@ +3262,4 @@
+  const NamespaceDecl *NSDecl = UD.getNominatedNamespace();
+  if (!NSDecl->isAnonymousNamespace() ||
+  CGM.getTarget().getTriple().isPS4CPU()) {
+DBuilder.createImportedModule(

probinson wrote:
> rsmith wrote:
> > I think we should do this unconditionally, to better match the source 
> > language semantics, but I'm curious what David, Eric, and other folks on 
> > the DWARF side think.
> David (in previous discussions and review comments) has said he thinks it is 
> unnecessary as the debugger already must know so much about C++ to get 
> various things right, it might as well know that it has to implicitly import 
> the anonymous namespace contents.  One example debugger UI allows the user to 
> type source-like syntax, and requires the debugger to apply (for example) C++ 
> parameter-type matching rules to distinguish between overloaded functions.  
> Compared to this, implicit imports are child's play.
>
> I believe Eric agrees with David; I don't remember whether Adrian said 
> anything in the previous iterations of this patch.
>
> I believe the explicit (although artificial) import is a good thing, because 
> it matches the source language semantics.  I find an important distinction 
> between "which declarations are available in this scope" and "how does the 
> user disambiguate declarations in this scope."  As a counterpart to the above 
> debugger UI example, I postulate a GUI drop-down list of symbols available 
> in-scope; this UI needs to know nothing about language semantics and 
> automatic imports, if the DWARF provides the correct explicit import.  This 
> suggests to me that the DWARF should provide it.
>
> There's also the piddly detail that debuggers are not the only consumers of 
> DWARF information, and presenting the DWARF in a more source-language-neutral 
> way (i.e., with the explicit artificial import) could be beneficial for those 
> other consumers, who might not necessarily want to learn language-specific 
> scoping rules.
>
> No debugger will be thrown for a loop if it sees the explicit import; however 
> for some debuggers it would be redundant (because they implicitly import the 
> anonymous namespace already).  There is a pretty trivial space savings if 
> it's omitted.
>
> Katya has mentioned the GCC and ICC precedent; in fairness I will say GCC 
> didn't used to emit this, and GDB tolerated that.
>
> Note that the DWARF standard does not tell us what to do; it merely tells us 
> how to emit the import, if we want to emit one.  Whether we want to emit one 
> is up to us.
>
I've chatted to David about this offline, and he said largely similar things. 
It seems that different DWARF consumers will want and expect different things 
here, so (sadly) we should do different things depending on who we think will 
be consuming the DWARF.

I'm fine keeping this conditional, but I don't think IR generation should be 
making this decision based on the triple, so I'd prefer it was phrased in a 
different way: add a CodeGenOpt for whether to emit imports for anonymous 
namespaces, and enable it for PS4 targets from the frontend.

This seems pretty fine-grained for a CodeGenOpt (not that I've looked there, 
perhaps there are examples of similarly fine grained things already there?)- 
I'm curious to understand the preference towards that 

Re: [PATCH] D11797: [LIbClang] Report the named type for ElaboratedType

2015-09-09 Thread Sergey Kalinichev via cfe-commits
skalinichev updated this revision to Diff 34350.
skalinichev added a comment.

Yes, I've noticed that inconsistency too. But, seems like, this is an unrelated 
issue: TemplateSpecializationType type for some reasons uses id instead of qid 
(See also all other tests with templates in print-type.cpp, e.g. 
FieldDecl=baz). To get the type with nested name specifiers for the 
TemplateSpecializationType c-index-test should use the clang_getCanonicalType. 
But it doesn't  use it for pointers. (Compare c-index-test.c:1289 and 
c-index-test.c:1335)

Here I'm also adding an another test to show that nested name specifiers are 
not lost.


http://reviews.llvm.org/D11797

Files:
  test/Index/print-type.c
  test/Index/print-type.cpp
  tools/libclang/CXType.cpp

Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -121,6 +121,11 @@
 if (const DecayedType *DT = T->getAs()) {
   return MakeCXType(DT->getOriginalType(), TU);
 }
+
+/* Handle elaborated types as the original type */
+if (const auto *ET = T->getAs()) {
+  return MakeCXType(ET->getNamedType(), TU);
+}
   }
   if (TK == CXType_Invalid)
 TK = GetTypeKind(T);
@@ -388,7 +393,6 @@
 
   Decl *D = nullptr;
 
-try_again:
   switch (TP->getTypeClass()) {
   case Type::Typedef:
 D = cast(TP)->getDecl();
@@ -417,10 +421,6 @@
 
   // FIXME: Template type parameters!  
 
-  case Type::Elaborated:
-TP = cast(TP)->getNamedType().getTypePtrOrNull();
-goto try_again;
-
   default:
 break;
   }
Index: test/Index/print-type.cpp
===
--- test/Index/print-type.cpp
+++ test/Index/print-type.cpp
@@ -1,5 +1,7 @@
 namespace outer {
 
+struct NonTemplateStruct {};
+
 template
 struct Foo {
   T t;
@@ -15,6 +17,7 @@
 
 struct Bar {
   Bar(outer::Foo* foo) { }
+  Bar(outer::NonTemplateStruct* foo) { }
 
   typedef int FooType;
   int *p;
@@ -48,7 +51,7 @@
 };
 int Blob::*member_pointer;
 
-
+namespace NS { struct Type{}; } NS::Type elaboratedNamespaceType();
 
 auto autoI = 0;
 auto autoTbar = tbar(0);
@@ -58,89 +61,105 @@
 
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] [isPOD=0]
-// CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] [isPOD=0]
-// CHECK: TemplateTypeParameter=T:3:19 (Definition) [type=T] [typekind=Unexposed] [canonicaltype=type-parameter-0-0] [canonicaltypekind=Unexposed] [isPOD=0]
-// CHECK: FieldDecl=t:5:5 (Definition) [type=T] [typekind=Unexposed] [canonicaltype=type-parameter-0-0] [canonicaltypekind=Unexposed] [isPOD=0]
-// CHECK: TypeRef=T:3:19 [type=T] [typekind=Unexposed] [canonicaltype=type-parameter-0-0] [canonicaltypekind=Unexposed] [isPOD=0]
-// CHECK: ClassTemplate=Baz:9:8 (Definition) [type=] [typekind=Invalid] [isPOD=0]
-// CHECK: TemplateTypeParameter=T:8:20 (Definition) [type=T] [typekind=Unexposed] [canonicaltype=type-parameter-0-0] [canonicaltypekind=Unexposed] [isPOD=0]
-// CHECK: NonTypeTemplateParameter=U:8:32 (Definition) [type=unsigned int] [typekind=UInt] [isPOD=1]
-// CHECK: TemplateTemplateParameter=W:8:60 (Definition) [type=] [typekind=Invalid] [isPOD=0]
-// CHECK: Namespace=inner:14:11 (Definition) [type=] [typekind=Invalid] [isPOD=0]
-// CHECK: StructDecl=Bar:16:8 (Definition) [type=outer::inner::Bar] [typekind=Record] [isPOD=0] [nbFields=3]
-// CHECK: CXXConstructor=Bar:17:3 (Definition) [type=void (outer::Foo *){{.*}}] [typekind=FunctionProto] [canonicaltype=void (outer::Foo *){{.*}}] [canonicaltypekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [args= [outer::Foo *] [Pointer]] [isPOD=0]
-// CHECK: ParmDecl=foo:17:25 (Definition) [type=outer::Foo *] [typekind=Pointer] [canonicaltype=outer::Foo *] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=outer::Foo] [pointeekind=Unexposed]
+// CHECK: StructDecl=NonTemplateStruct:3:8 (Definition) [type=outer::NonTemplateStruct] [typekind=Record] [isPOD=1]
+// CHECK: ClassTemplate=Foo:6:8 (Definition) [type=] [typekind=Invalid] [isPOD=0]
+// CHECK: TemplateTypeParameter=T:5:19 (Definition) [type=T] [typekind=Unexposed] [canonicaltype=type-parameter-0-0] [canonicaltypekind=Unexposed] [isPOD=0]
+// CHECK: FieldDecl=t:7:5 (Definition) [type=T] [typekind=Unexposed] [canonicaltype=type-parameter-0-0] [canonicaltypekind=Unexposed] [isPOD=0]
+// CHECK: TypeRef=T:5:19 [type=T] [typekind=Unexposed] [canonicaltype=type-parameter-0-0] [canonicaltypekind=Unexposed] [isPOD=0]
+// CHECK: ClassTemplate=Baz:11:8 (Definition) [type=] [typekind=Invalid] [isPOD=0]
+// CHECK: TemplateTypeParameter=T:10:20 (Definition) [type=T] [typekind=Unexposed] [canonicaltype=type-parameter-0-0] [canonicaltypekind=Unexposed] [isPOD=0]
+// CHECK: NonTypeTemplateParameter=U:10:32 (Definition) [type=unsigned int] [typekind=UInt] [isPOD=1]
+// CHECK: TemplateTemplateParameter=W:10:60 

Re: [PATCH] D12247: [libc++] remove possible trailing padding from aligned_storage

2015-09-09 Thread Yiran Wang via cfe-commits
yiranwang added a comment.

Thank you, Eric. Also, could you please help to commit the change? I personally 
do not have the permissions to change libc++ code, thanks a lot.


http://reviews.llvm.org/D12247



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


Re: [PATCH] D12700: [clang-tidy] install helper scripts in CMake build

2015-09-09 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added a comment.

On my understanding share contains architecture-independent files.

clang-format files installation is also part of CMake build only.


http://reviews.llvm.org/D12700



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


Re: [PATCH] D12624: Top-level anonymous namespaces are missing import DW_TAG_imported_module and nested anonymous namespaces are not

2015-09-09 Thread Adrian Prantl via cfe-commits

> On Sep 8, 2015, at 3:08 PM, Paul Robinson 
>  wrote:
> 
> probinson added inline comments.
> 
> 
> Comment at: lib/CodeGen/CGDebugInfo.cpp:3263-3264
> @@ +3262,4 @@
> +  const NamespaceDecl *NSDecl = UD.getNominatedNamespace();
> +  if (!NSDecl->isAnonymousNamespace() || 
> +  CGM.getTarget().getTriple().isPS4CPU()) { 
> +DBuilder.createImportedModule(
> 
> rsmith wrote:
>> I think we should do this unconditionally, to better match the source 
>> language semantics, but I'm curious what David, Eric, and other folks on the 
>> DWARF side think.
> David (in previous discussions and review comments) has said he thinks it is 
> unnecessary as the debugger already must know so much about C++ to get 
> various things right, it might as well know that it has to implicitly import 
> the anonymous namespace contents.  One example debugger UI allows the user to 
> type source-like syntax, and requires the debugger to apply (for example) C++ 
> parameter-type matching rules to distinguish between overloaded functions.  
> Compared to this, implicit imports are child's play.
> 
> I believe Eric agrees with David; I don't remember whether Adrian said 
> anything in the previous iterations of this patch.

The information is redundant but otherwise harmless and there are other 
compilers that emit it and debuggers that came to expect it; this makes it look 
like a perfect candidate for a debugger tuning setting.

> 
> I believe the explicit (although artificial) import is a good thing, because 
> it matches the source language semantics.  I find an important distinction 
> between "which declarations are available in this scope" and "how does the 
> user disambiguate declarations in this scope."  As a counterpart to the above 
> debugger UI example, I postulate a GUI drop-down list of symbols available 
> in-scope; this UI needs to know nothing about language semantics and 
> automatic imports, if the DWARF provides the correct explicit import.  This 
> suggests to me that the DWARF should provide it.
> 
> There's also the piddly detail that debuggers are not the only consumers of 
> DWARF information, and presenting the DWARF in a more source-language-neutral 
> way (i.e., with the explicit artificial import) could be beneficial for those 
> other consumers, who might not necessarily want to learn language-specific 
> scoping rules.
> 
> No debugger will be thrown for a loop if it sees the explicit import; however 
> for some debuggers it would be redundant (because they implicitly import the 
> anonymous namespace already).  There is a pretty trivial space savings if 
> it's omitted.
> 
> Katya has mentioned the GCC and ICC precedent; in fairness I will say GCC 
> didn't used to emit this, and GDB tolerated that.
> 
> Note that the DWARF standard does not tell us what to do; it merely tells us 
> how to emit the import, if we want to emit one.  Whether we want to emit one 
> is up to us.

Appendix D.3 does give an (albeit non-normative) example of an anonymous 
top-level namespace without an explicit import.

-- adrian

> 
> http://reviews.llvm.org/D12624
> 
> 
> 

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


Re: r247049 - Module Debugging: Emit debug type information into clang modules.

2015-09-09 Thread David Blaikie via cfe-commits
On Wed, Sep 9, 2015 at 9:26 AM, Adrian Prantl  wrote:

>
> On Sep 8, 2015, at 8:05 PM, David Blaikie  wrote:
>
>
>
> On Tue, Sep 8, 2015 at 12:20 PM, Adrian Prantl via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: adrian
>> Date: Tue Sep  8 14:20:27 2015
>> New Revision: 247049
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=247049=rev
>> Log:
>> Module Debugging: Emit debug type information into clang modules.
>>
>> When -fmodule-format is set to "obj", emit debug info for all types
>> declared in a module or referenced by a declaration into the module's
>> object file container.
>>
>> This patch adds support for C and C++ types.
>>
>> Added:
>> cfe/trunk/test/Modules/Inputs/DebugCXX.h
>> cfe/trunk/test/Modules/ModuleDebugInfo.cpp
>> Modified:
>> cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
>> cfe/trunk/test/Modules/Inputs/module.map
>>
>> Modified: cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp?rev=247049=247048=247049=diff
>>
>> ==
>> --- cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp Tue Sep  8
>> 14:20:27 2015
>> @@ -50,6 +50,34 @@ class PCHContainerGenerator : public AST
>>raw_pwrite_stream *OS;
>>std::shared_ptr Buffer;
>>
>> +  /// Visit every type and emit debug info for it.
>> +  struct DebugTypeVisitor : public RecursiveASTVisitor
>> {
>> +clang::CodeGen::CGDebugInfo 
>> +ASTContext 
>> +DebugTypeVisitor(clang::CodeGen::CGDebugInfo , ASTContext )
>> +: DI(DI), Ctx(Ctx) {}
>> +
>> +/// Determine whether this type can be represented in DWARF.
>> +static bool CanRepresent(const Type *Ty) {
>> +  return !Ty->isDependentType() && !Ty->isUndeducedType();
>> +}
>> +
>> +bool VisitTypeDecl(TypeDecl *D) {
>>
>
> Does this only visit types defined in this module? Or also types otherwise
> referenced by this module? (does it only visit definitions, or also
> declarations?)
>
>
> Currently this does the wrong thing and emits all types referenced by this
> module because the patch that emits fwddecls for external types is not yet
> committed (though expected to land soon).
>

OK


>
>
>
>> +  QualType QualTy = Ctx.getTypeDeclType(D);
>> +  if (!QualTy.isNull() && CanRepresent(QualTy.getTypePtr()))
>> +DI.getOrCreateStandaloneType(QualTy, D->getLocation());
>> +  return true;
>> +}
>> +
>> +bool VisitValueDecl(ValueDecl *D) {
>>
>
> This seems strange - why would we put this type into the module debug
> info? (the type may be defined elsewhere, in another module, etc - just
> because there's a variable of that type defined in the module wouldn't
> imply that the module should contain a definition of the type, would it?
> That would seem to result in a lot of duplicate info)
>
>
> CGDebugInfo eventually will only emit type definitions for types defined
> in the current module, but that said, I think your argument is correct and
> this can safely be removed.
>

OK - having a multi-module test case that demonstrates why removing this
code improves things would be great (& that multi-module test case could
also demonstrate the "excess types" issue discussed above with a FIXME of
"this type isn't defined in this module, so we should omit it" or somesuch)


>
>
>
>> +  QualType QualTy = D->getType();
>> +  if (!QualTy.isNull() && CanRepresent(QualTy.getTypePtr()))
>> +DI.getOrCreateStandaloneType(QualTy, D->getLocation());
>> +  return true;
>> +}
>> +
>> +  };
>> +
>>  public:
>>PCHContainerGenerator(DiagnosticsEngine ,
>>  const HeaderSearchOptions ,
>> @@ -82,6 +110,36 @@ public:
>>  *Ctx, HeaderSearchOpts, PreprocessorOpts, CodeGenOpts, *M,
>> Diags));
>>}
>>
>> +  bool HandleTopLevelDecl(DeclGroupRef D) override {
>> +if (Diags.hasErrorOccurred() ||
>> +(CodeGenOpts.getDebugInfo() == CodeGenOptions::NoDebugInfo))
>> +  return true;
>> +
>> +// Collect debug info for all decls in this group.
>> +for (auto *I : D)
>> +  if (!I->isFromASTFile()) {
>> +DebugTypeVisitor DTV(*Builder->getModuleDebugInfo(), *Ctx);
>> +DTV.TraverseDecl(I);
>> +  }
>> +return true;
>> +  }
>> +
>> +  void HandleTagDeclDefinition(TagDecl *D) override {
>> +if (Diags.hasErrorOccurred())
>>
>
> Is it particularly useful to check for errors here (& in
> HandleTagDeclRequiredDefinition below)? That seems like a speed
> optimization for the slow case (we're emitting diagnostics anyway, the
> speed isn't too important - and we'll still have to be able to discard this
> work later in case we haven't seen errors yet, but we do see them later/by
> the end of the module?)
>
>
> This is 

r247160 - Fix a small bug in clang where generating some temporary files would have an extra period before the extension.

2015-09-09 Thread Argyrios Kyrtzidis via cfe-commits
Author: akirtzidis
Date: Wed Sep  9 11:48:47 2015
New Revision: 247160

URL: http://llvm.org/viewvc/llvm-project?rev=247160=rev
Log:
Fix a small bug in clang where generating some temporary files would have an 
extra period before the extension.

Patch by Cameron Esfahani!

Modified:
cfe/trunk/lib/ARCMigrate/FileRemapper.cpp
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp

Modified: cfe/trunk/lib/ARCMigrate/FileRemapper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/FileRemapper.cpp?rev=247160=247159=247160=diff
==
--- cfe/trunk/lib/ARCMigrate/FileRemapper.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/FileRemapper.cpp Wed Sep  9 11:48:47 2015
@@ -144,7 +144,7 @@ bool FileRemapper::flushToFile(StringRef
   SmallString<64> tempPath;
   int fd;
   if (fs::createTemporaryFile(path::filename(origFE->getName()),
-  path::extension(origFE->getName()), fd,
+  
path::extension(origFE->getName()).drop_front(), fd,
   tempPath))
 return report("Could not create file: " + tempPath.str(), Diag);
 

Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=247160=247159=247160=diff
==
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Wed Sep  9 11:48:47 2015
@@ -2218,7 +2218,7 @@ static std::string applyEditsToTemp(cons
   SmallString<64> TempPath;
   int FD;
   if (fs::createTemporaryFile(path::filename(FE->getName()),
-  path::extension(FE->getName()), FD,
+  path::extension(FE->getName()).drop_front(), FD,
   TempPath)) {
 reportDiag("Could not create file: " + TempPath.str(), Diag);
 return std::string();

Modified: cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp?rev=247160=247159=247160=diff
==
--- cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp Wed Sep  9 11:48:47 2015
@@ -78,7 +78,7 @@ public:
   std::string RewriteFilename(const std::string , int ) override {
 SmallString<128> Path;
 llvm::sys::fs::createTemporaryFile(llvm::sys::path::filename(Filename),
-   llvm::sys::path::extension(Filename), 
fd,
+   
llvm::sys::path::extension(Filename).drop_front(), fd,
Path);
 return Path.str();
   }


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


Re: [PATCH] D12700: [clang-tidy] install helper scripts in CMake build

2015-09-09 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

Not sure whether the scripts should go to share/clang or some other place. 
Sylvestre should know what's the common practice. Also, configure builds are 
still used for building packages, AFAIU, so they have to be modified as well 
(preferably, in the same patch).


http://reviews.llvm.org/D12700



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


r247179 - EmitRecordWith* API change: takes an ArrayRef instead of a SmallVector (NFC)

2015-09-09 Thread Mehdi Amini via cfe-commits
Author: mehdi_amini
Date: Wed Sep  9 15:08:51 2015
New Revision: 247179

URL: http://llvm.org/viewvc/llvm-project?rev=247179=rev
Log:
EmitRecordWith* API change: takes an ArrayRef instead of a SmallVector (NFC)

From: Mehdi Amini 

Modified:
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=247179=247178=247179=diff
==
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Wed Sep  9 15:08:51 2015
@@ -84,6 +84,7 @@ class ASTWriter : public ASTDeserializat
 public:
   typedef SmallVector RecordData;
   typedef SmallVectorImpl RecordDataImpl;
+  typedef ArrayRef RecordDataRef;
 
   friend class ASTDeclWriter;
   friend class ASTStmtWriter;
@@ -756,7 +757,7 @@ public:
   void AddPath(StringRef Path, RecordDataImpl );
 
   /// \brief Emit the current record with the given path as a blob.
-  void EmitRecordWithPath(unsigned Abbrev, RecordDataImpl ,
+  void EmitRecordWithPath(unsigned Abbrev, const RecordDataRef ,
   StringRef Path);
 
   /// \brief Add a version tuple to the given record

Modified: cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp?rev=247179=247178=247179=diff
==
--- cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp Wed Sep  9 15:08:51 
2015
@@ -51,6 +51,7 @@ public:
  
 typedef SmallVector RecordData;
 typedef SmallVectorImpl RecordDataImpl;
+typedef ArrayRef RecordDataRef;
 
 class SDiagsWriter;
   
@@ -393,13 +394,9 @@ unsigned SDiagsWriter::getEmitFile(const
   
   // Lazily generate the record for the file.
   entry = State->Files.size();
-  RecordData Record;
-  Record.push_back(RECORD_FILENAME);
-  Record.push_back(entry);
-  Record.push_back(0); // For legacy.
-  Record.push_back(0); // For legacy.
   StringRef Name(FileName);
-  Record.push_back(Name.size());
+  RecordDataRef Record = {RECORD_FILENAME, entry, 0 /* For legacy */,
+  0 /* For legacy */, Name.size()};
   State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_FILENAME), Record,
Name);
 
@@ -412,7 +409,7 @@ void SDiagsWriter::EmitCharSourceRange(C
   State->Record.push_back(RECORD_SOURCE_RANGE);
   AddCharSourceRangeToRecord(R, State->Record, SM);
   State->Stream.EmitRecordWithAbbrev(State->Abbrevs.get(RECORD_SOURCE_RANGE),
- State->Record);
+ makeArrayRef(State->Record));
 }
 
 /// \brief Emits the preamble of the diagnostics file.
@@ -531,14 +528,11 @@ void SDiagsWriter::EmitBlockInfoBlock()
 
 void SDiagsWriter::EmitMetaBlock() {
   llvm::BitstreamWriter  = State->Stream;
-  RecordData  = State->Record;
   AbbreviationMap  = State->Abbrevs;
 
   Stream.EnterSubblock(BLOCK_META, 3);
-  Record.clear();
-  Record.push_back(RECORD_VERSION);
-  Record.push_back(VersionNumber);
-  Stream.EmitRecordWithAbbrev(Abbrevs.get(RECORD_VERSION), Record);  
+  RecordDataRef Record = {RECORD_VERSION, VersionNumber};
+  Stream.EmitRecordWithAbbrev(Abbrevs.get(RECORD_VERSION), Record);
   Stream.ExitBlock();
 }
 
@@ -548,11 +542,8 @@ unsigned SDiagsWriter::getEmitCategory(u
 
   // We use a local version of 'Record' so that we can be generating
   // another record when we lazily generate one for the category entry.
-  RecordData Record;
-  Record.push_back(RECORD_CATEGORY);
-  Record.push_back(category);
   StringRef catName = DiagnosticIDs::getCategoryNameFromID(category);
-  Record.push_back(catName.size());
+  RecordDataRef Record = {RECORD_CATEGORY, category, catName.size()};
   State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_CATEGORY), Record,
catName);
   
@@ -581,10 +572,7 @@ unsigned SDiagsWriter::getEmitDiagnostic
 entry.second = FlagName;
 
 // Lazily emit the string in a separate record.
-RecordData Record;
-Record.push_back(RECORD_DIAG_FLAG);
-Record.push_back(entry.first);
-Record.push_back(FlagName.size());
+RecordDataRef Record = {RECORD_DIAG_FLAG, entry.first, FlagName.size()};
 State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_DIAG_FLAG),
  Record, FlagName);
   }
@@ -682,7 +670,8 @@ void SDiagsWriter::EmitDiagnosticMessage
   }
 
   Record.push_back(Message.size());
-  

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


Re: [PATCH] D12571: [Analyzer] Fix assertions in commit r246345 (pr22954).

2015-09-09 Thread pierre gousseau via cfe-commits
pgousseau added inline comments.


Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:843
@@ +842,3 @@
+  if (!Length)
+return true;
+

dcoughlin wrote:
> There doesn't seem to be a test that cares about this returning true (as 
> compared to false).
Will add thanks, f263 was the test meant for it.


Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:855
@@ +854,3 @@
+  if (!BufLoc)
+return true;
+

dcoughlin wrote:
> There doesn't appear to be a test that cares about this returning true (as 
> compared to false).
Will add thanks, f34 was the test meant for it.


Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:863
@@ +862,3 @@
+  if (!R)
+return true;
+

dcoughlin wrote:
> What's the rationale for treating the array access as in-bounds if the BufEnd 
> is unknown? Or if LengthValue is unknown? Should these branches return false? 
> Either way, can you add a comment explaining why this is the right thing to 
> do and also update the doc comment of IsFirstBufInBound to reflect this 
> behavior (e.g., "Returns true if destination buffer of copy function must/may 
> be in bound")
Yes I mean to return true in the case of an unknown array access to not warn on 
unknown state, will add comment thanks.


Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:1109
@@ +1108,3 @@
+  }
+  assert(RO.getOffset() >= 0 && "Offset should not be negative");
+  uint64_t LowerOffset = RO.getOffset();

dcoughlin wrote:
> This assertion is triggering on our internal build bots. I'm working to get a 
> reduced test case.
I can replace the assert by an if statement meanwhile ?


Comment at: test/Analysis/pr22954.c:739
@@ +738,3 @@
+// Test tainted values.
+struct yy {
+  char s1[4];

dcoughlin wrote:
> A question: how does this test tainted values?
Yes this comment is wrong, this is not testing tainted values. Will change 
comment and description thanks.


http://reviews.llvm.org/D12571



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


Re: [PATCH] D12571: [Analyzer] Fix assertions in commit r246345 (pr22954).

2015-09-09 Thread pierre gousseau via cfe-commits
pgousseau updated the summary for this revision.
pgousseau updated this revision to Diff 34359.
pgousseau added a comment.

Following Devin's review:
Correct test for unknown length and unknown destination buffer.
Add comment to 'IsFirstBufInBound' behavior regarding unknown states.
Remove comments regarding tainted values.
Replace assertion regarding negative Region offset by an if statement.

Thanks for reviewing !

Pierre


http://reviews.llvm.org/D12571

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  lib/StaticAnalyzer/Core/RegionStore.cpp
  test/Analysis/pr22954.c

Index: test/Analysis/pr22954.c
===
--- /dev/null
+++ test/Analysis/pr22954.c
@@ -0,0 +1,756 @@
+// Given code 'struct aa { char s1[4]; char * s2;} a; memcpy(a.s1, ...);',
+// this test checks that the CStringChecker only invalidates the destination buffer array a.s1 (instead of a.s1 and a.s2).
+// At the moment the whole of the destination array content is invalidated.
+// If a.s1 region has a symbolic offset, the whole region of 'a' is invalidated.
+// Specific triple set to test structures of size 0.
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-store=region -verify %s
+
+typedef __typeof(sizeof(int)) size_t;
+
+char *strdup(const char *s);
+void free(void *);
+void *memcpy(void *dst, const void *src, size_t n); // expected-note{{passing argument to parameter 'dst' here}}
+void *malloc(size_t n);
+
+void clang_analyzer_eval(int);
+
+struct aa {
+char s1[4];
+char *s2;
+};
+
+// Test different types of structure initialisation.
+int f0() {
+  struct aa a0 = {{1, 2, 3, 4}, 0};
+  a0.s2 = strdup("hello");
+  char input[] = {'a', 'b', 'c', 'd'};
+  memcpy(a0.s1, input, 4);
+  clang_analyzer_eval(a0.s1[0] == 'a'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a0.s1[1] == 'b'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a0.s1[2] == 'c'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a0.s1[3] == 'd'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a0.s2 == 0); // expected-warning{{UNKNOWN}}
+  free(a0.s2); // no warning
+  return 0;
+}
+
+int f1() {
+  struct aa a1;
+  a1.s2 = strdup("hello");
+  char input[] = {'a', 'b', 'c', 'd'};
+  memcpy(a1.s1, input, 4);
+  clang_analyzer_eval(a1.s1[0] == 'a'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a1.s1[1] == 'b'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a1.s1[2] == 'c'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a1.s1[3] == 'd'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a1.s2 == 0); // expected-warning{{UNKNOWN}}
+  free(a1.s2); // no warning
+  return 0;
+}
+
+int f2() {
+  struct aa a2 = {{1, 2}};
+  a2.s2 = strdup("hello");
+  char input[] = {'a', 'b', 'c', 'd'};
+  memcpy(a2.s1, input, 4);
+  clang_analyzer_eval(a2.s1[0] == 'a'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a2.s1[1] == 'b'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a2.s1[2] == 'c'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a2.s1[3] == 'd'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a2.s2 == 0); // expected-warning{{UNKNOWN}}
+  free(a2.s2); // no warning
+  return 0;
+}
+
+int f3() {
+  struct aa a3 = {{1, 2, 3, 4}, 0};
+  a3.s2 = strdup("hello");
+  char input[] = {'a', 'b', 'c', 'd'};
+  int * dest = (int*)a3.s1;
+  memcpy(dest, input, 4);
+  clang_analyzer_eval(a3.s1[0] == 'a'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(dest[0] == 'a'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a3.s1[1] == 'b'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(dest[1] == 'b'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a3.s1[2] == 'c'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(dest[2] == 'c'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a3.s1[3] == 'd'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(dest[3] == 'd'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(a3.s2 == 0); // expected-warning{{UNKNOWN}}
+  free(a3.s2); // no warning
+  return 0;
+}
+
+struct bb {
+  struct aa a;
+  char * s2;
+};
+
+int f4() {
+  struct bb b0 = {{1, 2, 3, 4}, 0};
+  b0.s2 = strdup("hello");
+  b0.a.s2 = strdup("hola");
+  char input[] = {'a', 'b', 'c', 'd'};
+  char * dest = (char*)(b0.a.s1);
+  memcpy(dest, input, 4);
+  clang_analyzer_eval(b0.a.s1[0] == 'a'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(dest[0] == 'a'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b0.a.s1[1] == 'b'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(dest[1] == 'b'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b0.a.s1[2] == 'c'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(dest[2] == 'c'); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(b0.a.s1[3] == 'd'); // expected-warning{{UNKNOWN}}
+  

PATCH: Expose the 'file' that is associated with a compile database command

2015-09-09 Thread Argyrios Kyrtzidis via cfe-commits
Hi,

The attached patch exposes the ‘file’ entry in a compilation database command, 
via the CompileCommand structure.



compile_db_file.patch
Description: Binary data
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12712: Implementation and testing for poisoning vtable ptr in dtor.

2015-09-09 Thread Evgeniy Stepanov via cfe-commits
eugenis added inline comments.


Comment at: lib/CodeGen/CGClass.cpp:1685
@@ +1684,3 @@
+// function
+Poison(CGF, VTablePtr, PoisonSize);
+  }

Did you mean to move this chunk to the other cleanup class?
Is there a test that would fail if vptr is prematurely poisoned? There should 
be one (it's ok if it is only in compiler-rt, this could be hard to test with 
lit over IR).



http://reviews.llvm.org/D12712



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


Re: [PATCH] D10018: C11 _Bool bitfield diagnostic

2015-09-09 Thread Hubert Tong via cfe-commits
hubert.reinterpretcast added inline comments.


Comment at: lib/Sema/SemaDecl.cpp:12586
@@ -12585,3 +12585,3 @@
   if (!FieldTy->isDependentType()) {
 uint64_t TypeSize = Context.getTypeSize(FieldTy);
 if (Value.getZExtValue() > TypeSize) {

rsmith wrote:
> I think the right way to fix this is to call `getIntWidth` here instead of 
> `getTypeSize`, and finesse our error message to clarify that we're talking 
> about the width of the type (the number of value bits) rather than the size 
> of the type (the number of storage bits).
The implementation of `getIntWidth` currently makes this consideration moot at 
this time, but should this extend to C89 (aside from the `_Bool` extension)?


http://reviews.llvm.org/D10018



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


Re: [PATCH] D12462: [PATCH] [clang-tidy] Add inconsistent declaration parameter name check

2015-09-09 Thread Piotr Dziwinski via cfe-commits
piotrdz updated this revision to Diff 34358.
piotrdz marked 6 inline comments as done.
piotrdz added a comment.

Again, addressed all review issues. I hope this is the final version


http://reviews.llvm.org/D12462

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
  clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-inconsistent-declaration-parameter-name.rst
  test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp

Index: test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp
===
--- test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp
+++ test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp
@@ -0,0 +1,188 @@
+// RUN: %python %S/check_clang_tidy.py %s readability-inconsistent-declaration-parameter-name %t
+
+void consistentFunction(int a, int b, int c);
+void consistentFunction(int a, int b, int c);
+void consistentFunction(int a, int b, int /*c*/);
+void consistentFunction(int /*c*/, int /*c*/, int /*c*/);
+
+//
+
+// CHECK-MESSAGES: :[[@LINE+1]]:6: warning: function 'inconsistentFunction' has 2 other declarations with different parameter names [readability-inconsistent-declaration-parameter-name]
+void inconsistentFunction(int a, int b, int c);
+// CHECK-MESSAGES: :[[@LINE+2]]:6: note: the 1st inconsistent declaration seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('d', 'e', 'f'), in the other declaration: ('a', 'b', 'c')
+void inconsistentFunction(int d, int e, int f);
+// CHECK-MESSAGES: :[[@LINE+2]]:6: note: the 2nd inconsistent declaration seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('x', 'y', 'z'), in the other declaration: ('a', 'b', 'c')
+void inconsistentFunction(int x, int y, int z);
+
+//
+
+// CHECK-MESSAGES: :[[@LINE+4]]:6: warning: function 'inconsistentFunctionWithVisibleDefinition' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name]
+// CHECK-MESSAGES: :[[@LINE+9]]:6: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+2]]:6: note: differing parameters are named here: ('a'), in definition: ('c')
+// CHECK-FIXES: void inconsistentFunctionWithVisibleDefinition(int c);
+void inconsistentFunctionWithVisibleDefinition(int a);
+// CHECK-MESSAGES: :[[@LINE+4]]:6: warning: function 'inconsistentFunctionWithVisibleDefinition' has a definition
+// CHECK-MESSAGES: :[[@LINE+4]]:6: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+2]]:6: note: differing parameters are named here: ('b'), in definition: ('c')
+// CHECK-FIXES: void inconsistentFunctionWithVisibleDefinition(int c);
+void inconsistentFunctionWithVisibleDefinition(int b);
+void inconsistentFunctionWithVisibleDefinition(int c) { c; }
+
+// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function 'inconsidentFunctionWithUnreferencedParameterInDefinition' has a definition
+// CHECK-MESSAGES: :[[@LINE+3]]:6: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('a'), in definition: ('b')
+void inconsidentFunctionWithUnreferencedParameterInDefinition(int a);
+void inconsidentFunctionWithUnreferencedParameterInDefinition(int b) {}
+
+//
+
+struct Struct {
+// CHECK-MESSAGES: :[[@LINE+4]]:8: warning: function 'Struct::inconsistentFunction' has a definition
+// CHECK-MESSAGES: :[[@LINE+6]]:14: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+2]]:8: note: differing parameters are named here: ('a'), in definition: ('b')
+// CHECK-FIXES: void inconsistentFunction(int b);
+  void inconsistentFunction(int a);
+};
+
+void Struct::inconsistentFunction(int b) { b = 0; }
+
+//
+
+struct SpecialFunctions {
+// CHECK-MESSAGES: :[[@LINE+4]]:3: warning: function 'SpecialFunctions::SpecialFunctions' has a definition
+// CHECK-MESSAGES: :[[@LINE+12]]:19: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+2]]:3: note: differing parameters are named here: ('a'), in definition: ('b')
+// CHECK-FIXES: SpecialFunctions(int b);
+  SpecialFunctions(int a);
+
+// CHECK-MESSAGES: :[[@LINE+4]]:21: warning: function 'SpecialFunctions::operator=' has a definition
+// CHECK-MESSAGES: :[[@LINE+8]]:37: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+2]]:21: note: differing parameters are named here: ('a'), in definition: ('b')
+// CHECK-FIXES: SpecialFunctions& operator=(const SpecialFunctions& b);
+  SpecialFunctions& operator=(const SpecialFunctions& a);
+};
+
+SpecialFunctions::SpecialFunctions(int b) 

Re: [PATCH] D12453: [CUDA] Allow function overloads based on host/device attributes.

2015-09-09 Thread Artem Belevich via cfe-commits
tra updated this revision to Diff 34368.
tra added a comment.

Implemented pcc@'s suggestion to disallow mixing HD and H/D functions.
Removed name mangling as it's no longer needed. Restriction on HD overloading 
guarantees that we'll emit only one viable function during particular side of 
compilation (H or HD on the host side, D or HD on device side).
Updated test cases to reflect reduced number of attribute combinations we need 
to deal with now.


http://reviews.llvm.org/D12453

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Driver/CC1Options.td
  include/clang/Sema/Sema.h
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaCUDA.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaOverload.cpp
  test/CodeGenCUDA/function-overload.cu
  test/SemaCUDA/function-overload.cu

Index: test/SemaCUDA/function-overload.cu
===
--- /dev/null
+++ test/SemaCUDA/function-overload.cu
@@ -0,0 +1,317 @@
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+
+// Make sure we handle target overloads correctly.
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu \
+// RUN:-fsyntax-only -fcuda-target-overloads -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda \
+// RUN:-fsyntax-only -fcuda-target-overloads -fcuda-is-device -verify %s
+
+// Check target overloads handling with disabled call target checks.
+// RUN: %clang_cc1 -DNOCHECKS -triple x86_64-unknown-linux-gnu -fsyntax-only \
+// RUN:-fcuda-disable-target-call-checks -fcuda-target-overloads -verify %s
+// RUN: %clang_cc1 -DNOCHECKS -triple nvptx64-nvidia-cuda -fsyntax-only \
+// RUN:-fcuda-disable-target-call-checks -fcuda-target-overloads \
+// RUN:-fcuda-is-device -verify %s
+
+#include "Inputs/cuda.h"
+
+typedef int (*fp_t)(void);
+typedef void (*gp_t)(void);
+
+// Host and unattributed functions can't be overloaded
+__host__ int hh(void) { return 1; } // expected-note {{previous definition is here}}
+int hh(void) { return 1; } // expected-error {{redefinition of 'hh'}}
+
+// H/D overloading is OK
+__host__ int dh(void) { return 2; }
+__device__ int dh(void) { return 2; }
+
+// H/HD and D/HD are not allowed
+__host__ __device__ int hdh(void) { return 5; } // expected-note {{previous definition is here}}
+__host__ int hdh(void) { return 4; } // expected-error {{redefinition of 'hdh'}}
+
+__host__ int hhd(void) { return 4; } // expected-note {{previous definition is here}}
+__host__ __device__ int hhd(void) { return 5; } // expected-error {{redefinition of 'hhd'}}
+// expected-warning@-1 {{attribute declaration must precede definition}}
+// expected-note@-3 {{previous definition is here}}
+
+__host__ __device__ int hdd(void) { return 7; } // expected-note {{previous definition is here}}
+__device__ int hdd(void) { return 6; } // expected-error {{redefinition of 'hdd'}}
+
+__device__ int dhd(void) { return 6; } // expected-note {{previous definition is here}}
+__host__ __device__ int dhd(void) { return 7; } // expected-error {{redefinition of 'dhd'}}
+// expected-warning@-1 {{attribute declaration must precede definition}}
+// expected-note@-3 {{previous definition is here}}
+
+// Same tests for extern "C" functions
+extern "C" __host__ int chh(void) {return 11;} // expected-note {{previous definition is here}}
+extern "C" int chh(void) {return 11;} // expected-error {{redefinition of 'chh'}}
+
+// H/D overloading is OK
+extern "C" __device__ int cdh(void) {return 10;}
+extern "C" __host__ int cdh(void) {return 11;}
+
+// H/HD and D/HD overloading is not allowed.
+extern "C" __host__ __device__ int chhd1(void) {return 12;} // expected-note {{previous definition is here}}
+extern "C" __host__ int chhd1(void) {return 13;} // expected-error {{redefinition of 'chhd1'}}
+
+extern "C" __host__ int chhd2(void) {return 13;} // expected-note {{previous definition is here}}
+extern "C" __host__ __device__ int chhd2(void) {return 12;} // expected-error {{redefinition of 'chhd2'}}
+// expected-warning@-1 {{attribute declaration must precede definition}}
+// expected-note@-3 {{previous definition is here}}
+
+// Helper functions to verify calling restrictions.
+__device__ int d(void) { return 8; }
+__host__ int h(void) { return 9; }
+__global__ void g(void) {}
+extern "C" __device__ int cd(void) {return 10;}
+extern "C" __host__ int ch(void) {return 11;}
+
+__host__ void hostf(void) {
+  fp_t dp = d;
+  fp_t cdp = cd;
+#if !defined(NOCHECKS)
+  // expected-error@-3 {{reference to __device__ function 'd' in __host__ function}}
+  // expected-note@65 {{'d' declared here}}
+  // expected-error@-4 {{reference to __device__ function 'cd' in __host__ function}}
+  // expected-note@68 {{'cd' declared here}}
+#endif
+  fp_t hp = h;
+  fp_t chp = ch;
+  fp_t dhp = dh;
+  fp_t cdhp = cdh;
+  gp_t gp = g;
+
+  d();
+  cd();
+#if !defined(NOCHECKS)
+  // expected-error@-3 {{no matching function for call to 'd'}}
+  // expected-note@65 {{candidate