r200381 - Fix crash on unmatched #endif's.

David Blaikie dblaikie at gmail.com
Wed Jan 29 08:47:37 PST 2014


On Wed, Jan 29, 2014 at 12:49 AM, Manuel Klimek <klimek at google.com> wrote:

> Author: klimek
> Date: Wed Jan 29 02:49:02 2014
> New Revision: 200381
>
> URL: http://llvm.org/viewvc/llvm-project?rev=200381&view=rev
> Log:
> Fix crash on unmatched #endif's.
>
> The following snippet would crash:
>   #endif
>   #if A
>

Any reason this wasn't contributed as a test case?


>
> 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=200381&r1=200380&r2=200381&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
> +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Jan 29 02:49:02 2014
> @@ -509,7 +509,9 @@ void UnwrappedLineParser::parsePPEndIf()
>        PPLevelBranchCount[PPBranchLevel] = PPChainBranchIndex.top() + 1;
>      }
>    }
> -  --PPBranchLevel;
> +  // Guard against #endif's without #if.
> +  if (PPBranchLevel > 0)
> +    --PPBranchLevel;
>    if (!PPChainBranchIndex.empty())
>      PPChainBranchIndex.pop();
>    if (!PPStack.empty())
>
> Modified: cfe/trunk/unittests/Format/FormatTest.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=200381&r1=200380&r2=200381&view=diff
>
> ==============================================================================
> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
> +++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan 29 02:49:02 2014
> @@ -2427,6 +2427,11 @@ TEST_F(FormatTest, LayoutStatementsAroun
>                 "#endif");
>  }
>
> +TEST_F(FormatTest, GraciouslyHandleIncorrectPreprocessorConditions) {
> +  verifyFormat("#endif\n"
> +               "#if B");
> +}
> +
>  TEST_F(FormatTest, FormatsJoinedLinesOnSubsequentRuns) {
>    FormatStyle SingleLine = getLLVMStyle();
>    SingleLine.AllowShortIfStatementsOnASingleLine = true;
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140129/fd5954fa/attachment.html>


More information about the cfe-commits mailing list