Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Fix for stringized function-macro args continued across lines
Browse files Browse the repository at this point in the history
In case of certain #define'd macros, there's a space just before line continuation
that the minimized-source lexer was missing to include, resulting in invalid stringize.

Patch by: kousikk (Kousik Kumar)

Differential Revision: https://reviews.llvm.org/D67635

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372360 91177308-0d34-0410-b5e6-96231b3b80d8
(cherry picked from commit 6fc00ec)
  • Loading branch information
hyp committed Sep 19, 2019
1 parent 6a40532 commit ec36602
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
7 changes: 5 additions & 2 deletions lib/Lex/DependencyDirectivesSourceMinimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,12 @@ static void skipToNewlineRaw(const char *&First, const char *const End) {

static const char *reverseOverSpaces(const char *First, const char *Last) {
assert(First <= Last);
while (First != Last && isHorizontalWhitespace(Last[-1]))
const char *PrevLast = Last;
while (First != Last && isHorizontalWhitespace(Last[-1])) {
PrevLast = Last;
--Last;
return Last;
}
return PrevLast;
}

static void skipLineComment(const char *&First, const char *const End) {
Expand Down
26 changes: 18 additions & 8 deletions unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,19 @@ TEST(MinimizeSourceToDependencyDirectivesTest, DefineHorizontalWhitespace) {

ASSERT_FALSE(minimizeSourceToDependencyDirectives(
"#define MACRO(\t)\tcon \t tent\t", Out));
EXPECT_STREQ("#define MACRO() con \t tent\n", Out.data());
EXPECT_STREQ("#define MACRO() con \t tent\t\n", Out.data());

ASSERT_FALSE(minimizeSourceToDependencyDirectives(
"#define MACRO(\f)\fcon \f tent\f", Out));
EXPECT_STREQ("#define MACRO() con \f tent\n", Out.data());
EXPECT_STREQ("#define MACRO() con \f tent\f\n", Out.data());

ASSERT_FALSE(minimizeSourceToDependencyDirectives(
"#define MACRO(\v)\vcon \v tent\v", Out));
EXPECT_STREQ("#define MACRO() con \v tent\n", Out.data());
EXPECT_STREQ("#define MACRO() con \v tent\v\n", Out.data());

ASSERT_FALSE(minimizeSourceToDependencyDirectives(
"#define MACRO \t\v\f\v\t con\f\t\vtent\v\f \v", Out));
EXPECT_STREQ("#define MACRO con\f\t\vtent\n", Out.data());
EXPECT_STREQ("#define MACRO con\f\t\vtent\v\n", Out.data());
}

TEST(MinimizeSourceToDependencyDirectivesTest, DefineMultilineArgs) {
Expand All @@ -187,7 +187,7 @@ TEST(MinimizeSourceToDependencyDirectivesTest, DefineMultilineArgs) {
" call((a), \\\n"
" (b))",
Out));
EXPECT_STREQ("#define MACRO(a,b) call((a),(b))\n", Out.data());
EXPECT_STREQ("#define MACRO(a,b) call((a), (b))\n", Out.data());
}

TEST(MinimizeSourceToDependencyDirectivesTest,
Expand All @@ -200,7 +200,17 @@ TEST(MinimizeSourceToDependencyDirectivesTest,
" call((a), \\\r"
" (b))",
Out));
EXPECT_STREQ("#define MACRO(a,b) call((a),(b))\n", Out.data());
EXPECT_STREQ("#define MACRO(a,b) call((a), (b))\n", Out.data());
}

TEST(MinimizeSourceToDependencyDirectivesTest, DefineMultilineArgsStringize) {
SmallVector<char, 128> Out;

ASSERT_FALSE(minimizeSourceToDependencyDirectives("#define MACRO(a,b) \\\n"
" #a \\\n"
" #b",
Out));
EXPECT_STREQ("#define MACRO(a,b) #a #b\n", Out.data());
}

TEST(MinimizeSourceToDependencyDirectivesTest,
Expand All @@ -213,7 +223,7 @@ TEST(MinimizeSourceToDependencyDirectivesTest,
" call((a), \\\r\n"
" (b))",
Out));
EXPECT_STREQ("#define MACRO(a,b) call((a),(b))\n", Out.data());
EXPECT_STREQ("#define MACRO(a,b) call((a), (b))\n", Out.data());
}

TEST(MinimizeSourceToDependencyDirectivesTest,
Expand All @@ -226,7 +236,7 @@ TEST(MinimizeSourceToDependencyDirectivesTest,
" call((a), \\\n\r"
" (b))",
Out));
EXPECT_STREQ("#define MACRO(a,b) call((a),(b))\n", Out.data());
EXPECT_STREQ("#define MACRO(a,b) call((a), (b))\n", Out.data());
}

TEST(MinimizeSourceToDependencyDirectivesTest, DefineNumber) {
Expand Down

0 comments on commit ec36602

Please sign in to comment.