clang 20.0.0git
SemaMSP430.cpp
Go to the documentation of this file.
1//===------ SemaMSP430.cpp ----- MSP430 target-specific routines ----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements semantic analysis functions specific to NVPTX.
10//
11//===----------------------------------------------------------------------===//
12
15#include "clang/AST/Attr.h"
16#include "clang/AST/DeclBase.h"
18#include "clang/Sema/Attr.h"
20
21namespace clang {
22
24
26 // MSP430 'interrupt' attribute is applied to
27 // a function with no parameters and void return type.
29 Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type)
31 return;
32 }
33
35 Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
36 << /*MSP430*/ 1 << 0;
37 return;
38 }
39
40 if (!getFunctionOrMethodResultType(D)->isVoidType()) {
41 Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
42 << /*MSP430*/ 1 << 1;
43 return;
44 }
45
46 // The attribute takes one integer argument.
47 if (!AL.checkExactlyNumArgs(SemaRef, 1))
48 return;
49
50 if (!AL.isArgExpr(0)) {
51 Diag(AL.getLoc(), diag::err_attribute_argument_type)
53 return;
54 }
55
56 Expr *NumParamsExpr = static_cast<Expr *>(AL.getArgAsExpr(0));
57 std::optional<llvm::APSInt> NumParams = llvm::APSInt(32);
58 if (!(NumParams = NumParamsExpr->getIntegerConstantExpr(getASTContext()))) {
59 Diag(AL.getLoc(), diag::err_attribute_argument_type)
61 << NumParamsExpr->getSourceRange();
62 return;
63 }
64 // The argument should be in range 0..63.
65 unsigned Num = NumParams->getLimitedValue(255);
66 if (Num > 63) {
67 Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
68 << AL << (int)NumParams->getSExtValue()
69 << NumParamsExpr->getSourceRange();
70 return;
71 }
72
73 D->addAttr(::new (getASTContext())
74 MSP430InterruptAttr(getASTContext(), AL, Num));
75 D->addAttr(UsedAttr::CreateImplicit(getASTContext()));
76}
77
78} // namespace clang
Defines the clang::ASTContext interface.
const Decl * D
This file declares semantic analysis functions specific to MSP430.
__device__ int
SourceLocation getLoc() const
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
This represents one expression.
Definition: Expr.h:110
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
ParsedAttr - Represents a syntactic attribute.
Definition: ParsedAttr.h:129
bool checkExactlyNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has exactly as many args as Num.
Definition: ParsedAttr.cpp:298
Expr * getArgAsExpr(unsigned Arg) const
Definition: ParsedAttr.h:398
bool isArgExpr(unsigned Arg) const
Definition: ParsedAttr.h:394
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:60
ASTContext & getASTContext() const
Definition: SemaBase.cpp:9
Sema & SemaRef
Definition: SemaBase.h:40
void handleInterruptAttr(Decl *D, const ParsedAttr &AL)
Definition: SemaMSP430.cpp:25
SemaMSP430(Sema &S)
Definition: SemaMSP430.cpp:23
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:535
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:326
The JSON file list parser is used to communicate input to InstallAPI.
@ ExpectedFunctionOrMethod
Definition: ParsedAttr.h:1094
QualType getFunctionOrMethodResultType(const Decl *D)
Definition: Attr.h:98
@ AANT_ArgumentIntegerConstant
Definition: ParsedAttr.h:1081
bool isFuncOrMethodForAttrSubject(const Decl *D)
isFuncOrMethodForAttrSubject - Return true if the given decl has function type (function or function-...
Definition: Attr.h:34
bool hasFunctionProto(const Decl *D)
hasFunctionProto - Return true if the given decl has a argument information.
Definition: Attr.h:55
unsigned getFunctionOrMethodNumParams(const Decl *D)
getFunctionOrMethodNumParams - Return number of function or method parameters.
Definition: Attr.h:64