]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
When compiling CUDA code, recognize -dc as compilation only argument
authorAlexander Korsunsky <alexander.korsunsky@rcpe.at>
Tue, 16 Apr 2019 14:38:51 +0000 (16:38 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 24 Mar 2020 19:53:51 +0000 (20:53 +0100)
nvcc's options -dc or --device-c imply -c but also generates device
code. We catch it as an option if our guessed compiler is NVCC

(cherry picked from commit cece6046bbab113eb57018b41a679b82ff6d8f62)

src/ccache.c

index b9bafac2e4c617e70a31f35228f170dcece5668c..2b437636df09d98539e0d38f988962392849fc76 100644 (file)
@@ -2543,6 +2543,7 @@ cc_process_args(struct args *args,
                 struct args **compiler_args)
 {
        bool found_c_opt = false;
+       bool found_dc_opt = false;
        bool found_S_opt = false;
        bool found_pch = false;
        bool found_fpch_preprocess = false;
@@ -2754,6 +2755,12 @@ cc_process_args(struct args *args,
                        continue;
                }
 
+               // when using nvcc with separable compilation, -dc implies -c
+               if ((str_eq(argv[i], "-dc") || str_eq(argv[i], "--device-c")) && guessed_compiler == GUESSED_NVCC) {
+                       found_dc_opt = true;
+                       continue;
+               }
+
                // -S changes the default extension.
                if (str_eq(argv[i], "-S")) {
                        args_add(common_args, argv[i]);
@@ -3270,7 +3277,7 @@ cc_process_args(struct args *args,
                        if (language_for_file(argv[i])) {
                                cc_log("Multiple input files: %s and %s", input_file, argv[i]);
                                stats_update(STATS_MULTIPLE);
-                       } else if (!found_c_opt) {
+                       } else if (!found_c_opt && !found_dc_opt) {
                                cc_log("Called for link with %s", argv[i]);
                                if (strstr(argv[i], "conftest.")) {
                                        stats_update(STATS_CONFTEST);
@@ -3411,7 +3418,7 @@ cc_process_args(struct args *args,
                goto out;
        }
 
-       if (!found_c_opt && !found_S_opt) {
+       if (!found_c_opt && !found_dc_opt && !found_S_opt) {
                if (output_is_precompiled_header) {
                        args_add(common_args, "-c");
                } else {
@@ -3615,6 +3622,10 @@ cc_process_args(struct args *args,
                args_add(*compiler_args, "-c");
        }
 
+       if (found_dc_opt) {
+               args_add(*compiler_args, "-dc");
+       }
+
        for (size_t i = 0; i < arch_args_size; ++i) {
                args_add(*compiler_args, "-arch");
                args_add(*compiler_args, arch_args[i]);