@@ -124,6 +124,17 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
124
124
// The parser verifies that there is a string literal here.
125
125
assert (AsmString->isAscii ());
126
126
127
+ bool ValidateConstraints = true ;
128
+ if (getLangOpts ().CUDA ) {
129
+ // In CUDA mode don't verify asm constraints in device functions during host
130
+ // compilation and vice versa.
131
+ bool InDeviceMode = getLangOpts ().CUDAIsDevice ;
132
+ FunctionDecl *FD = getCurFunctionDecl ();
133
+ bool IsDeviceFunction =
134
+ FD && (FD->hasAttr <CUDADeviceAttr>() || FD->hasAttr <CUDAGlobalAttr>());
135
+ ValidateConstraints = IsDeviceFunction == InDeviceMode;
136
+ }
137
+
127
138
for (unsigned i = 0 ; i != NumOutputs; i++) {
128
139
StringLiteral *Literal = Constraints[i];
129
140
assert (Literal->isAscii ());
@@ -133,7 +144,8 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
133
144
OutputName = Names[i]->getName ();
134
145
135
146
TargetInfo::ConstraintInfo Info (Literal->getString (), OutputName);
136
- if (!Context.getTargetInfo ().validateOutputConstraint (Info))
147
+ if (ValidateConstraints &&
148
+ !Context.getTargetInfo ().validateOutputConstraint (Info))
137
149
return StmtError (Diag (Literal->getLocStart (),
138
150
diag::err_asm_invalid_output_constraint)
139
151
<< Info.getConstraintStr ());
@@ -207,8 +219,9 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
207
219
InputName = Names[i]->getName ();
208
220
209
221
TargetInfo::ConstraintInfo Info (Literal->getString (), InputName);
210
- if (!Context.getTargetInfo ().validateInputConstraint (OutputConstraintInfos.data (),
211
- NumOutputs, Info)) {
222
+ if (ValidateConstraints &&
223
+ !Context.getTargetInfo ().validateInputConstraint (
224
+ OutputConstraintInfos.data (), NumOutputs, Info)) {
212
225
return StmtError (Diag (Literal->getLocStart (),
213
226
diag::err_asm_invalid_input_constraint)
214
227
<< Info.getConstraintStr ());
0 commit comments