Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -1566,7 +1566,14 @@ frontend::IncludeDirGroup Group = frontend::System; if (A->getOption().matches(OPT_internal_externc_isystem)) Group = frontend::ExternCSystem; - Opts.AddPath(A->getValue(), Group, false, true); + + SmallString<128> P(Opts.ResourceDir); + llvm::sys::path::append(P, "include"); + + if (StringRef(A->getValue()) == P) + Opts.AddPath(A->getValue(), Group, false, true); + else + Opts.AddPath(A->getValue(), Group, false, false); } // Add the path prefixes which are implicitly treated as being system headers. Index: clang/test/Driver/sysroot-flags.c =================================================================== --- clang/test/Driver/sysroot-flags.c +++ clang/test/Driver/sysroot-flags.c @@ -26,3 +26,7 @@ // RUN: FileCheck %s -check-prefix=SYSROOT_SEPARATE // SYSROOT_SEPARATE: "-isysroot" "{{[^"]*}}/foo/bar" // SYSROOT_SEPARATE: "--sysroot{{" "|=}}{{[^"]*}}/foo/bar" + +// Check that -isysroot is handled properly +// RUN: %clang -isysroot /foo/bar -c %s -v 2>&1 | \ +// RUN: grep "/foo/bar"