[clang] test (PR #101992)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 5 07:39:29 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-format

Author: Damien (Damien-Chen)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/101992.diff


2 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+3-4) 
- (modified) clang/unittests/Format/FormatTest.cpp (+16) 


``````````diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 4ed3e9d0e8e85..7d6dd3acc03a0 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3532,10 +3532,9 @@ void TokenAnnotator::setCommentLineLevels(
       // Align comments for preprocessor lines with the # in column 0 if
       // preprocessor lines are not indented. Otherwise, align with the next
       // line.
-      Line->Level = Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash &&
-                            PPDirectiveOrImportStmt
-                        ? 0
-                        : NextNonCommentLine->Level;
+      Line->Level = (PPDirectiveOrImportStmt && Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash)
+                              ? NextNonCommentLine->Level
+                              : 0;
     } else {
       NextNonCommentLine = Line->First->isNot(tok::r_brace) ? Line : nullptr;
     }
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 2a754a29e81e7..e3556ca573202 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5436,6 +5436,22 @@ TEST_F(FormatTest, IndentsPPDirectiveWithPPIndentWidth) {
                "  int y = 0;\n"
                "}",
                style);
+  verifyFormat("#ifndef PREDICTORS_HPP_\n"
+               "#define PREDICTORS_HPP_\n"
+               "int compute_prior(int column) {\n"
+               "#if defined(SPECIAL_PATH)\n"
+               "  return top[column];\n"
+               "#else\n"
+               "  // division-by-multiplication\n"
+               "  #ifdef PEDANTIC\n"
+               "  return prior(top[column]);\n",
+               "  #else\n"
+               "  return fast_prior(top[column]);\n"
+               "  #endif\n"
+               "#endif\n"
+               "}\n"
+               "#endif // PREDICTORS_HPP_"
+               style);
 
   style.IndentPPDirectives = FormatStyle::PPDIS_None;
   verifyFormat("#ifdef foo\n"

``````````

</details>


https://github.com/llvm/llvm-project/pull/101992


More information about the cfe-commits mailing list