]> 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>
Wed, 31 Jul 2019 19:18:55 +0000 (21:18 +0200)
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

src/ccache.c

index 1781fb1140c67f7089e434d5445bd03737f26625..d87c53b9fadf24aa9d474192cd6ea5df1729eed4 100644 (file)
@@ -2300,6 +2300,7 @@ cc_process_args(struct args *args, struct args **preprocessor_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;
@@ -2508,6 +2509,12 @@ cc_process_args(struct args *args, struct args **preprocessor_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]);
@@ -3013,7 +3020,7 @@ cc_process_args(struct args *args, struct args **preprocessor_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);
@@ -3152,7 +3159,7 @@ cc_process_args(struct args *args, struct args **preprocessor_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 {
@@ -3355,6 +3362,10 @@ cc_process_args(struct args *args, struct args **preprocessor_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]);