blob: 47a7672ae19bdd8e4a4245d349bec22cbbb9e20f [file] [log] [blame]
Chad Rosier571c5e92012-08-17 21:27:25 +00001//===--- SemaStmtAsm.cpp - Semantic Analysis for Asm Statements -----------===//
Chad Rosier0731aff2012-08-17 21:19:40 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements semantic analysis for inline asm statements.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Sema/SemaInternal.h"
Chad Rosier5c563642012-10-25 21:49:22 +000015#include "clang/AST/RecordLayout.h"
Chad Rosier0731aff2012-08-17 21:19:40 +000016#include "clang/AST/TypeLoc.h"
Chad Rosier0731aff2012-08-17 21:19:40 +000017#include "clang/Basic/TargetInfo.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000018#include "clang/Sema/Initialization.h"
19#include "clang/Sema/Lookup.h"
20#include "clang/Sema/Scope.h"
21#include "clang/Sema/ScopeInfo.h"
Chad Rosier0731aff2012-08-17 21:19:40 +000022#include "llvm/ADT/ArrayRef.h"
23#include "llvm/ADT/BitVector.h"
Alp Toker10399272014-06-08 05:11:37 +000024#include "llvm/MC/MCParser/MCAsmParser.h"
Chad Rosier0731aff2012-08-17 21:19:40 +000025using namespace clang;
26using namespace sema;
27
28/// CheckAsmLValue - GNU C has an extremely ugly extension whereby they silently
29/// ignore "noop" casts in places where an lvalue is required by an inline asm.
30/// We emulate this behavior when -fheinous-gnu-extensions is specified, but
31/// provide a strong guidance to not use it.
32///
33/// This method checks to see if the argument is an acceptable l-value and
34/// returns false if it is a case we can handle.
35static bool CheckAsmLValue(const Expr *E, Sema &S) {
36 // Type dependent expressions will be checked during instantiation.
37 if (E->isTypeDependent())
38 return false;
39
40 if (E->isLValue())
41 return false; // Cool, this is an lvalue.
42
43 // Okay, this is not an lvalue, but perhaps it is the result of a cast that we
44 // are supposed to allow.
45 const Expr *E2 = E->IgnoreParenNoopCasts(S.Context);
46 if (E != E2 && E2->isLValue()) {
47 if (!S.getLangOpts().HeinousExtensions)
48 S.Diag(E2->getLocStart(), diag::err_invalid_asm_cast_lvalue)
49 << E->getSourceRange();
50 else
51 S.Diag(E2->getLocStart(), diag::warn_invalid_asm_cast_lvalue)
52 << E->getSourceRange();
53 // Accept, even if we emitted an error diagnostic.
54 return false;
55 }
56
57 // None of the above, just randomly invalid non-lvalue.
58 return true;
59}
60
61/// isOperandMentioned - Return true if the specified operand # is mentioned
62/// anywhere in the decomposed asm string.
63static bool isOperandMentioned(unsigned OpNo,
Chad Rosierde70e0e2012-08-25 00:11:56 +000064 ArrayRef<GCCAsmStmt::AsmStringPiece> AsmStrPieces) {
Chad Rosier0731aff2012-08-17 21:19:40 +000065 for (unsigned p = 0, e = AsmStrPieces.size(); p != e; ++p) {
Chad Rosierde70e0e2012-08-25 00:11:56 +000066 const GCCAsmStmt::AsmStringPiece &Piece = AsmStrPieces[p];
Chad Rosier0731aff2012-08-17 21:19:40 +000067 if (!Piece.isOperand()) continue;
68
69 // If this is a reference to the input and if the input was the smaller
70 // one, then we have to reject this asm.
71 if (Piece.getOperandNo() == OpNo)
72 return true;
73 }
74 return false;
75}
76
Chad Rosierde70e0e2012-08-25 00:11:56 +000077StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
78 bool IsVolatile, unsigned NumOutputs,
79 unsigned NumInputs, IdentifierInfo **Names,
Dmitri Gribenkoea2d5f82013-05-10 01:14:26 +000080 MultiExprArg constraints, MultiExprArg Exprs,
Chad Rosierde70e0e2012-08-25 00:11:56 +000081 Expr *asmString, MultiExprArg clobbers,
82 SourceLocation RParenLoc) {
Chad Rosier0731aff2012-08-17 21:19:40 +000083 unsigned NumClobbers = clobbers.size();
84 StringLiteral **Constraints =
Benjamin Kramercc4c49d2012-08-23 23:38:35 +000085 reinterpret_cast<StringLiteral**>(constraints.data());
Chad Rosier0731aff2012-08-17 21:19:40 +000086 StringLiteral *AsmString = cast<StringLiteral>(asmString);
Benjamin Kramercc4c49d2012-08-23 23:38:35 +000087 StringLiteral **Clobbers = reinterpret_cast<StringLiteral**>(clobbers.data());
Chad Rosier0731aff2012-08-17 21:19:40 +000088
89 SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos;
90
91 // The parser verifies that there is a string literal here.
92 if (!AsmString->isAscii())
93 return StmtError(Diag(AsmString->getLocStart(),diag::err_asm_wide_character)
94 << AsmString->getSourceRange());
95
96 for (unsigned i = 0; i != NumOutputs; i++) {
97 StringLiteral *Literal = Constraints[i];
98 if (!Literal->isAscii())
99 return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character)
100 << Literal->getSourceRange());
101
102 StringRef OutputName;
103 if (Names[i])
104 OutputName = Names[i]->getName();
105
106 TargetInfo::ConstraintInfo Info(Literal->getString(), OutputName);
107 if (!Context.getTargetInfo().validateOutputConstraint(Info))
108 return StmtError(Diag(Literal->getLocStart(),
109 diag::err_asm_invalid_output_constraint)
110 << Info.getConstraintStr());
111
112 // Check that the output exprs are valid lvalues.
113 Expr *OutputExpr = Exprs[i];
Bill Wendlingc4fc3a22013-03-25 21:09:49 +0000114 if (CheckAsmLValue(OutputExpr, *this))
Chad Rosier0731aff2012-08-17 21:19:40 +0000115 return StmtError(Diag(OutputExpr->getLocStart(),
Bill Wendlingc4fc3a22013-03-25 21:09:49 +0000116 diag::err_asm_invalid_lvalue_in_output)
117 << OutputExpr->getSourceRange());
118
Bill Wendlingb68b7572013-03-27 06:06:26 +0000119 if (RequireCompleteType(OutputExpr->getLocStart(), Exprs[i]->getType(),
120 diag::err_dereference_incomplete_type))
121 return StmtError();
Chad Rosier0731aff2012-08-17 21:19:40 +0000122
123 OutputConstraintInfos.push_back(Info);
124 }
125
126 SmallVector<TargetInfo::ConstraintInfo, 4> InputConstraintInfos;
127
128 for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) {
129 StringLiteral *Literal = Constraints[i];
130 if (!Literal->isAscii())
131 return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character)
132 << Literal->getSourceRange());
133
134 StringRef InputName;
135 if (Names[i])
136 InputName = Names[i]->getName();
137
138 TargetInfo::ConstraintInfo Info(Literal->getString(), InputName);
139 if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos.data(),
140 NumOutputs, Info)) {
141 return StmtError(Diag(Literal->getLocStart(),
142 diag::err_asm_invalid_input_constraint)
143 << Info.getConstraintStr());
144 }
145
146 Expr *InputExpr = Exprs[i];
147
148 // Only allow void types for memory constraints.
149 if (Info.allowsMemory() && !Info.allowsRegister()) {
150 if (CheckAsmLValue(InputExpr, *this))
151 return StmtError(Diag(InputExpr->getLocStart(),
152 diag::err_asm_invalid_lvalue_in_input)
153 << Info.getConstraintStr()
154 << InputExpr->getSourceRange());
David Majnemerade4bee2014-07-14 16:27:53 +0000155 } else {
156 ExprResult Result = DefaultFunctionArrayLvalueConversion(Exprs[i]);
157 if (Result.isInvalid())
158 return StmtError();
159
160 Exprs[i] = Result.get();
Chad Rosier0731aff2012-08-17 21:19:40 +0000161 }
162
163 if (Info.allowsRegister()) {
164 if (InputExpr->getType()->isVoidType()) {
165 return StmtError(Diag(InputExpr->getLocStart(),
166 diag::err_asm_invalid_type_in_input)
167 << InputExpr->getType() << Info.getConstraintStr()
168 << InputExpr->getSourceRange());
169 }
170 }
171
Chad Rosier0731aff2012-08-17 21:19:40 +0000172 InputConstraintInfos.push_back(Info);
Bill Wendling887b4852012-11-12 06:42:51 +0000173
174 const Type *Ty = Exprs[i]->getType().getTypePtr();
Bill Wendlingc4fc3a22013-03-25 21:09:49 +0000175 if (Ty->isDependentType())
Eric Christopherd41010a2012-11-12 23:13:34 +0000176 continue;
177
Bill Wendlingc4fc3a22013-03-25 21:09:49 +0000178 if (!Ty->isVoidType() || !Info.allowsMemory())
Bill Wendlingb68b7572013-03-27 06:06:26 +0000179 if (RequireCompleteType(InputExpr->getLocStart(), Exprs[i]->getType(),
180 diag::err_dereference_incomplete_type))
181 return StmtError();
Bill Wendlingc4fc3a22013-03-25 21:09:49 +0000182
Bill Wendling887b4852012-11-12 06:42:51 +0000183 unsigned Size = Context.getTypeSize(Ty);
184 if (!Context.getTargetInfo().validateInputSize(Literal->getString(),
185 Size))
186 return StmtError(Diag(InputExpr->getLocStart(),
187 diag::err_asm_invalid_input_size)
188 << Info.getConstraintStr());
Chad Rosier0731aff2012-08-17 21:19:40 +0000189 }
190
191 // Check that the clobbers are valid.
192 for (unsigned i = 0; i != NumClobbers; i++) {
193 StringLiteral *Literal = Clobbers[i];
194 if (!Literal->isAscii())
195 return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character)
196 << Literal->getSourceRange());
197
198 StringRef Clobber = Literal->getString();
199
200 if (!Context.getTargetInfo().isValidClobber(Clobber))
201 return StmtError(Diag(Literal->getLocStart(),
202 diag::err_asm_unknown_register_name) << Clobber);
203 }
204
Chad Rosierde70e0e2012-08-25 00:11:56 +0000205 GCCAsmStmt *NS =
206 new (Context) GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs,
Dmitri Gribenkoea2d5f82013-05-10 01:14:26 +0000207 NumInputs, Names, Constraints, Exprs.data(),
208 AsmString, NumClobbers, Clobbers, RParenLoc);
Chad Rosier0731aff2012-08-17 21:19:40 +0000209 // Validate the asm string, ensuring it makes sense given the operands we
210 // have.
Chad Rosierde70e0e2012-08-25 00:11:56 +0000211 SmallVector<GCCAsmStmt::AsmStringPiece, 8> Pieces;
Chad Rosier0731aff2012-08-17 21:19:40 +0000212 unsigned DiagOffs;
213 if (unsigned DiagID = NS->AnalyzeAsmString(Pieces, Context, DiagOffs)) {
214 Diag(getLocationOfStringLiteralByte(AsmString, DiagOffs), DiagID)
215 << AsmString->getSourceRange();
216 return StmtError();
217 }
218
Bill Wendling9d1ee112012-10-25 23:28:48 +0000219 // Validate constraints and modifiers.
220 for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
221 GCCAsmStmt::AsmStringPiece &Piece = Pieces[i];
222 if (!Piece.isOperand()) continue;
223
224 // Look for the correct constraint index.
225 unsigned Idx = 0;
226 unsigned ConstraintIdx = 0;
227 for (unsigned i = 0, e = NS->getNumOutputs(); i != e; ++i, ++ConstraintIdx) {
228 TargetInfo::ConstraintInfo &Info = OutputConstraintInfos[i];
229 if (Idx == Piece.getOperandNo())
230 break;
231 ++Idx;
232
233 if (Info.isReadWrite()) {
234 if (Idx == Piece.getOperandNo())
235 break;
236 ++Idx;
237 }
238 }
239
240 for (unsigned i = 0, e = NS->getNumInputs(); i != e; ++i, ++ConstraintIdx) {
241 TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i];
242 if (Idx == Piece.getOperandNo())
243 break;
244 ++Idx;
245
246 if (Info.isReadWrite()) {
247 if (Idx == Piece.getOperandNo())
248 break;
249 ++Idx;
250 }
251 }
252
253 // Now that we have the right indexes go ahead and check.
254 StringLiteral *Literal = Constraints[ConstraintIdx];
255 const Type *Ty = Exprs[ConstraintIdx]->getType().getTypePtr();
256 if (Ty->isDependentType() || Ty->isIncompleteType())
257 continue;
258
259 unsigned Size = Context.getTypeSize(Ty);
Akira Hatanaka987f1862014-08-22 06:05:21 +0000260 std::string SuggestedModifier;
261 if (!Context.getTargetInfo().validateConstraintModifier(
262 Literal->getString(), Piece.getModifier(), Size,
263 SuggestedModifier)) {
Bill Wendling9d1ee112012-10-25 23:28:48 +0000264 Diag(Exprs[ConstraintIdx]->getLocStart(),
265 diag::warn_asm_mismatched_size_modifier);
Akira Hatanaka987f1862014-08-22 06:05:21 +0000266
267 if (!SuggestedModifier.empty()) {
268 auto B = Diag(Piece.getRange().getBegin(),
269 diag::note_asm_missing_constraint_modifier)
270 << SuggestedModifier;
271 SuggestedModifier = "%" + SuggestedModifier + Piece.getString();
272 B.AddFixItHint(FixItHint::CreateReplacement(Piece.getRange(),
273 SuggestedModifier));
274 }
275 }
Bill Wendling9d1ee112012-10-25 23:28:48 +0000276 }
277
Chad Rosier0731aff2012-08-17 21:19:40 +0000278 // Validate tied input operands for type mismatches.
279 for (unsigned i = 0, e = InputConstraintInfos.size(); i != e; ++i) {
280 TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i];
281
282 // If this is a tied constraint, verify that the output and input have
283 // either exactly the same type, or that they are int/ptr operands with the
284 // same size (int/long, int*/long, are ok etc).
285 if (!Info.hasTiedOperand()) continue;
286
287 unsigned TiedTo = Info.getTiedOperand();
288 unsigned InputOpNo = i+NumOutputs;
289 Expr *OutputExpr = Exprs[TiedTo];
290 Expr *InputExpr = Exprs[InputOpNo];
291
292 if (OutputExpr->isTypeDependent() || InputExpr->isTypeDependent())
293 continue;
294
295 QualType InTy = InputExpr->getType();
296 QualType OutTy = OutputExpr->getType();
297 if (Context.hasSameType(InTy, OutTy))
298 continue; // All types can be tied to themselves.
299
300 // Decide if the input and output are in the same domain (integer/ptr or
301 // floating point.
302 enum AsmDomain {
303 AD_Int, AD_FP, AD_Other
304 } InputDomain, OutputDomain;
305
306 if (InTy->isIntegerType() || InTy->isPointerType())
307 InputDomain = AD_Int;
308 else if (InTy->isRealFloatingType())
309 InputDomain = AD_FP;
310 else
311 InputDomain = AD_Other;
312
313 if (OutTy->isIntegerType() || OutTy->isPointerType())
314 OutputDomain = AD_Int;
315 else if (OutTy->isRealFloatingType())
316 OutputDomain = AD_FP;
317 else
318 OutputDomain = AD_Other;
319
320 // They are ok if they are the same size and in the same domain. This
321 // allows tying things like:
322 // void* to int*
323 // void* to int if they are the same size.
324 // double to long double if they are the same size.
325 //
326 uint64_t OutSize = Context.getTypeSize(OutTy);
327 uint64_t InSize = Context.getTypeSize(InTy);
328 if (OutSize == InSize && InputDomain == OutputDomain &&
329 InputDomain != AD_Other)
330 continue;
331
332 // If the smaller input/output operand is not mentioned in the asm string,
333 // then we can promote the smaller one to a larger input and the asm string
334 // won't notice.
335 bool SmallerValueMentioned = false;
336
337 // If this is a reference to the input and if the input was the smaller
338 // one, then we have to reject this asm.
339 if (isOperandMentioned(InputOpNo, Pieces)) {
340 // This is a use in the asm string of the smaller operand. Since we
341 // codegen this by promoting to a wider value, the asm will get printed
342 // "wrong".
343 SmallerValueMentioned |= InSize < OutSize;
344 }
345 if (isOperandMentioned(TiedTo, Pieces)) {
346 // If this is a reference to the output, and if the output is the larger
347 // value, then it's ok because we'll promote the input to the larger type.
348 SmallerValueMentioned |= OutSize < InSize;
349 }
350
351 // If the smaller value wasn't mentioned in the asm string, and if the
352 // output was a register, just extend the shorter one to the size of the
353 // larger one.
354 if (!SmallerValueMentioned && InputDomain != AD_Other &&
355 OutputConstraintInfos[TiedTo].allowsRegister())
356 continue;
357
358 // Either both of the operands were mentioned or the smaller one was
359 // mentioned. One more special case that we'll allow: if the tied input is
360 // integer, unmentioned, and is a constant, then we'll allow truncating it
361 // down to the size of the destination.
362 if (InputDomain == AD_Int && OutputDomain == AD_Int &&
363 !isOperandMentioned(InputOpNo, Pieces) &&
364 InputExpr->isEvaluatable(Context)) {
365 CastKind castKind =
366 (OutTy->isBooleanType() ? CK_IntegralToBoolean : CK_IntegralCast);
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000367 InputExpr = ImpCastExprToType(InputExpr, OutTy, castKind).get();
Chad Rosier0731aff2012-08-17 21:19:40 +0000368 Exprs[InputOpNo] = InputExpr;
369 NS->setInputExpr(i, InputExpr);
370 continue;
371 }
372
373 Diag(InputExpr->getLocStart(),
374 diag::err_asm_tying_incompatible_types)
375 << InTy << OutTy << OutputExpr->getSourceRange()
376 << InputExpr->getSourceRange();
377 return StmtError();
378 }
379
Nikola Smiljanic03ff2592014-05-29 14:05:12 +0000380 return NS;
Chad Rosier0731aff2012-08-17 21:19:40 +0000381}
382
John McCallf413f5e2013-05-03 00:10:13 +0000383ExprResult Sema::LookupInlineAsmIdentifier(CXXScopeSpec &SS,
384 SourceLocation TemplateKWLoc,
385 UnqualifiedId &Id,
Alp Toker10399272014-06-08 05:11:37 +0000386 llvm::InlineAsmIdentifierInfo &Info,
John McCallf413f5e2013-05-03 00:10:13 +0000387 bool IsUnevaluatedContext) {
Chad Rosierb18a2852013-04-22 17:01:37 +0000388 Info.clear();
Chad Rosierce2bcbf2012-10-18 15:49:40 +0000389
John McCallf413f5e2013-05-03 00:10:13 +0000390 if (IsUnevaluatedContext)
391 PushExpressionEvaluationContext(UnevaluatedAbstract,
392 ReuseLambdaContextDecl);
393
394 ExprResult Result = ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Id,
395 /*trailing lparen*/ false,
Chad Rosierb9aff1e2013-05-24 18:32:55 +0000396 /*is & operand*/ false,
Craig Topperc3ec1492014-05-26 06:22:03 +0000397 /*CorrectionCandidateCallback=*/nullptr,
Chad Rosierb9aff1e2013-05-24 18:32:55 +0000398 /*IsInlineAsmIdentifier=*/ true);
John McCallf413f5e2013-05-03 00:10:13 +0000399
400 if (IsUnevaluatedContext)
401 PopExpressionEvaluationContext();
402
403 if (!Result.isUsable()) return Result;
404
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000405 Result = CheckPlaceholderExpr(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +0000406 if (!Result.isUsable()) return Result;
407
408 QualType T = Result.get()->getType();
409
410 // For now, reject dependent types.
411 if (T->isDependentType()) {
412 Diag(Id.getLocStart(), diag::err_asm_incomplete_type) << T;
413 return ExprError();
Chad Rosierce2bcbf2012-10-18 15:49:40 +0000414 }
415
John McCallf413f5e2013-05-03 00:10:13 +0000416 // Any sort of function type is fine.
417 if (T->isFunctionType()) {
418 return Result;
Chad Rosierce2bcbf2012-10-18 15:49:40 +0000419 }
420
John McCallf413f5e2013-05-03 00:10:13 +0000421 // Otherwise, it needs to be a complete type.
422 if (RequireCompleteExprType(Result.get(), diag::err_asm_incomplete_type)) {
423 return ExprError();
424 }
425
426 // Compute the type size (and array length if applicable?).
427 Info.Type = Info.Size = Context.getTypeSizeInChars(T).getQuantity();
428 if (T->isArrayType()) {
429 const ArrayType *ATy = Context.getAsArrayType(T);
430 Info.Type = Context.getTypeSizeInChars(ATy->getElementType()).getQuantity();
431 Info.Length = Info.Size / Info.Type;
432 }
433
434 // We can work with the expression as long as it's not an r-value.
435 if (!Result.get()->isRValue())
Chad Rosierb18a2852013-04-22 17:01:37 +0000436 Info.IsVarDecl = true;
Chad Rosierce2bcbf2012-10-18 15:49:40 +0000437
John McCallf413f5e2013-05-03 00:10:13 +0000438 return Result;
Chad Rosier4a0054f2012-10-15 19:56:10 +0000439}
Chad Rosierd997bd12012-08-22 19:18:30 +0000440
Chad Rosier5c563642012-10-25 21:49:22 +0000441bool Sema::LookupInlineAsmField(StringRef Base, StringRef Member,
442 unsigned &Offset, SourceLocation AsmLoc) {
443 Offset = 0;
444 LookupResult BaseResult(*this, &Context.Idents.get(Base), SourceLocation(),
445 LookupOrdinaryName);
446
447 if (!LookupName(BaseResult, getCurScope()))
448 return true;
449
450 if (!BaseResult.isSingleResult())
451 return true;
452
Craig Topperc3ec1492014-05-26 06:22:03 +0000453 const RecordType *RT = nullptr;
Chad Rosier10230d42013-04-01 17:58:03 +0000454 NamedDecl *FoundDecl = BaseResult.getFoundDecl();
455 if (VarDecl *VD = dyn_cast<VarDecl>(FoundDecl))
Chad Rosier5c563642012-10-25 21:49:22 +0000456 RT = VD->getType()->getAs<RecordType>();
Nico Weber9ef9ca42014-05-06 03:13:27 +0000457 else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(FoundDecl))
Chad Rosier5c563642012-10-25 21:49:22 +0000458 RT = TD->getUnderlyingType()->getAs<RecordType>();
Nico Weber9ef9ca42014-05-06 03:13:27 +0000459 else if (TypeDecl *TD = dyn_cast<TypeDecl>(FoundDecl))
460 RT = TD->getTypeForDecl()->getAs<RecordType>();
Chad Rosier5c563642012-10-25 21:49:22 +0000461 if (!RT)
462 return true;
463
464 if (RequireCompleteType(AsmLoc, QualType(RT, 0), 0))
465 return true;
466
467 LookupResult FieldResult(*this, &Context.Idents.get(Member), SourceLocation(),
468 LookupMemberName);
469
470 if (!LookupQualifiedName(FieldResult, RT->getDecl()))
471 return true;
472
473 // FIXME: Handle IndirectFieldDecl?
474 FieldDecl *FD = dyn_cast<FieldDecl>(FieldResult.getFoundDecl());
475 if (!FD)
476 return true;
477
478 const ASTRecordLayout &RL = Context.getASTRecordLayout(RT->getDecl());
479 unsigned i = FD->getFieldIndex();
480 CharUnits Result = Context.toCharUnitsFromBits(RL.getFieldOffset(i));
481 Offset = (unsigned)Result.getQuantity();
482
483 return false;
484}
485
Chad Rosierb261a502012-09-13 00:06:55 +0000486StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +0000487 ArrayRef<Token> AsmToks,
488 StringRef AsmString,
489 unsigned NumOutputs, unsigned NumInputs,
490 ArrayRef<StringRef> Constraints,
491 ArrayRef<StringRef> Clobbers,
492 ArrayRef<Expr*> Exprs,
493 SourceLocation EndLoc) {
494 bool IsSimple = (NumOutputs != 0 || NumInputs != 0);
Chad Rosier0731aff2012-08-17 21:19:40 +0000495 MSAsmStmt *NS =
Chad Rosierce2bcbf2012-10-18 15:49:40 +0000496 new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, IsSimple,
497 /*IsVolatile*/ true, AsmToks, NumOutputs, NumInputs,
John McCallf413f5e2013-05-03 00:10:13 +0000498 Constraints, Exprs, AsmString,
499 Clobbers, EndLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +0000500 return NS;
Chad Rosier0731aff2012-08-17 21:19:40 +0000501}