summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunyan He <junyan.he@linux.intel.com>2016-01-21 18:44:27 +0800
committerYang Rong <rong.r.yang@intel.com>2016-01-25 10:07:06 +0800
commit8e9ef20f731d4135fc4866bcf7374c8222e21a25 (patch)
treea82b97083b984666a26f612c0261ada81711c274
parent43ed76cfcb4ca4b2553c3c8b8986d91f86c28d25 (diff)
Fix the bug when we pass argument with spaces.
We failed to handle -I "/XX X/YY YY/" like path or -DAAA=BBB"CC DDD"EEE like defines from the build option. We need to consider the spaces here and pass it correctly to Clang. V4: Fix a minor mistake. Signed-off-by: Junyan He <junyan.he@linux.intel.com> Reviewed-by: Yang Rong <rong.r.yang@intel.com>
-rw-r--r--backend/src/backend/program.cpp73
1 files changed, 67 insertions, 6 deletions
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index f886d034..e3df36b3 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -770,9 +770,9 @@ namespace gbe {
bool useDefaultCLCVersion = true;
if (options) {
- char *str = (char *)malloc(sizeof(char) * (strlen(options) + 1));
- memcpy(str, options, strlen(options) + 1);
- std::string optionStr(str);
+ char *c_str = (char *)malloc(sizeof(char) * (strlen(options) + 1));
+ memcpy(c_str, options, strlen(options) + 1);
+ std::string optionStr(c_str);
const std::string unsupportedOptions("-cl-denorms-are-zero, -cl-strict-aliasing, -cl-opt-disable,"
"-cl-no-signed-zeros, -cl-fp32-correctly-rounded-divide-sqrt");
@@ -781,14 +781,75 @@ namespace gbe {
while (end != std::string::npos) {
end = optionStr.find(' ', start);
std::string str = optionStr.substr(start, end - start);
- start = end + 1;
- if(str.size() == 0)
+
+ if(str.size() == 0) {
+ start = end + 1;
continue;
+ }
+
+EXTEND_QUOTE:
+ /* We need to find the ", if the there are odd number of " within this string,
+ we need to extend the string to the matched " of the last one. */
+ int quoteNum = 0;
+ for (size_t i = 0; i < str.size(); i++) {
+ if (str[i] == '"') {
+ quoteNum++;
+ }
+ }
+
+ if (quoteNum % 2) { // Odd number of ", need to extend the string.
+ /* find the second " */
+ while (end < optionStr.size() && optionStr[end] != '"')
+ end++;
+
+ if (end == optionStr.size()) {
+ printf("Warning: Unmatched \" number in build option\n");
+ free(c_str);
+ return false;
+ }
+
+ GBE_ASSERT(optionStr[end] == '"');
+ end++;
+
+ if (end < optionStr.size() && optionStr[end] != ' ') {
+ // "CC AAA"BBDDDD case, need to further extend.
+ end = optionStr.find(' ', end);
+ str = optionStr.substr(start, end - start);
+ goto EXTEND_QUOTE;
+ } else {
+ str = optionStr.substr(start, end - start);
+ }
+ }
+ start = end + 1;
if(unsupportedOptions.find(str) != std::string::npos) {
continue;
}
+ /* if -I, we need to extract "path" to path, no " */
+ if (clOpt.back() == "-I") {
+ if (str[0] == '"') {
+ GBE_ASSERT(str[str.size() - 1] == '"');
+ if (str.size() > 2) {
+ clOpt.push_back(str.substr(1, str.size() - 2));
+ } else {
+ clOpt.push_back("");
+ }
+ continue;
+ }
+ }
+ // The -I"YYYY" like case.
+ if (str.size() > 4 && str[0] == '-' && str[1] == 'I' && str[2] == '"') {
+ GBE_ASSERT(str[str.size() - 1] == '"');
+ clOpt.push_back("-I");
+ if (str.size() > 4) {
+ clOpt.push_back(str.substr(3, str.size() - 4));
+ } else {
+ clOpt.push_back("");
+ }
+ continue;
+ }
+
if(str.find("-cl-std=") != std::string::npos) {
useDefaultCLCVersion = false;
if (str == "-cl-std=CL1.1")
@@ -822,7 +883,7 @@ namespace gbe {
clOpt.push_back(str);
}
- free(str);
+ free(c_str);
}
if (useDefaultCLCVersion) {