[PATCH] D14484: Formatting constructor initializer lists by putting them always on different lines

2015-11-08 Thread JVApen via cfe-commits
JVApen created this revision.
JVApen added a reviewer: djasper.
JVApen added a subscriber: cfe-commits.
JVApen set the repository for this revision to rL LLVM.
Herald added a subscriber: klimek.

Hi all,

I've been playing around with the clang for a while now and really enjoy it. 
Unfortunately clang-format does not yet do what I like it to do, so I started 
hacking it. So here is my first successful attempt to get something working.

The issue: ConstructorInitializerAllOnOneLineOrOnePerLine only works if 'If the 
constructor initializers don’t fit on a line', while I prefer it to always 
work. In other words, I use the following formatting:

```
Constructor()
  : a(a)
  , b(b)
```

Since everyone can benefit from upstreaming, I like to share my changes and get 
some feedback.
Here is already some of the stuff which I was uncertain about:

  - Should I keep ConstructorInitializerAllOnOneLineOrOnePerLine or rename it 
(currently the second one)
  - How to name the values, currently: Compact (old: false), BestFit (old: 
true), OnePerLine (new)
  - Is the back-ward compatibility in ScalarEnumerationTraits a good idea? (On 
rename most likely not)

JVApen



Repository:
  rL LLVM

http://reviews.llvm.org/D14484

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -3586,8 +3586,51 @@
"  aaa(aaa),\n"
"  at() {}");

+  FormatStyle BestFit = getLLVMStyle();
+  BestFit.ConstructorInitializer = FormatStyle::CI_BestFit;
+  verifyFormat("SomeClass::Constructor()\n"
+   ": a(aa),\n"
+   "  a(aa),\n"
+   "  a(aa) {}",
+   BestFit);
+  verifyFormat("SomeClass::Constructor()\n"
+   ": a(aa), // Some comment\n"
+   "  a(aa),\n"
+   "  a(aa) {}",
+   BestFit);
+  verifyFormat("MyClass::MyClass(int var)\n"
+   ": some_var_(var),// 4 space indent\n"
+   "  some_other_var_(var + 1) { // lined up\n"
+   "}",
+   BestFit);
+  verifyFormat("Constructor() : a(a), a(a) {}\n",
+   BestFit);
+  verifyFormat("Constructor()\n"
+   ": a(aa),\n"
+   "  a(aa),\n"
+   "  a(aa),\n"
+   "  a(aa),\n"
+   "  a(aa) {}",
+   BestFit);
+  verifyFormat("Constructor()\n"
+   ": a(aa, aa,\n"
+   "aa) {}",
+   BestFit);
+  BestFit.ColumnLimit = 60;
+  verifyFormat("Constructor()\n"
+   ": (a),\n"
+   "  (b) {}",
+   BestFit);
+
+  EXPECT_EQ("Constructor()\n"
+": // Comment forcing unwanted break.\n"
+"  () {}",
+format("Constructor() :\n"
+   "// Comment forcing unwanted break.\n"
+   "() {}"));
+
   FormatStyle OnePerLine = getLLVMStyle();
-  OnePerLine.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
+  OnePerLine.ConstructorInitializer = FormatStyle::CI_OnePerLine;
   verifyFormat("SomeClass::Constructor()\n"
": a(aa),\n"
"  a(aa),\n"
@@ -3604,6 +3647,10 @@
"}",
OnePerLine);
   verifyFormat("Constructor()\n"
+   ": a(a),\n"
+   "  a(a) {}",
+   OnePerLine);
+  verifyFormat("Constructor()\n"
": a(aa),\n"
"  a(aa),\n"
"  a(aa),\n"
@@ -3696,7 +3743,7 @@

   // This test takes VERY long when memoization is broken.
   FormatStyle OnePerLine = getLLVMStyle();
-  OnePerLine.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
+  OnePerLine.ConstructorInitializer = FormatStyle::CI_BestFit;
   OnePerLine.BinPackParameters = false;
   std::string input = "Constructor()\n"
   ": (a,\n";
@@ -9560,7 +9607,6 @@
   CHECK_PARSE_BOOL(BinPackParameters);
   CHECK_PARSE_BOOL(BreakBeforeTernaryOperators);
   CHECK_PARSE_BOOL(BreakConstructorInitializersBeforeComma);
-  CHECK_PARSE_BOOL(ConstructorInitializerAllOnOneLineOrOnePerLine);
   CHECK_PARSE_BOOL(DerivePointerAlignment);
   CHECK_PARSE_B

Re: [PATCH] D14484: Formatting constructor initializer lists by putting them always on different lines

2015-11-08 Thread Daniel Jasper via cfe-commits
Please read
http://clang.llvm.org/docs/ClangFormatStyleOptions.html#adding-additional-style-options

Does your style option qualify?

On Sun, Nov 8, 2015 at 8:04 AM, JVApen  wrote:

> JVApen created this revision.
> JVApen added a reviewer: djasper.
> JVApen added a subscriber: cfe-commits.
> JVApen set the repository for this revision to rL LLVM.
> Herald added a subscriber: klimek.
>
> Hi all,
>
> I've been playing around with the clang for a while now and really enjoy
> it. Unfortunately clang-format does not yet do what I like it to do, so I
> started hacking it. So here is my first successful attempt to get something
> working.
>
> The issue: ConstructorInitializerAllOnOneLineOrOnePerLine only works if
> 'If the constructor initializers don’t fit on a line', while I prefer it to
> always work. In other words, I use the following formatting:
>
> ```
> Constructor()
>   : a(a)
>   , b(b)
> ```
>
> Since everyone can benefit from upstreaming, I like to share my changes
> and get some feedback.
> Here is already some of the stuff which I was uncertain about:
>
>   - Should I keep ConstructorInitializerAllOnOneLineOrOnePerLine or rename
> it (currently the second one)
>   - How to name the values, currently: Compact (old: false), BestFit (old:
> true), OnePerLine (new)
>   - Is the back-ward compatibility in ScalarEnumerationTraits a good idea?
> (On rename most likely not)
>
> JVApen
>
>
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D14484
>
> Files:
>   docs/ClangFormatStyleOptions.rst
>   include/clang/Format/Format.h
>   lib/Format/ContinuationIndenter.cpp
>   lib/Format/Format.cpp
>   lib/Format/TokenAnnotator.cpp
>   unittests/Format/FormatTest.cpp
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D14484: Formatting constructor initializer lists by putting them always on different lines

2015-11-08 Thread JVApen via cfe-commits
JVApen added a comment.

In http://reviews.llvm.org/D14484#284767, @djasper wrote:

> Please read
>  
> http://clang.llvm.org/docs/ClangFormatStyleOptions.html#adding-additional-style-options
>
> Does your style option qualify?




- Is it used by a project of significant size? Yes, we use the same style at 
work, where I try to get this used by about 70 developers. (Which I consider 
already dozens of contributors) Though it is also the same style I learned at 
school.
- Does it have a publicly accessible style guide? Yes, it's both an accepted by 
the Google Style guide 

 as Ubuntu Unity 
,
 which do not state that you have to use the compact form. Further more the 
graphisoft 

 styleguide doesn't appear to allow the condensed form.
- Does it have a person willing to contribute and maintain patches? Maybe, I 
currently don't believe I'm familiar enough with the code to maintain it. 
Though without putting it out here (e.g. LLVM community) the answer will 
definitely be no. Furthermore, beside the 2 lines in TokenAnnotator.cpp, this 
style does not differentiate from the current implementation.

Though since you are the/a maintainer of this code, you are more qualified to 
give a final answer on this question.

Regardless, even if you don't want this patch upstreamed, I like to understand 
the codebase better as well as the considerations which lead to certain 
decisions for code changes. (See also the uncertainties I listed in the 
original post) Which at least will make my local changes similar to what they 
would be in case you would allow an upstream of them.


Repository:
  rL LLVM

http://reviews.llvm.org/D14484



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


Re: [PATCH] D14215: Disable frame pointer elimination when using -pg

2015-11-08 Thread Stefan Kempf via cfe-commits
sisnkemp updated this revision to Diff 39651.

http://reviews.llvm.org/D14215

Files:
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/x86_64-profiling-keep-fp.c

Index: test/CodeGen/x86_64-profiling-keep-fp.c
===
--- /dev/null
+++ test/CodeGen/x86_64-profiling-keep-fp.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -O3 -pg -S -o - %s | \
+// RUN:   FileCheck %s
+
+// Test that the frame pointer is kept when compiling with
+// profiling.
+
+//CHECK: pushq %rbp
+int main(void)
+{
+  return 0;
+}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -452,7 +452,8 @@
   Opts.CXXCtorDtorAliases = Args.hasArg(OPT_mconstructor_aliases);
   Opts.CodeModel = getCodeModel(Args, Diags);
   Opts.DebugPass = Args.getLastArgValue(OPT_mdebug_pass);
-  Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim);
+  Opts.DisableFPElim =
+  (Args.hasArg(OPT_mdisable_fp_elim) || Args.hasArg(OPT_pg));
   Opts.DisableFree = Args.hasArg(OPT_disable_free);
   Opts.DisableTailCalls = Args.hasArg(OPT_mdisable_tail_calls);
   Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -2717,6 +2717,8 @@
   if (Arg *A = Args.getLastArg(options::OPT_fno_omit_frame_pointer,
options::OPT_fomit_frame_pointer))
 return A->getOption().matches(options::OPT_fno_omit_frame_pointer);
+  if (Args.hasArg(options::OPT_pg))
+return true;
 
   return shouldUseFramePointerForTarget(Args, Triple);
 }
@@ -2726,6 +2728,8 @@
   if (Arg *A = Args.getLastArg(options::OPT_mno_omit_leaf_frame_pointer,
options::OPT_momit_leaf_frame_pointer))
 return A->getOption().matches(options::OPT_mno_omit_leaf_frame_pointer);
+  if (Args.hasArg(options::OPT_pg))
+return true;
 
   if (Triple.isPS4CPU())
 return false;


Index: test/CodeGen/x86_64-profiling-keep-fp.c
===
--- /dev/null
+++ test/CodeGen/x86_64-profiling-keep-fp.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -O3 -pg -S -o - %s | \
+// RUN:   FileCheck %s
+
+// Test that the frame pointer is kept when compiling with
+// profiling.
+
+//CHECK: pushq %rbp
+int main(void)
+{
+  return 0;
+}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -452,7 +452,8 @@
   Opts.CXXCtorDtorAliases = Args.hasArg(OPT_mconstructor_aliases);
   Opts.CodeModel = getCodeModel(Args, Diags);
   Opts.DebugPass = Args.getLastArgValue(OPT_mdebug_pass);
-  Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim);
+  Opts.DisableFPElim =
+  (Args.hasArg(OPT_mdisable_fp_elim) || Args.hasArg(OPT_pg));
   Opts.DisableFree = Args.hasArg(OPT_disable_free);
   Opts.DisableTailCalls = Args.hasArg(OPT_mdisable_tail_calls);
   Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -2717,6 +2717,8 @@
   if (Arg *A = Args.getLastArg(options::OPT_fno_omit_frame_pointer,
options::OPT_fomit_frame_pointer))
 return A->getOption().matches(options::OPT_fno_omit_frame_pointer);
+  if (Args.hasArg(options::OPT_pg))
+return true;
 
   return shouldUseFramePointerForTarget(Args, Triple);
 }
@@ -2726,6 +2728,8 @@
   if (Arg *A = Args.getLastArg(options::OPT_mno_omit_leaf_frame_pointer,
options::OPT_momit_leaf_frame_pointer))
 return A->getOption().matches(options::OPT_mno_omit_leaf_frame_pointer);
+  if (Args.hasArg(options::OPT_pg))
+return true;
 
   if (Triple.isPS4CPU())
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D14215: Disable frame pointer elimination when using -pg

2015-11-08 Thread Stefan Kempf via cfe-commits
sisnkemp added a comment.

Ping. Can somebody please comment on this?


http://reviews.llvm.org/D14215



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


[clang-tools-extra] r252425 - [clang-tidy] add new check cppcoreguidelines-pro-type-cstyle-cast

2015-11-08 Thread Matthias Gehre via cfe-commits
Author: mgehre
Date: Sun Nov  8 15:10:39 2015
New Revision: 252425

URL: http://llvm.org/viewvc/llvm-project?rev=252425&view=rev
Log:
[clang-tidy] add new check cppcoreguidelines-pro-type-cstyle-cast

Summary:
This check flags all use of c-style casts that perform a static_cast
downcast, const_cast, or reinterpret_cast.

Use of these casts can violate type safety and cause the program to
access a
variable that is actually of type X to be accessed as if it were of an
unrelated type Z. Note that a C-style (T)expression cast means to
perform
the first of the following that is possible: a const_cast, a
static_cast, a
static_cast followed by a const_cast, a reinterpret_cast, or a
reinterpret_cast followed by a const_cast. This rule bans (T)expression
only when used to perform an unsafe cast.

This rule is part of the "Type safety" profile of the C++ Core
Guidelines, see
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type4-dont-use-c-style-texpression-casts-that-would-perform-a-static_cast-downcast-const_cast-or-reinterpret_cast.

Reviewers: alexfh, sbenza, bkramer, aaron.ballman

Subscribers: cfe-commits

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

Added:

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

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-type-cstyle-cast.rst

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-cstyle-cast.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt?rev=252425&r1=252424&r2=252425&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt Sun Nov 
 8 15:10:39 2015
@@ -5,6 +5,7 @@ add_clang_library(clangTidyCppCoreGuidel
   ProBoundsArrayToPointerDecayCheck.cpp
   ProBoundsPointerArithmeticCheck.cpp
   ProTypeConstCastCheck.cpp
+  ProTypeCstyleCastCheck.cpp
   ProTypeReinterpretCastCheck.cpp
   ProTypeStaticCastDowncastCheck.cpp
   ProTypeUnionAccessCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp?rev=252425&r1=252424&r2=252425&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 Sun Nov  8 15:10:39 2015
@@ -14,6 +14,7 @@
 #include "ProBoundsArrayToPointerDecayCheck.h"
 #include "ProBoundsPointerArithmeticCheck.h"
 #include "ProTypeConstCastCheck.h"
+#include "ProTypeCstyleCastCheck.h"
 #include "ProTypeReinterpretCastCheck.h"
 #include "ProTypeStaticCastDowncastCheck.h"
 #include "ProTypeUnionAccessCheck.h"
@@ -33,6 +34,8 @@ public:
 "cppcoreguidelines-pro-bounds-pointer-arithmetic");
 CheckFactories.registerCheck(
 "cppcoreguidelines-pro-type-const-cast");
+CheckFactories.registerCheck(
+"cppcoreguidelines-pro-type-cstyle-cast");
 CheckFactories.registerCheck(
 "cppcoreguidelines-pro-type-reinterpret-cast");
 CheckFactories.registerCheck(

Added: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp?rev=252425&view=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp 
(added)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp 
Sun Nov  8 15:10:39 2015
@@ -0,0 +1,107 @@
+//===--- ProTypeCstyleCastCheck.cpp - 
clang-tidy---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ProTypeCstyleCastCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+
+static bool needsConstCast(QualType So

Re: [PATCH] D14096: [clang-tidy] add new check cppcoreguidelines-pro-type-cstyle-cast

2015-11-08 Thread Matthias Gehre via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL252425: [clang-tidy] add new check 
cppcoreguidelines-pro-type-cstyle-cast (authored by mgehre).

Changed prior to commit:
  http://reviews.llvm.org/D14096?vs=39576&id=39655#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D14096

Files:
  clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt
  
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp
  clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.h
  
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-type-cstyle-cast.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-cstyle-cast.cpp

Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.h
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.h
@@ -0,0 +1,34 @@
+//===--- ProTypeCstyleCastCheck.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_CSTYLE_CAST_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_CSTYLE_CAST_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+
+/// This check flags all use of C-style casts that perform a static_cast
+/// downcast, const_cast, or reinterpret_cast.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-pro-type-cstyle-cast.html
+class ProTypeCstyleCastCheck : public ClangTidyCheck {
+public:
+  ProTypeCstyleCastCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_CSTYLE_CAST_H
Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -14,6 +14,7 @@
 #include "ProBoundsArrayToPointerDecayCheck.h"
 #include "ProBoundsPointerArithmeticCheck.h"
 #include "ProTypeConstCastCheck.h"
+#include "ProTypeCstyleCastCheck.h"
 #include "ProTypeReinterpretCastCheck.h"
 #include "ProTypeStaticCastDowncastCheck.h"
 #include "ProTypeUnionAccessCheck.h"
@@ -33,6 +34,8 @@
 "cppcoreguidelines-pro-bounds-pointer-arithmetic");
 CheckFactories.registerCheck(
 "cppcoreguidelines-pro-type-const-cast");
+CheckFactories.registerCheck(
+"cppcoreguidelines-pro-type-cstyle-cast");
 CheckFactories.registerCheck(
 "cppcoreguidelines-pro-type-reinterpret-cast");
 CheckFactories.registerCheck(
Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp
@@ -0,0 +1,107 @@
+//===--- ProTypeCstyleCastCheck.cpp - clang-tidy---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ProTypeCstyleCastCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+
+static bool needsConstCast(QualType SourceType, QualType DestType) {
+  SourceType = SourceType.getNonReferenceType();
+  DestType = DestType.getNonReferenceType();
+  while (SourceType->isPointerType() && DestType->isPointerType()) {
+SourceType = SourceType->getPointeeType();
+DestType = DestType->getPointeeType();
+if (SourceType.isConstQualified() && !DestType.isConstQualified())
+  return true;
+  }
+  return false;
+}
+
+void ProTypeCstyleCastCheck::registerMatchers(MatchFinder *

r252426 - Replace tab with 8 spaces, NFC.

2015-11-08 Thread Yaron Keren via cfe-commits
Author: yrnkrn
Date: Sun Nov  8 16:01:45 2015
New Revision: 252426

URL: http://llvm.org/viewvc/llvm-project?rev=252426&view=rev
Log:
Replace tab with 8 spaces, NFC.


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=252426&r1=252425&r2=252426&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Sun Nov  8 16:01:45 2015
@@ -1517,7 +1517,7 @@ void CodeGenModule::ConstructAttributeLi
   getTarget().getTargetOpts().FeaturesAsWritten.end());
 
   if (ParsedAttr.second != "")
-   TargetCPU = ParsedAttr.second;
+TargetCPU = ParsedAttr.second;
 
   // Now populate the feature map, first with the TargetCPU which is either
   // the default or a new one from the target attribute string. Then we'll


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


r252434 - [PGO] Code cleanup [NFC]

2015-11-08 Thread Xinliang David Li via cfe-commits
Author: davidxl
Date: Sun Nov  8 18:04:16 2015
New Revision: 252434

URL: http://llvm.org/viewvc/llvm-project?rev=252434&view=rev
Log:
[PGO] Code cleanup [NFC]

Use interfaces defined in LLVM to create FuncName
and FuncNameVar.

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

Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=252434&r1=252433&r2=252434&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Sun Nov  8 18:04:16 2015
@@ -28,58 +28,17 @@ using namespace CodeGen;
 
 void CodeGenPGO::setFuncName(StringRef Name,
  llvm::GlobalValue::LinkageTypes Linkage) {
-  StringRef RawFuncName = Name;
-
-  // Function names may be prefixed with a binary '1' to indicate
-  // that the backend should not modify the symbols due to any platform
-  // naming convention. Do not include that '1' in the PGO profile name.
-  if (RawFuncName[0] == '\1')
-RawFuncName = RawFuncName.substr(1);
-
-  FuncName = RawFuncName;
-  if (llvm::GlobalValue::isLocalLinkage(Linkage)) {
-// For local symbols, prepend the main file name to distinguish them.
-// Do not include the full path in the file name since there's no guarantee
-// that it will stay the same, e.g., if the files are checked out from
-// version control in different locations.
-if (CGM.getCodeGenOpts().MainFileName.empty())
-  FuncName = FuncName.insert(0, ":");
-else
-  FuncName = FuncName.insert(0, CGM.getCodeGenOpts().MainFileName + ":");
-  }
+  FuncName = llvm::getPGOFuncName(Name, Linkage, 
CGM.getCodeGenOpts().MainFileName);
 
   // If we're generating a profile, create a variable for the name.
   if (CGM.getCodeGenOpts().ProfileInstrGenerate)
-createFuncNameVar(Linkage);
+FuncNameVar = llvm::createPGOFuncNameVar(CGM.getModule(), Linkage, 
FuncName);
 }
 
 void CodeGenPGO::setFuncName(llvm::Function *Fn) {
   setFuncName(Fn->getName(), Fn->getLinkage());
 }
 
-void CodeGenPGO::createFuncNameVar(llvm::GlobalValue::LinkageTypes Linkage) {
-  // We generally want to match the function's linkage, but 
available_externally
-  // and extern_weak both have the wrong semantics, and anything that doesn't
-  // need to link across compilation units doesn't need to be visible at all.
-  if (Linkage == llvm::GlobalValue::ExternalWeakLinkage)
-Linkage = llvm::GlobalValue::LinkOnceAnyLinkage;
-  else if (Linkage == llvm::GlobalValue::AvailableExternallyLinkage)
-Linkage = llvm::GlobalValue::LinkOnceODRLinkage;
-  else if (Linkage == llvm::GlobalValue::InternalLinkage ||
-   Linkage == llvm::GlobalValue::ExternalLinkage)
-Linkage = llvm::GlobalValue::PrivateLinkage;
-
-  auto *Value =
-  llvm::ConstantDataArray::getString(CGM.getLLVMContext(), FuncName, 
false);
-  FuncNameVar =
-  new llvm::GlobalVariable(CGM.getModule(), Value->getType(), true, 
Linkage,
-   Value, llvm::getInstrProfNameVarPrefix() + 
FuncName);
-
-  // Hide the symbol so that we correctly get a copy for each executable.
-  if (!llvm::GlobalValue::isLocalLinkage(FuncNameVar->getLinkage()))
-FuncNameVar->setVisibility(llvm::GlobalValue::HiddenVisibility);
-}
-
 namespace {
 /// \brief Stable hasher for PGO region counters.
 ///


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


Re: [PATCH] D14134: [OpenMP] Parsing and sema support for map clause

2015-11-08 Thread Kelvin Li via cfe-commits
kkwli0 added a comment.

Ping


http://reviews.llvm.org/D14134



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


Re: [PATCH] D14286: ASTImporter: expressions, pt.1

2015-11-08 Thread Serge Pavlov via cfe-commits
2015-11-06 20:28 GMT+06:00 Aleksei Sidorin :

> a.sidorin marked 7 inline comments as done.
> a.sidorin added a comment.
>
> Thank you for your comments. I leaved some replies and will update
> revision.
> Something about lacking tests.
>
> 1. We cannot check if expression import is correct until we implement
> FunctionDecl body import. I was going to upstream Decl-related parts later
> but maybe it is better to include this small case in the first patch. What
> do you think?
>

There is implementation of FunctionDecl import, it definitely can import
function body, tests ASTMerge/Inputs/{body1,body2} check this. In
http://reviews.llvm.org/D14224 function bodies are used to check that some
statement nodes are imported successfully. You may take necessary tests
from there.


> 2. What is the best way to test import of statements? Currently I have no
> idea how to do this (except of ast-dump). Any suggestions are welcome.
>
>
IMHO ast-dump is not the best way to check this. It does not check if
import was right. Many tests in ASTMerge just check that Importer handles
particular node, as a first step it looks sufficient. But you can go
further and define constexpr function in imported module, which uses the
node being tested. Then in the importing module you call this constexpr
function in static_assert. Not all nodes can be tested in this way, but for
those that can (for instance, ConditionalOperator) it would be a good test.


>
> 
> Comment at: lib/AST/ASTImporter.cpp:35
> @@ +34,3 @@
> +void ImportMultipleItems(IIter Ibegin, IIter Iend, OIter Obegin) {
> +  ASTImporter &_Importer = Importer;
> +  std::transform(Ibegin, Iend, Obegin,
> 
> sepavloff wrote:
> > A name started with underscore is a reserved identifier (see C++
> standard, [global.names]), so it is better to use something more neutral,
> like //TheImporter// or //Imp// or something else.
> Ouch. I was just trying to unify this with the code already existing in
> ASTImporter. I'll rename this.
> // TODO: refactor std::transform usage in ASTImporter.
>
> 
> Comment at: lib/AST/ASTImporter.cpp:48
> @@ +47,3 @@
> +template
> +bool checkPossibleNull(IIter Ibegin, IIter Iend, OIter Obegin) {
> +  for (; Ibegin != Iend; Ibegin++, Obegin++)
> 
> sepavloff wrote:
> > This function is used in one place only, maybe inline its body in that
> place?
> I'll use it in later patches so I'd prefer to keep it.
>
> 
> Comment at: lib/AST/ASTImporter.cpp:4655
> @@ +4654,3 @@
> +  for (unsigned i = 0, e = S->getNumClobbers(); i != e; i++) {
> +StringLiteral *Clobber = cast_or_null(
> +  Importer.Import(S->getClobberStringLiteral(i)));
> 
> sepavloff wrote:
> > Again, clobber cannot be null, maybe `cast` instead of `cast_or_null`?
> This guard is here because the return result of import may be null. This
> cast_or_null (and some others) handles such cases.
>
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D14286
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] r252452 - Make it possible to use libunwind without heap.

2015-11-08 Thread Peter Zotov via cfe-commits
Author: whitequark
Date: Mon Nov  9 00:57:29 2015
New Revision: 252452

URL: http://llvm.org/viewvc/llvm-project?rev=252452&view=rev
Log:
Make it possible to use libunwind without heap.

This patch allows to use libunwind on bare-metal systems that do not
include malloc/free by conditionally turning off nonessential
functionality that requires these functions.

The disabled functionality includes:

  * the .cfi_remember_state and .cfi_restore_state instructions;
  * the DWARF FDE cache.

The .cfi_{remember,restore}_state instructions don't seem to be used
by contemporary compilers. None of the LLVM backends emit it.

The DWARF FDE cache is bypassed if _LIBUNWIND_NO_HEAP is defined.
Specifically, entries are never added to it, so the search begins
and ends at the statically allocated, empty initial cache.

Such heap-less libunwind on a bare metal system is successfully used
in the ARTIQ project[1], and it is my hope that it will be useful
elsewhere.

[1]: http://m-labs.hk/artiq

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

Modified:
libunwind/trunk/src/DwarfParser.hpp
libunwind/trunk/src/UnwindCursor.hpp

Modified: libunwind/trunk/src/DwarfParser.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/DwarfParser.hpp?rev=252452&r1=252451&r2=252452&view=diff
==
--- libunwind/trunk/src/DwarfParser.hpp (original)
+++ libunwind/trunk/src/DwarfParser.hpp Mon Nov  9 00:57:29 2015
@@ -380,7 +380,9 @@ bool CFI_Parser::parseInstructions(A
 uint64_t length;
 uint8_t opcode = addressSpace.get8(p);
 uint8_t operand;
+#if !defined(_LIBUNWIND_NO_HEAP)
 PrologInfoStackEntry *entry;
+#endif
 ++p;
 switch (opcode) {
 case DW_CFA_nop:
@@ -492,6 +494,7 @@ bool CFI_Parser::parseInstructions(A
 fprintf(stderr, "DW_CFA_register(reg=%" PRIu64 ", reg2=%" PRIu64 ")\n",
 reg, reg2);
   break;
+#if !defined(_LIBUNWIND_NO_HEAP)
 case DW_CFA_remember_state:
   // avoid operator new, because that would be an upward dependency
   entry = (PrologInfoStackEntry *)malloc(sizeof(PrologInfoStackEntry));
@@ -517,6 +520,7 @@ bool CFI_Parser::parseInstructions(A
   if (logDwarf)
 fprintf(stderr, "DW_CFA_restore_state\n");
   break;
+#endif
 case DW_CFA_def_cfa:
   reg = addressSpace.getULEB128(p, instructionsEnd);
   offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd);

Modified: libunwind/trunk/src/UnwindCursor.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/UnwindCursor.hpp?rev=252452&r1=252451&r2=252452&view=diff
==
--- libunwind/trunk/src/UnwindCursor.hpp (original)
+++ libunwind/trunk/src/UnwindCursor.hpp Mon Nov  9 00:57:29 2015
@@ -114,6 +114,7 @@ typename A::pint_t DwarfFDECache::fin
 template 
 void DwarfFDECache::add(pint_t mh, pint_t ip_start, pint_t ip_end,
pint_t fde) {
+#if !defined(_LIBUNWIND_NO_HEAP)
   _LIBUNWIND_LOG_NON_ZERO(::pthread_rwlock_wrlock(&_lock));
   if (_bufferUsed >= _bufferEnd) {
 size_t oldSize = (size_t)(_bufferEnd - _buffer);
@@ -139,6 +140,7 @@ void DwarfFDECache::add(pint_t mh, pi
   }
 #endif
   _LIBUNWIND_LOG_NON_ZERO(::pthread_rwlock_unlock(&_lock));
+#endif
 }
 
 template 


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