Browse Source

add test to handle preprocessing an already preprocessed file. (#4898)

* add test to not blow up if an already preprocessed file is part of the source, remove assert
Joshua Batista 2 years ago
parent
commit
65795cfd21

+ 0 - 1
tools/clang/lib/Frontend/PrintPreprocessedOutput.cpp

@@ -280,7 +280,6 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
   }
   }
   if (PP.getLangOpts().HLSL) {
   if (PP.getLangOpts().HLSL) {
     if (0 == strcmp(UserLoc.getFilename(), "<built-in>")) {
     if (0 == strcmp(UserLoc.getFilename(), "<built-in>")) {
-      assert(NewLine == 1 && "else built-in is generating preprocessor output");
       return;
       return;
     }
     }
   }
   }

+ 25 - 0
tools/clang/unittests/HLSL/CompilerTest.cpp

@@ -238,6 +238,7 @@ public:
   TEST_METHOD(LibGVStore)
   TEST_METHOD(LibGVStore)
   TEST_METHOD(PreprocessWhenExpandTokenPastingOperandThenAccept)
   TEST_METHOD(PreprocessWhenExpandTokenPastingOperandThenAccept)
   TEST_METHOD(PreprocessWithDebugOptsThenOk)
   TEST_METHOD(PreprocessWithDebugOptsThenOk)
+  TEST_METHOD(PreprocessCheckBuiltinIsOk)
   TEST_METHOD(WhenSigMismatchPCFunctionThenFail)
   TEST_METHOD(WhenSigMismatchPCFunctionThenFail)
   TEST_METHOD(CompileOtherModesWithDebugOptsThenOk)
   TEST_METHOD(CompileOtherModesWithDebugOptsThenOk)
 
 
@@ -3967,6 +3968,30 @@ TEST_F(CompilerTest, PreprocessWithDebugOptsThenOk) {
     "int BAR;\n", text.c_str());
     "int BAR;\n", text.c_str());
 }
 }
 
 
+// Make sure that '#line 1 "<built-in>"' won't blow up when preprocessing.
+TEST_F(CompilerTest, PreprocessCheckBuiltinIsOk) {
+  CComPtr<IDxcCompiler> pCompiler;
+  CComPtr<IDxcOperationResult> pResult;
+  CComPtr<IDxcBlobEncoding> pSource;
+  
+  VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
+  CreateBlobFromText(
+    "#line 1 \"<built-in>\"\r\n"
+    "int x;", &pSource);
+  VERIFY_SUCCEEDED(pCompiler->Preprocess(pSource, L"file.hlsl", nullptr, 0,
+                                         nullptr, 0, nullptr,
+                                         &pResult));
+  HRESULT hrOp;
+  VERIFY_SUCCEEDED(pResult->GetStatus(&hrOp));
+  VERIFY_SUCCEEDED(hrOp);
+
+  CComPtr<IDxcBlob> pOutText;
+  VERIFY_SUCCEEDED(pResult->GetResult(&pOutText));
+  std::string text(BlobToUtf8(pOutText));
+  VERIFY_ARE_EQUAL_STR(
+    "#line 1 \"file.hlsl\"\n\n", text.c_str());
+}
+
 TEST_F(CompilerTest, CompileOtherModesWithDebugOptsThenOk) {
 TEST_F(CompilerTest, CompileOtherModesWithDebugOptsThenOk) {
   // Make sure debug options, such as -Zi and -Fd,
   // Make sure debug options, such as -Zi and -Fd,
   // are simply ignored when compiling in modes:
   // are simply ignored when compiling in modes: