Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 2b2e574

Browse files
committed
Ensure that we still parse preprocessed CUDA files as CUDA when we use
-save-temps option. Summary: Fixes PR22926. Review: http://reviews.llvm.org/D8383 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@232737 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 4c42621 commit 2b2e574

File tree

8 files changed

+38
-5
lines changed

8 files changed

+38
-5
lines changed

Diff for: include/clang/Driver/Types.def

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
TYPE("cpp-output", PP_C, INVALID, "i", "u")
4343
TYPE("c", C, PP_C, "c", "u")
4444
TYPE("cl", CL, PP_C, "cl", "u")
45-
TYPE("cuda", CUDA, PP_CXX, "cpp", "u")
45+
TYPE("cuda-cpp-output", PP_CUDA, INVALID, "cui", "u")
46+
TYPE("cuda", CUDA, PP_CUDA, "cu", "u")
4647
TYPE("objective-c-cpp-output", PP_ObjC, INVALID, "mi", "u")
4748
TYPE("objc-cpp-output", PP_ObjC_Alias, INVALID, "mi", "u")
4849
TYPE("objective-c", ObjC, PP_ObjC, "m", "u")

Diff for: include/clang/Frontend/FrontendOptions.h

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ enum InputKind {
7171
IK_PreprocessedObjCXX,
7272
IK_OpenCL,
7373
IK_CUDA,
74+
IK_PreprocessedCuda,
7475
IK_AST,
7576
IK_LLVM_IR
7677
};

Diff for: lib/Driver/Types.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ bool types::isAcceptedByClang(ID Id) {
8585
case TY_Asm:
8686
case TY_C: case TY_PP_C:
8787
case TY_CL:
88-
case TY_CUDA:
88+
case TY_CUDA: case TY_PP_CUDA:
8989
case TY_ObjC: case TY_PP_ObjC: case TY_PP_ObjC_Alias:
9090
case TY_CXX: case TY_PP_CXX:
9191
case TY_ObjCXX: case TY_PP_ObjCXX: case TY_PP_ObjCXX_Alias:
@@ -122,7 +122,7 @@ bool types::isCXX(ID Id) {
122122
case TY_ObjCXX: case TY_PP_ObjCXX: case TY_PP_ObjCXX_Alias:
123123
case TY_CXXHeader: case TY_PP_CXXHeader:
124124
case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader:
125-
case TY_CUDA:
125+
case TY_CUDA: case TY_PP_CUDA:
126126
return true;
127127
}
128128
}
@@ -153,6 +153,7 @@ types::ID types::lookupTypeForExtension(const char *Ext) {
153153
.Case("cl", TY_CL)
154154
.Case("cp", TY_CXX)
155155
.Case("cu", TY_CUDA)
156+
.Case("cui", TY_PP_CUDA)
156157
.Case("hh", TY_CXXHeader)
157158
.Case("ll", TY_LLVM_IR)
158159
.Case("hpp", TY_CXXHeader)

Diff for: lib/Frontend/CompilerInvocation.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
990990
.Case("cpp-output", IK_PreprocessedC)
991991
.Case("assembler-with-cpp", IK_Asm)
992992
.Case("c++-cpp-output", IK_PreprocessedCXX)
993+
.Case("cuda-cpp-output", IK_PreprocessedCuda)
993994
.Case("objective-c-cpp-output", IK_PreprocessedObjC)
994995
.Case("objc-cpp-output", IK_PreprocessedObjC)
995996
.Case("objective-c++-cpp-output", IK_PreprocessedObjCXX)
@@ -1193,6 +1194,7 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
11931194
LangStd = LangStandard::lang_opencl;
11941195
break;
11951196
case IK_CUDA:
1197+
case IK_PreprocessedCuda:
11961198
LangStd = LangStandard::lang_cuda;
11971199
break;
11981200
case IK_Asm:
@@ -1245,7 +1247,8 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
12451247
Opts.NativeHalfType = 1;
12461248
}
12471249

1248-
Opts.CUDA = LangStd == LangStandard::lang_cuda || IK == IK_CUDA;
1250+
Opts.CUDA = IK == IK_CUDA || IK == IK_PreprocessedCuda ||
1251+
LangStd == LangStandard::lang_cuda;
12491252

12501253
// OpenCL and C++ both have bool, true, false keywords.
12511254
Opts.Bool = Opts.OpenCL || Opts.CPlusPlus;
@@ -1360,6 +1363,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
13601363
<< A->getAsString(Args) << "OpenCL";
13611364
break;
13621365
case IK_CUDA:
1366+
case IK_PreprocessedCuda:
13631367
if (!Std.isCPlusPlus())
13641368
Diags.Report(diag::err_drv_argument_not_allowed_with)
13651369
<< A->getAsString(Args) << "CUDA";

Diff for: lib/Frontend/FrontendActions.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ void PrintPreambleAction::ExecuteAction() {
690690
case IK_None:
691691
case IK_Asm:
692692
case IK_PreprocessedC:
693+
case IK_PreprocessedCuda:
693694
case IK_PreprocessedCXX:
694695
case IK_PreprocessedObjC:
695696
case IK_PreprocessedObjCXX:

Diff for: lib/Frontend/FrontendOptions.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ InputKind FrontendOptions::getInputKindForExtension(StringRef Extension) {
1818
.Cases("S", "s", IK_Asm)
1919
.Case("i", IK_PreprocessedC)
2020
.Case("ii", IK_PreprocessedCXX)
21+
.Case("cui", IK_PreprocessedCuda)
2122
.Case("m", IK_ObjC)
2223
.Case("mi", IK_PreprocessedObjC)
2324
.Cases("mm", "M", IK_ObjCXX)

Diff for: test/Driver/cuda-simple.cu

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Verify that we can parse a simple CUDA file with or without -save-temps
2+
// http://llvm.org/PR22936
3+
// RUN: %clang -Werror -fsyntax-only -c %s
4+
//
5+
// Verify that we pass -x cuda-cpp-output to compiler after
6+
// preprocessing a CUDA file
7+
// RUN: %clang -Werror -### -save-temps -c %s 2>&1 | FileCheck %s
8+
// CHECK: "-cc1"
9+
// CHECK: "-E"
10+
// CHECK: "-x" "cuda"
11+
// CHECK-NEXT: "-cc1"
12+
// CHECK: "-x" "cuda-cpp-output"
13+
//
14+
// Verify that compiler accepts CUDA syntax with "-x cuda-cpp-output".
15+
// RUN: %clang -Werror -fsyntax-only -x cuda-cpp-output -c %s
16+
17+
int cudaConfigureCall(int, int);
18+
__attribute__((global)) void kernel() {}
19+
20+
void func() {
21+
kernel<<<1,1>>>();
22+
}
23+

Diff for: test/Driver/lit.local.cfg

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
config.suffixes = ['.c', '.cpp', '.h', '.m', '.mm', '.S', '.s', '.f90', '.f95']
1+
config.suffixes = ['.c', '.cpp', '.h', '.m', '.mm', '.S', '.s', '.f90', '.f95',
2+
'.cu']
23
config.substitutions = list(config.substitutions)
34
config.substitutions.insert(0,
45
('%clang_cc1',

0 commit comments

Comments
 (0)