This is an archive of the discontinued LLVM Phabricator instance.

Fix evaluation of `__has_include_next` during -frewrite-includes.
ClosedPublic

Authored by vsapsai on Apr 12 2018, 4:43 PM.

Details

Summary

__has_include_next requires correct DirectoryLookup for being
evaluated correctly. We were using Preprocessor::GetCurDirLookup() but
we were calling it after the preprocessor finished its work. And in this
case CurDirLookup is always nullptr which makes __has_include_next
behave as __has_include.

Fix by storing and using CurDirLookup when preprocessor enters a file,
not when we rewrite the includes.

rdar://problem/36305026

Event Timeline

vsapsai created this revision.Apr 12 2018, 4:43 PM

To simplify reviewing additions to the test, here is the corresponding output

# 23 "/Users/vsapsai/Projects/llvm/llvm-project/clang/test/Frontend/rewrite-includes.c" 2
#if 0 /* expanded by -frewrite-includes */
#include "rewrite-includes9.h"
#endif /* expanded by -frewrite-includes */
# 23 "/Users/vsapsai/Projects/llvm/llvm-project/clang/test/Frontend/rewrite-includes.c"
# 1 "/Users/vsapsai/Projects/llvm/llvm-project/clang/test/Frontend/Inputs/rewrite-includes9.h" 1
#if (1)/*__has_include_next(<rewrite-includes9.h>)*/
#if 0 /* expanded by -frewrite-includes */
#include_next <rewrite-includes9.h>
#endif /* expanded by -frewrite-includes */
# 2 "/Users/vsapsai/Projects/llvm/llvm-project/clang/test/Frontend/Inputs/rewrite-includes9.h"
# 1 "/Users/vsapsai/Projects/llvm/llvm-project/clang/test/Frontend/Inputs/NextIncludes/rewrite-includes9.h" 1
included_line9
# 3 "/Users/vsapsai/Projects/llvm/llvm-project/clang/test/Frontend/Inputs/rewrite-includes9.h" 2
#endif
# 4 "/Users/vsapsai/Projects/llvm/llvm-project/clang/test/Frontend/Inputs/rewrite-includes9.h"
# 24 "/Users/vsapsai/Projects/llvm/llvm-project/clang/test/Frontend/rewrite-includes.c" 2
#if 0 /* expanded by -frewrite-includes */
#include "rewrite-includes9.h"
#endif /* expanded by -frewrite-includes */
#if (1)/*__has_include_next(<rewrite-includes9.h>)*/
#if 0 /* expanded by -frewrite-includes */
#include_next <rewrite-includes9.h>
#endif /* expanded by -frewrite-includes */
included_line9
#endif
This revision is now accepted and ready to land.Apr 13 2018, 5:41 AM

Thanks for the prompt review.

This revision was automatically updated to reflect the committed changes.