@@ -236,6 +236,8 @@ static bool proceedCommand(std::vector<std::string> command, llvm::StringRef Dir
236
236
// This code change all the paths to be absolute paths
237
237
// FIXME: it is a bit fragile.
238
238
bool previousIsDashI = false ;
239
+ bool previousNeedsMacro = false ;
240
+ bool hasNoStdInc = false ;
239
241
for (std::string &A : command) {
240
242
if (previousIsDashI && !A.empty () && A[0 ] != ' /' ) {
241
243
A = Directory % " /" % A;
@@ -244,6 +246,16 @@ static bool proceedCommand(std::vector<std::string> command, llvm::StringRef Dir
244
246
} else if (A == " -I" ) {
245
247
previousIsDashI = true ;
246
248
continue ;
249
+ } else if (A == " -nostdinc" ) {
250
+ hasNoStdInc = true ;
251
+ continue ;
252
+ } else if (A == " -U" || A == " -D" ) {
253
+ previousNeedsMacro = true ;
254
+ continue ;
255
+ }
256
+ if (previousNeedsMacro) {
257
+ previousNeedsMacro = false ;
258
+ continue ;
247
259
}
248
260
previousIsDashI = false ;
249
261
if (A.empty ()) continue ;
@@ -268,17 +280,21 @@ static bool proceedCommand(std::vector<std::string> command, llvm::StringRef Dir
268
280
command = clang::tooling::getClangSyntaxOnlyAdjuster ()(command, file);
269
281
command = clang::tooling::getClangStripOutputAdjuster ()(command, file);
270
282
#endif
271
- command.push_back (" -isystem" );
272
- command.push_back (" /builtins" );
283
+ if (!hasNoStdInc) {
284
+ command.push_back (" -isystem" );
285
+ command.push_back (" /builtins" );
286
+ }
273
287
command.push_back (" -Qunused-arguments" );
274
288
command.push_back (" -Wno-unknown-warning-option" );
275
289
clang::tooling::ToolInvocation Inv (command, new BrowserAction (WasInDatabase), FM);
276
290
277
- // Map the builtins includes
278
- const EmbeddedFile *f = EmbeddedFiles;
279
- while (f->filename ) {
280
- Inv.mapVirtualFile (f->filename , {f->content , f->size } );
281
- f++;
291
+ if (!hasNoStdInc) {
292
+ // Map the builtins includes
293
+ const EmbeddedFile *f = EmbeddedFiles;
294
+ while (f->filename ) {
295
+ Inv.mapVirtualFile (f->filename , {f->content , f->size } );
296
+ f++;
297
+ }
282
298
}
283
299
bool result = Inv.run ();
284
300
if (!result) {
0 commit comments