[Mesa-dev] [PATCH] clover: Pass unquoted include path to Clang

Vedran Miletić rivanvx at gmail.com
Wed May 11 12:26:01 UTC 2016


OpenCL apps quote include paths they pass to the OpenCL compiler. If
the OpenCL compiler is called via a shell, the shell removes quotes
before passing the argument to the compiler. Since we call Clang as a
library, we have to remove quotes before passing the argument.
---
 src/gallium/state_trackers/clover/llvm/invocation.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
index 96f6a48..88ed14a 100644
--- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
+++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
@@ -152,6 +152,20 @@ namespace {
       while (!ss.eof()) {
          std::string opt;
          getline(ss, opt, ' ');
+         if (opt.substr(0, 2) == std::string("-I"))
+         {
+             // OpenCL programs are not aware that we are not a shell and could
+             // therefore pass a quoted include path. We should unquote it
+             // before passing it to the compiler.
+             // We do not want to use std::string::replace here, as include path
+             // can contain quotes in file names.
+             if ((opt[2] == '"' && opt[opt.length() - 1] == '"') ||
+                 (opt[2] == '\'' && opt[opt.length() - 1] == '\''))
+             {
+                 // "-I" + path, subtracting 4 characters for -I and two quotes
+                 opt = opt.substr(0, 2) + opt.substr(3, opt.length() - 4);
+             }
+         }
          opts_array.push_back(opt);
       }
 
-- 
2.7.4



More information about the mesa-dev mailing list