[clang] [SCCP] [Transform] Adding ICMP folding for zext and sext in SCCPSolver (PR #67594)
https://github.com/mariannems edited https://github.com/llvm/llvm-project/pull/67594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SCCP] [Transform] Adding ICMP folding for zext and sext in SCCPSolver (PR #67594)
https://github.com/mariannems commented: Thanks for fixing that regression! https://github.com/llvm/llvm-project/pull/67594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SCCP] [Transform] Adding ICMP folding for zext and sext in SCCPSolver (PR #67594)
@@ -193,6 +193,60 @@ static bool replaceSignedInst(SCCPSolver &Solver, NewInst = BinaryOperator::Create(NewOpcode, Op0, Op1, "", &Inst); break; } + case Instruction::ICmp: { +ICmpInst &ICmp = cast(Inst); + +ZExtInst *Op0_zext = dyn_cast(ICmp.getOperand(0)); +SExtInst *Op0_sext = dyn_cast(ICmp.getOperand(0)); + +ZExtInst *Op1_zext = dyn_cast(ICmp.getOperand(1)); +SExtInst *Op1_sext = dyn_cast(ICmp.getOperand(1)); + +CastInst *Op0; +CastInst *Op1; + +if (Op0_zext) Op0 = Op0_zext; else Op0 = Op0_sext; +if (Op1_zext) Op1 = Op1_zext; else Op1 = Op1_sext; + +bool reversed = false; + +if (!Op0 || !Op1){ + // Op0 and Op1 must be defined + return false; +} + +if (Op1_zext && (! Op0_zext)){ + // We force Op0 to be a zext and reverse the arguments + // at the end if we swap + reversed = true; + + std::swap(Op0_zext, Op1_zext); + std::swap(Op0_sext, Op1_sext); + std::swap(Op0, Op1); +} + + +if(Op0->getType() != Op1->getType()){ mariannems wrote: Its is always better to exit early. This check should ideally be done before potential swapping. https://github.com/llvm/llvm-project/pull/67594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SCCP] [Transform] Adding ICMP folding for zext and sext in SCCPSolver (PR #67594)
@@ -193,6 +193,66 @@ static bool replaceSignedInst(SCCPSolver &Solver, NewInst = BinaryOperator::Create(NewOpcode, Op0, Op1, "", &Inst); break; } + case Instruction::ICmp: { +ICmpInst &ICmp = cast(Inst); + +ZExtInst *Op0_zext = dyn_cast(ICmp.getOperand(0)); +SExtInst *Op0_sext = dyn_cast(ICmp.getOperand(0)); + +ZExtInst *Op1_zext = dyn_cast(ICmp.getOperand(1)); +SExtInst *Op1_sext = dyn_cast(ICmp.getOperand(1)); + +CastInst *Op0; +CastInst *Op1; + +if (Op0_zext) + Op0 = Op0_zext; +else + Op0 = Op0_sext; +if (Op1_zext) + Op1 = Op1_zext; +else + Op1 = Op1_sext; + +bool reversed = false; + +if (!Op0 || !Op1) { + // Op0 and Op1 must be defined + return false; +} + +if (Op1_zext && (!Op0_zext)) { + // We force Op0 to be a zext and reverse the arguments + // at the end if we swap + reversed = true; mariannems wrote: IMHO the swapping makes it harder to read. Not swapping would force case to be checked in the if statement, but would make the code more readable. https://github.com/llvm/llvm-project/pull/67594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SCCP] [Transform] Adding ICMP folding for zext and sext in SCCPSolver (PR #67594)
@@ -0,0 +1,185 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --tool ./bin/opt --version 3 +; See PRXXX for more details mariannems wrote: `See PRXXX` Was that autogenerated ? Does it need to be updated ? https://github.com/llvm/llvm-project/pull/67594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D19827: Do not disable completely loop unroll according to optimization level.
mamai created this revision. mamai added a reviewer: chandlerc. mamai added a subscriber: cfe-commits. mamai set the repository for this revision to rL LLVM. By disabling completely the loop unroll at some optimization levels (e.g. /Os), the #pragma unroll have no effect at those optimization levels. This contradicts the paragraph in an llvm blog post about the loop pragmas (http://blog.llvm.org/2014/11/loop-vectorization-diagnostics-and.html) saying the following: > For example, when compiling for size (-Os) it's a good idea to vectorize the > hot loops of the application to improve performance. Vectorization, > interleaving, and unrolling can be explicitly specified using the #pragma > clang loop directive prior to any for, while, do-while, or c++11 range-based > for loop. Also, as explained in a previous commit, the loop unroll pass already have the logic to unroll loop are not according to optimization level (http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20130805/085399.html). Repository: rL LLVM http://reviews.llvm.org/D19827 Files: lib/Frontend/CompilerInvocation.cpp Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -511,9 +511,7 @@ Args.hasArg(OPT_ffreestanding)); if (Opts.SimplifyLibCalls) getAllNoBuiltinFuncValues(Args, Opts.NoBuiltinFuncs); - Opts.UnrollLoops = - Args.hasFlag(OPT_funroll_loops, OPT_fno_unroll_loops, - (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize)); + Opts.UnrollLoops = Args.hasFlag(OPT_funroll_loops, OPT_fno_unroll_loops); Opts.RerollLoops = Args.hasArg(OPT_freroll_loops); Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as); Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -511,9 +511,7 @@ Args.hasArg(OPT_ffreestanding)); if (Opts.SimplifyLibCalls) getAllNoBuiltinFuncValues(Args, Opts.NoBuiltinFuncs); - Opts.UnrollLoops = - Args.hasFlag(OPT_funroll_loops, OPT_fno_unroll_loops, - (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize)); + Opts.UnrollLoops = Args.hasFlag(OPT_funroll_loops, OPT_fno_unroll_loops); Opts.RerollLoops = Args.hasArg(OPT_freroll_loops); Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19827: Do not disable completely loop unroll according to optimization level.
mamai added a subscriber: tyler.nowicki. mamai added a comment. I think the blog comment is right. The pragma should make the loop unroll even in /Os. I think it is essential to allow the user to optimize some specific loops even if he generally wants to optimize for size the rest of the code. I will add tests that show the behavior of the loop unroll pass when optnone or optsize are specified. Repository: rL LLVM http://reviews.llvm.org/D19827 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19827: Do not disable completely loop unroll when optimizing for size.
mamai retitled this revision from "Do not disable completely loop unroll according to optimization level." to "Do not disable completely loop unroll when optimizing for size.". mamai updated the summary for this revision. mamai updated this revision to Diff 56133. mamai added a comment. Modified the patch not to affect /O1 optimization level. Repository: rL LLVM http://reviews.llvm.org/D19827 Files: lib/Frontend/CompilerInvocation.cpp Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -513,7 +513,7 @@ getAllNoBuiltinFuncValues(Args, Opts.NoBuiltinFuncs); Opts.UnrollLoops = Args.hasFlag(OPT_funroll_loops, OPT_fno_unroll_loops, - (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize)); + (Opts.OptimizationLevel > 1)); Opts.RerollLoops = Args.hasArg(OPT_freroll_loops); Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as); Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -513,7 +513,7 @@ getAllNoBuiltinFuncValues(Args, Opts.NoBuiltinFuncs); Opts.UnrollLoops = Args.hasFlag(OPT_funroll_loops, OPT_fno_unroll_loops, - (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize)); + (Opts.OptimizationLevel > 1)); Opts.RerollLoops = Args.hasArg(OPT_freroll_loops); Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r268509 - Do not disable completely loop unroll when optimizing for size.
Author: mamai Date: Wed May 4 10:26:28 2016 New Revision: 268509 URL: http://llvm.org/viewvc/llvm-project?rev=268509&view=rev Log: Do not disable completely loop unroll when optimizing for size. Let the loop unroll pass handle /Os. It already checks that option and adjust its thresholds accordingly. Also, will allow the #pragma unroll to have an effect in /Os. Differential Revision: http://reviews.llvm.org/D19827 Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=268509&r1=268508&r2=268509&view=diff == --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed May 4 10:26:28 2016 @@ -513,7 +513,7 @@ static bool ParseCodeGenArgs(CodeGenOpti getAllNoBuiltinFuncValues(Args, Opts.NoBuiltinFuncs); Opts.UnrollLoops = Args.hasFlag(OPT_funroll_loops, OPT_fno_unroll_loops, - (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize)); + (Opts.OptimizationLevel > 1)); Opts.RerollLoops = Args.hasArg(OPT_freroll_loops); Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19827: Do not disable completely loop unroll when optimizing for size.
This revision was automatically updated to reflect the committed changes. Closed by commit rL268509: Do not disable completely loop unroll when optimizing for size. (authored by mamai). Changed prior to commit: http://reviews.llvm.org/D19827?vs=56133&id=56158#toc Repository: rL LLVM http://reviews.llvm.org/D19827 Files: cfe/trunk/lib/Frontend/CompilerInvocation.cpp Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp === --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp @@ -513,7 +513,7 @@ getAllNoBuiltinFuncValues(Args, Opts.NoBuiltinFuncs); Opts.UnrollLoops = Args.hasFlag(OPT_funroll_loops, OPT_fno_unroll_loops, - (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize)); + (Opts.OptimizationLevel > 1)); Opts.RerollLoops = Args.hasArg(OPT_freroll_loops); Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as); Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp === --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp @@ -513,7 +513,7 @@ getAllNoBuiltinFuncValues(Args, Opts.NoBuiltinFuncs); Opts.UnrollLoops = Args.hasFlag(OPT_funroll_loops, OPT_fno_unroll_loops, - (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize)); + (Opts.OptimizationLevel > 1)); Opts.RerollLoops = Args.hasArg(OPT_freroll_loops); Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D19925: Fixed test not to depend on loop unrolling pass
mamai created this revision. mamai added a reviewer: compnerd. mamai added a subscriber: cfe-commits. mamai set the repository for this revision to rL LLVM. This test have been broken by http://reviews.llvm.org/D19827, which re-enables loop unrolling at /Os. Since the goal of this test does not seem related unrolling, just disabled loop unroll pass when compiling this test. Repository: rL LLVM http://reviews.llvm.org/D19925 Files: test/CodeGenObjCXX/arc-cxx11-init-list.mm Index: test/CodeGenObjCXX/arc-cxx11-init-list.mm === --- test/CodeGenObjCXX/arc-cxx11-init-list.mm +++ test/CodeGenObjCXX/arc-cxx11-init-list.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple armv7-ios5.0 -std=c++11 -fobjc-arc -Os -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple armv7-ios5.0 -std=c++11 -fobjc-arc -Os -fno-unroll-loops -emit-llvm -o - %s | FileCheck %s typedef __SIZE_TYPE__ size_t; Index: test/CodeGenObjCXX/arc-cxx11-init-list.mm === --- test/CodeGenObjCXX/arc-cxx11-init-list.mm +++ test/CodeGenObjCXX/arc-cxx11-init-list.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple armv7-ios5.0 -std=c++11 -fobjc-arc -Os -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple armv7-ios5.0 -std=c++11 -fobjc-arc -Os -fno-unroll-loops -emit-llvm -o - %s | FileCheck %s typedef __SIZE_TYPE__ size_t; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19925: Fixed test not to depend on loop unrolling pass
mamai abandoned this revision. mamai added a comment. The test have been fixed otherwise in rev 268523. Repository: rL LLVM http://reviews.llvm.org/D19925 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r266320 - clang-format: Implemented tab usage for continuation and indentation
Author: mamai Date: Thu Apr 14 09:52:26 2016 New Revision: 266320 URL: http://llvm.org/viewvc/llvm-project?rev=266320&view=rev Log: clang-format: Implemented tab usage for continuation and indentation Use tabs to fill whitespace at the start of a line. Patch by Maxime Beaulieu Differential Revision: http://reviews.llvm.org/D19028 Modified: cfe/trunk/include/clang/Format/Format.h cfe/trunk/lib/Format/Format.cpp cfe/trunk/lib/Format/WhitespaceManager.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/include/clang/Format/Format.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=266320&r1=266319&r2=266320&view=diff == --- cfe/trunk/include/clang/Format/Format.h (original) +++ cfe/trunk/include/clang/Format/Format.h Thu Apr 14 09:52:26 2016 @@ -603,6 +603,8 @@ struct FormatStyle { UT_Never, /// Use tabs only for indentation. UT_ForIndentation, +/// Use tabs only for line continuation and indentation. +UT_ForContinuationAndIndentation, /// Use tabs whenever we need to fill whitespace that spans at least from /// one tab stop to the next one. UT_Always Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=266320&r1=266319&r2=266320&view=diff == --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Thu Apr 14 09:52:26 2016 @@ -69,6 +69,8 @@ template <> struct ScalarEnumerationTrai IO.enumCase(Value, "Always", FormatStyle::UT_Always); IO.enumCase(Value, "true", FormatStyle::UT_Always); IO.enumCase(Value, "ForIndentation", FormatStyle::UT_ForIndentation); +IO.enumCase(Value, "ForContinuationAndIndentation", +FormatStyle::UT_ForContinuationAndIndentation); } }; Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=266320&r1=266319&r2=266320&view=diff == --- cfe/trunk/lib/Format/WhitespaceManager.cpp (original) +++ cfe/trunk/lib/Format/WhitespaceManager.cpp Thu Apr 14 09:52:26 2016 @@ -558,6 +558,14 @@ void WhitespaceManager::appendIndentText } Text.append(Spaces, ' '); break; + case FormatStyle::UT_ForContinuationAndIndentation: +if (WhitespaceStartColumn == 0) { + unsigned Tabs = Spaces / Style.TabWidth; + Text.append(Tabs, '\t'); + Spaces -= Tabs * Style.TabWidth; +} +Text.append(Spaces, ' '); +break; } } Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=266320&r1=266319&r2=266320&view=diff == --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Apr 14 09:52:26 2016 @@ -8572,6 +8572,230 @@ TEST_F(FormatTest, ConfigurableUseOfTab) "\t */\n" "\t int i;\n" "}")); + + Tab.UseTab = FormatStyle::UT_ForContinuationAndIndentation; + Tab.TabWidth = 8; + Tab.IndentWidth = 8; + EXPECT_EQ("if ( && // q\n" +"bb) // w\n" +"\t;", +format("if ( &&// q\n" + "bb)// w\n" + ";", + Tab)); + EXPECT_EQ("if (aaa && bbb) // w\n" +"\t;", +format("if(aaa&&bbb)// w\n" + ";", + Tab)); + verifyFormat("class X {\n" + "\tvoid f() {\n" + "\t\tsomeFunction(parameter1,\n" + "\t\t\t parameter2);\n" + "\t}\n" + "};", + Tab); + verifyFormat("#define A\\\n" + "\tvoid f() { \\\n" + "\t\tsomeFunction(\\\n" + "\t\tparameter1, \\\n" + "\t\tparameter2); \\\n" + "\t}", + Tab); + Tab.TabWidth = 4; + Tab.IndentWidth = 8; + verifyFormat("class TabWidth4Indent8 {\n" + "\t\tvoid f() {\n" + "\t\t\t\tsomeFunction(parameter1,\n" + "\t\t\t\t\t\t\t parameter2);\n" + "\t\t}\n" + "};", + Tab); + Tab.TabWidth = 4; + Tab.IndentWidth = 4; + verifyFormat("class TabWidth4Indent4 {\n" + "\tvoid f() {\n" + "\t\tsomeFunction(parameter1,\n" + "\t\t\t\t\t parameter2);\n" + "\t}\n" + "};", + Tab); + Tab.TabWidth = 8; + Tab.IndentWidth = 4; + verifyFormat("class TabWidth8Indent4 {\n" + "void f() {\n" +
r266319 - clang-format: Allow include of clangFormat.h in managed context
Author: mamai Date: Thu Apr 14 09:47:37 2016 New Revision: 266319 URL: http://llvm.org/viewvc/llvm-project?rev=266319&view=rev Log: clang-format: Allow include of clangFormat.h in managed context Including VirtualFileSystem.h in the clangFormat.h indirectly includes . This header is blocked when compiling with /clr. Patch by Maxime Beaulieu Differential Revision: http://reviews.llvm.org/D19064 Modified: cfe/trunk/include/clang/Format/Format.h cfe/trunk/lib/Format/Format.cpp Modified: cfe/trunk/include/clang/Format/Format.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=266319&r1=266318&r2=266319&view=diff == --- cfe/trunk/include/clang/Format/Format.h (original) +++ cfe/trunk/include/clang/Format/Format.h Thu Apr 14 09:47:37 2016 @@ -16,7 +16,6 @@ #define LLVM_CLANG_FORMAT_FORMAT_H #include "clang/Basic/LangOptions.h" -#include "clang/Basic/VirtualFileSystem.h" #include "clang/Tooling/Core/Replacement.h" #include "llvm/ADT/ArrayRef.h" #include @@ -27,6 +26,10 @@ class Lexer; class SourceManager; class DiagnosticConsumer; +namespace vfs { +class FileSystem; +} + namespace format { enum class ParseError { Success = 0, Error, Unsuitable }; Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=266319&r1=266318&r2=266319&view=diff == --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Thu Apr 14 09:47:37 2016 @@ -22,6 +22,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/SourceManager.h" +#include "clang/Basic/VirtualFileSystem.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Allocator.h" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19064: clang-format: Allow include of clangFormat.h in managed context
This revision was automatically updated to reflect the committed changes. Closed by commit rL266319: clang-format: Allow include of clangFormat.h in managed context (authored by mamai). Changed prior to commit: http://reviews.llvm.org/D19064?vs=53608&id=53717#toc Repository: rL LLVM http://reviews.llvm.org/D19064 Files: cfe/trunk/include/clang/Format/Format.h cfe/trunk/lib/Format/Format.cpp Index: cfe/trunk/include/clang/Format/Format.h === --- cfe/trunk/include/clang/Format/Format.h +++ cfe/trunk/include/clang/Format/Format.h @@ -16,7 +16,6 @@ #define LLVM_CLANG_FORMAT_FORMAT_H #include "clang/Basic/LangOptions.h" -#include "clang/Basic/VirtualFileSystem.h" #include "clang/Tooling/Core/Replacement.h" #include "llvm/ADT/ArrayRef.h" #include @@ -27,6 +26,10 @@ class SourceManager; class DiagnosticConsumer; +namespace vfs { +class FileSystem; +} + namespace format { enum class ParseError { Success = 0, Error, Unsuitable }; Index: cfe/trunk/lib/Format/Format.cpp === --- cfe/trunk/lib/Format/Format.cpp +++ cfe/trunk/lib/Format/Format.cpp @@ -22,6 +22,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/SourceManager.h" +#include "clang/Basic/VirtualFileSystem.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Allocator.h" Index: cfe/trunk/include/clang/Format/Format.h === --- cfe/trunk/include/clang/Format/Format.h +++ cfe/trunk/include/clang/Format/Format.h @@ -16,7 +16,6 @@ #define LLVM_CLANG_FORMAT_FORMAT_H #include "clang/Basic/LangOptions.h" -#include "clang/Basic/VirtualFileSystem.h" #include "clang/Tooling/Core/Replacement.h" #include "llvm/ADT/ArrayRef.h" #include @@ -27,6 +26,10 @@ class SourceManager; class DiagnosticConsumer; +namespace vfs { +class FileSystem; +} + namespace format { enum class ParseError { Success = 0, Error, Unsuitable }; Index: cfe/trunk/lib/Format/Format.cpp === --- cfe/trunk/lib/Format/Format.cpp +++ cfe/trunk/lib/Format/Format.cpp @@ -22,6 +22,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/SourceManager.h" +#include "clang/Basic/VirtualFileSystem.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Allocator.h" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19065: clang-format: Last line in incomplete block is indented incorrectly
This revision was automatically updated to reflect the committed changes. Closed by commit rL266321: clang-format: Last line in incomplete block is indented incorrectly (authored by mamai). Changed prior to commit: http://reviews.llvm.org/D19065?vs=53582&id=53723#toc Repository: rL LLVM http://reviews.llvm.org/D19065 Files: cfe/trunk/lib/Format/UnwrappedLineParser.cpp cfe/trunk/unittests/Format/FormatTest.cpp Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp === --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp @@ -430,6 +430,9 @@ ++Line->Level; parseLevel(/*HasOpeningBrace=*/true); + if (eof()) +return; + if (MacroBlock ? !FormatTok->is(TT_MacroBlockEnd) : !FormatTok->is(tok::r_brace)) { Line->Level = InitialLevel; Index: cfe/trunk/unittests/Format/FormatTest.cpp === --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -7110,10 +7110,9 @@ } TEST_F(FormatTest, IndentLineCommentsInStartOfBlockAtEndOfFile) { - // FIXME: This is not what we want... verifyFormat("{\n" - "// a" - "// b"); + " // a\n" + " // b"); } TEST_F(FormatTest, FormatStarDependingOnContext) { Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp === --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp @@ -430,6 +430,9 @@ ++Line->Level; parseLevel(/*HasOpeningBrace=*/true); + if (eof()) +return; + if (MacroBlock ? !FormatTok->is(TT_MacroBlockEnd) : !FormatTok->is(tok::r_brace)) { Line->Level = InitialLevel; Index: cfe/trunk/unittests/Format/FormatTest.cpp === --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -7110,10 +7110,9 @@ } TEST_F(FormatTest, IndentLineCommentsInStartOfBlockAtEndOfFile) { - // FIXME: This is not what we want... verifyFormat("{\n" - "// a" - "// b"); + " // a\n" + " // b"); } TEST_F(FormatTest, FormatStarDependingOnContext) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r266321 - clang-format: Last line in incomplete block is indented incorrectly
Author: mamai Date: Thu Apr 14 09:56:49 2016 New Revision: 266321 URL: http://llvm.org/viewvc/llvm-project?rev=266321&view=rev Log: clang-format: Last line in incomplete block is indented incorrectly Indentation of the last line was reset to the initial indentation of the block when reaching EOF. Patch by Maxime Beaulieu Differential Revision: http://reviews.llvm.org/D19065 Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=266321&r1=266320&r2=266321&view=diff == --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original) +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Thu Apr 14 09:56:49 2016 @@ -430,6 +430,9 @@ void UnwrappedLineParser::parseBlock(boo ++Line->Level; parseLevel(/*HasOpeningBrace=*/true); + if (eof()) +return; + if (MacroBlock ? !FormatTok->is(TT_MacroBlockEnd) : !FormatTok->is(tok::r_brace)) { Line->Level = InitialLevel; Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=266321&r1=266320&r2=266321&view=diff == --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Apr 14 09:56:49 2016 @@ -7110,10 +7110,9 @@ TEST_F(FormatTest, BlockCommentsAtEndOfL } TEST_F(FormatTest, IndentLineCommentsInStartOfBlockAtEndOfFile) { - // FIXME: This is not what we want... verifyFormat("{\n" - "// a" - "// b"); + " // a\n" + " // b"); } TEST_F(FormatTest, FormatStarDependingOnContext) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19028: clang-format: Implemented tab usage for continuation and indentation
This revision was automatically updated to reflect the committed changes. Closed by commit rL266320: clang-format: Implemented tab usage for continuation and indentation (authored by mamai). Changed prior to commit: http://reviews.llvm.org/D19028?vs=53444&id=53721#toc Repository: rL LLVM http://reviews.llvm.org/D19028 Files: cfe/trunk/include/clang/Format/Format.h cfe/trunk/lib/Format/Format.cpp cfe/trunk/lib/Format/WhitespaceManager.cpp cfe/trunk/unittests/Format/FormatTest.cpp Index: cfe/trunk/include/clang/Format/Format.h === --- cfe/trunk/include/clang/Format/Format.h +++ cfe/trunk/include/clang/Format/Format.h @@ -603,6 +603,8 @@ UT_Never, /// Use tabs only for indentation. UT_ForIndentation, +/// Use tabs only for line continuation and indentation. +UT_ForContinuationAndIndentation, /// Use tabs whenever we need to fill whitespace that spans at least from /// one tab stop to the next one. UT_Always Index: cfe/trunk/lib/Format/Format.cpp === --- cfe/trunk/lib/Format/Format.cpp +++ cfe/trunk/lib/Format/Format.cpp @@ -69,6 +69,8 @@ IO.enumCase(Value, "Always", FormatStyle::UT_Always); IO.enumCase(Value, "true", FormatStyle::UT_Always); IO.enumCase(Value, "ForIndentation", FormatStyle::UT_ForIndentation); +IO.enumCase(Value, "ForContinuationAndIndentation", +FormatStyle::UT_ForContinuationAndIndentation); } }; Index: cfe/trunk/lib/Format/WhitespaceManager.cpp === --- cfe/trunk/lib/Format/WhitespaceManager.cpp +++ cfe/trunk/lib/Format/WhitespaceManager.cpp @@ -558,6 +558,14 @@ } Text.append(Spaces, ' '); break; + case FormatStyle::UT_ForContinuationAndIndentation: +if (WhitespaceStartColumn == 0) { + unsigned Tabs = Spaces / Style.TabWidth; + Text.append(Tabs, '\t'); + Spaces -= Tabs * Style.TabWidth; +} +Text.append(Spaces, ' '); +break; } } Index: cfe/trunk/unittests/Format/FormatTest.cpp === --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -8572,6 +8572,230 @@ "\t */\n" "\t int i;\n" "}")); + + Tab.UseTab = FormatStyle::UT_ForContinuationAndIndentation; + Tab.TabWidth = 8; + Tab.IndentWidth = 8; + EXPECT_EQ("if ( && // q\n" +"bb) // w\n" +"\t;", +format("if ( &&// q\n" + "bb)// w\n" + ";", + Tab)); + EXPECT_EQ("if (aaa && bbb) // w\n" +"\t;", +format("if(aaa&&bbb)// w\n" + ";", + Tab)); + verifyFormat("class X {\n" + "\tvoid f() {\n" + "\t\tsomeFunction(parameter1,\n" + "\t\t\t parameter2);\n" + "\t}\n" + "};", + Tab); + verifyFormat("#define A\\\n" + "\tvoid f() { \\\n" + "\t\tsomeFunction(\\\n" + "\t\tparameter1, \\\n" + "\t\tparameter2); \\\n" + "\t}", + Tab); + Tab.TabWidth = 4; + Tab.IndentWidth = 8; + verifyFormat("class TabWidth4Indent8 {\n" + "\t\tvoid f() {\n" + "\t\t\t\tsomeFunction(parameter1,\n" + "\t\t\t\t\t\t\t parameter2);\n" + "\t\t}\n" + "};", + Tab); + Tab.TabWidth = 4; + Tab.IndentWidth = 4; + verifyFormat("class TabWidth4Indent4 {\n" + "\tvoid f() {\n" + "\t\tsomeFunction(parameter1,\n" + "\t\t\t\t\t parameter2);\n" + "\t}\n" + "};", + Tab); + Tab.TabWidth = 8; + Tab.IndentWidth = 4; + verifyFormat("class TabWidth8Indent4 {\n" + "void f() {\n" + "\tsomeFunction(parameter1,\n" + "\t\t parameter2);\n" + "}\n" + "};", + Tab); + Tab.TabWidth = 8; + Tab.IndentWidth = 8; + EXPECT_EQ("/*\n" +"\t a\t\tcomment\n" +"\t in multiple lines\n" +" */", +format(" /*\t \t \n" + " \t \t a\t\tcomment\t \t\n" + " \t \t in multiple lines\t\n" + " \t */", + Tab)); + verifyFormat("{\n" + "\t();\n" + "\t();\n" + "\t();\n" + "\t();\n" + "\t();\n" + "\taa
Re: [PATCH] D18412: [clang-tidy] Add support for different char-types for the readability-redundant-string-cstr checker.
mamai added a subscriber: mamai. mamai added a comment. nit: in summary, consiring -> considering ? Comment at: test/clang-tidy/readability-redundant-string-cstr.cpp:54 @@ +53,3 @@ + // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to `c_str()` [readability-redundant-string-cstr] + // CHECK-FIXES: {{^ }}f1(s);{{$}} +} Isn't this a copy-paste error to reference f1 ? Same question for line 62 and 70... http://reviews.llvm.org/D18412 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits