[PATCH] D104459: [clang][lex] Ensure minimizer output is never larger than input

Duncan P. N. Exon Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 17 11:18:21 PDT 2021


dexonsmith added a comment.

> This patch ensures the output of source minimizer is never larger than the input. This property will be handy in a follow up patch that makes it possible to pad the minimized output to the size of the original input.

I suppose when I wrote first wrote this I was thinking of a secondary purpose of canonicalizing the sources; in which case, adding a trailing newline (for example) seems like feature rather than a bug. I'm not too attached to that, but I am curious for more context about why it's important to be able to pad the file to the same size, and whether that indicates a bug that should be fixed somewhere else instead. (I'll read the follow-up patches in the stack...)



================
Comment at: clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp:149
   ASSERT_FALSE(minimizeSourceToDependencyDirectives("#define MACRO((a))", Out));
-  EXPECT_STREQ("#define MACRO(/* invalid */\n", Out.data());
+  EXPECT_STREQ("#define MACRO\n", Out.data());
 
----------------
I'm not comfortable with this change... the idea of the `(/*invalid*/` was to guarantee that an invalid macro argument list didn't get minimized to something valid.

Perhaps the result could be `"#define MACRO(\n"`, and just strip the comment?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104459/new/

https://reviews.llvm.org/D104459



More information about the cfe-commits mailing list