Skip to content

Commit 65795cf

Browse files
authored
add test to handle preprocessing an already preprocessed file. (microsoft#4898)
* add test to not blow up if an already preprocessed file is part of the source, remove assert
1 parent 5decc4a commit 65795cf

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

tools/clang/lib/Frontend/PrintPreprocessedOutput.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
280280
}
281281
if (PP.getLangOpts().HLSL) {
282282
if (0 == strcmp(UserLoc.getFilename(), "<built-in>")) {
283-
assert(NewLine == 1 && "else built-in is generating preprocessor output");
284283
return;
285284
}
286285
}

tools/clang/unittests/HLSL/CompilerTest.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ class CompilerTest : public ::testing::Test {
238238
TEST_METHOD(LibGVStore)
239239
TEST_METHOD(PreprocessWhenExpandTokenPastingOperandThenAccept)
240240
TEST_METHOD(PreprocessWithDebugOptsThenOk)
241+
TEST_METHOD(PreprocessCheckBuiltinIsOk)
241242
TEST_METHOD(WhenSigMismatchPCFunctionThenFail)
242243
TEST_METHOD(CompileOtherModesWithDebugOptsThenOk)
243244

@@ -3967,6 +3968,30 @@ TEST_F(CompilerTest, PreprocessWithDebugOptsThenOk) {
39673968
"int BAR;\n", text.c_str());
39683969
}
39693970

3971+
// Make sure that '#line 1 "<built-in>"' won't blow up when preprocessing.
3972+
TEST_F(CompilerTest, PreprocessCheckBuiltinIsOk) {
3973+
CComPtr<IDxcCompiler> pCompiler;
3974+
CComPtr<IDxcOperationResult> pResult;
3975+
CComPtr<IDxcBlobEncoding> pSource;
3976+
3977+
VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
3978+
CreateBlobFromText(
3979+
"#line 1 \"<built-in>\"\r\n"
3980+
"int x;", &pSource);
3981+
VERIFY_SUCCEEDED(pCompiler->Preprocess(pSource, L"file.hlsl", nullptr, 0,
3982+
nullptr, 0, nullptr,
3983+
&pResult));
3984+
HRESULT hrOp;
3985+
VERIFY_SUCCEEDED(pResult->GetStatus(&hrOp));
3986+
VERIFY_SUCCEEDED(hrOp);
3987+
3988+
CComPtr<IDxcBlob> pOutText;
3989+
VERIFY_SUCCEEDED(pResult->GetResult(&pOutText));
3990+
std::string text(BlobToUtf8(pOutText));
3991+
VERIFY_ARE_EQUAL_STR(
3992+
"#line 1 \"file.hlsl\"\n\n", text.c_str());
3993+
}
3994+
39703995
TEST_F(CompilerTest, CompileOtherModesWithDebugOptsThenOk) {
39713996
// Make sure debug options, such as -Zi and -Fd,
39723997
// are simply ignored when compiling in modes:

0 commit comments

Comments
 (0)