-
Notifications
You must be signed in to change notification settings - Fork 74
WAR for __has_include #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maddyscientist
wants to merge
6
commits into
master
Choose a base branch
from
hotfix/__has_include
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
309dd11
WAR when nvrtc fails to correctly deal with __has_include
maddyscientist e38de0e
Remove now unnecessary includes builtin_numeric_cuda_std_limits_progr…
maddyscientist 6f9e8ac
__has_include parsing is now more robust and handles quotation includes
maddyscientist f42f49f
Added unit test for checking __has_include processing
maddyscientist 80f3920
Restore AssertHeader test as being the final test
maddyscientist 39ecb4c
Some cleanup
maddyscientist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -687,6 +687,80 @@ inline bool load_source( | |
| comment; | ||
| } | ||
|
|
||
| // WAR where nvrtc can fail to correctly return if an include is present | ||
| size_t has_include_start = cleanline.find("__has_include"); | ||
| if (has_include_start != std::string::npos) { | ||
| // find subsequent opening and closing braces | ||
| size_t open = cleanline.find("(", has_include_start); | ||
| size_t close = cleanline.find(")", open); | ||
| if (!(open == std::string::npos || close == std::string::npos)) { | ||
| std::string has_name = cleanline.substr(open + 1, close - open - 1); | ||
|
|
||
| size_t header_start = 0; | ||
| size_t header_count = 0; | ||
| bool quote_include = false; | ||
| if (has_name.find("<") != std::string::npos) { | ||
| header_start = has_name.find("<") + 1; | ||
| header_count = has_name.find(">") - header_start; | ||
| } else if (has_name.find("\"") != std::string::npos) { | ||
| quote_include = true; | ||
| header_start = has_name.find("\"") + 1; | ||
| header_count = has_name.find("\"", header_start) - header_start; | ||
| if (has_name.find("\"", header_start) == std::string::npos) | ||
| throw std::runtime_error("Malformed __has_include statement (" + | ||
| filename + ":" + std::to_string(linenum) + | ||
| ")"); | ||
| } | ||
|
|
||
| if (header_count != 0) { | ||
| std::string has_include_name = | ||
| has_name.substr(header_start, header_count); | ||
|
|
||
| #if JITIFY_PRINT_HEADER_PATHS | ||
| std::cout << "Found #if __has_include(" << has_name << ")" | ||
| << " from " << filename << ":" << linenum << std::endl; | ||
| #endif | ||
| // Try loading from filesystem | ||
| bool found_file = false; | ||
| std::string has_include_fullpath = | ||
| path_join(current_dir, has_include_name); | ||
| if (quote_include) { | ||
| file_stream.open(has_include_fullpath.c_str()); | ||
| if (file_stream) found_file = true; | ||
| } | ||
| // Search include directories | ||
| if (!found_file) { | ||
| for (int i = 0; i < (int)include_paths.size(); ++i) { | ||
| has_include_fullpath = | ||
| path_join(include_paths[i], has_include_name); | ||
| file_stream.open(has_include_fullpath.c_str()); | ||
| if (file_stream) { | ||
| found_file = true; | ||
| break; | ||
| } | ||
| } | ||
| if (!found_file) { | ||
| // Try loading from builtin headers | ||
| has_include_fullpath = | ||
| path_join("__jitify_builtin", has_include_name); | ||
| auto it = get_jitsafe_headers_map().find(has_include_name); | ||
| if (it != get_jitsafe_headers_map().end()) { | ||
| found_file = true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (found_file) { | ||
| line = cleanline.substr(0, has_include_start) + "(1)" + | ||
| cleanline.substr(close + 1); | ||
| } else { | ||
| line = cleanline.substr(0, has_include_start) + "(0)" + | ||
| cleanline.substr(close + 1); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A ternary would avoid the code duplication here: |
||
| } | ||
| } | ||
| } | ||
|
|
||
| source += line + "\n"; | ||
| } | ||
| // HACK TESTING (WAR for cub) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be unified between both
<>and""paths by setting aheader_endinstead ofheader_countand checking ifheader_end == std::string::nposafter the if/elseif. (It should also probably throw if neither<nor"is found?).