clang API Documentation

Functions
SemaStmt.cpp File Reference
#include "clang/Sema/SemaInternal.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTDiagnostic.h"
#include "clang/AST/CharUnits.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/EvaluatedExprVisitor.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/StmtCXX.h"
#include "clang/AST/StmtObjC.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
Include dependency graph for SemaStmt.cpp:

Go to the source code of this file.

Functions

static bool DiagnoseUnusedComparison (Sema &S, const Expr *E)
 Diagnose unused comparisons, both builtin and overloaded operators. For '==' and '!=', suggest fixits for '=' or '|='.
static bool CmpCaseVals (const std::pair< llvm::APSInt, CaseStmt * > &lhs, const std::pair< llvm::APSInt, CaseStmt * > &rhs)
static bool CmpEnumVals (const std::pair< llvm::APSInt, EnumConstantDecl * > &lhs, const std::pair< llvm::APSInt, EnumConstantDecl * > &rhs)
static bool EqEnumVals (const std::pair< llvm::APSInt, EnumConstantDecl * > &lhs, const std::pair< llvm::APSInt, EnumConstantDecl * > &rhs)
static QualType GetTypeBeforeIntegralPromotion (Expr *&expr)
static void AdjustAPSInt (llvm::APSInt &Val, unsigned BitWidth, bool IsSigned)
static void checkCaseValue (Sema &S, SourceLocation Loc, const llvm::APSInt &Val, unsigned UnpromotedWidth, bool UnpromotedSign)
static bool ShouldDiagnoseSwitchCaseNotInEnum (const ASTContext &Ctx, const EnumDecl *ED, const Expr *CaseExpr)
static bool FinishForRangeVarDecl (Sema &SemaRef, VarDecl *Decl, Expr *Init, SourceLocation Loc, int DiagID)
static bool ObjCEnumerationCollection (Expr *Collection)
static Sema::ForRangeStatus BuildNonArrayForRange (Sema &SemaRef, Scope *S, Expr *BeginRange, Expr *EndRange, QualType RangeType, VarDecl *BeginVar, VarDecl *EndVar, SourceLocation ColonLoc, OverloadCandidateSet *CandidateSet, ExprResult *BeginExpr, ExprResult *EndExpr, Sema::BeginEndFunction *BEF)
 Create the initialization, compare, and increment steps for the range-based for loop expression. This function does not handle array-based for loops, which are created in Sema::BuildCXXForRangeStmt.
static StmtResult RebuildForRangeWithDereference (Sema &SemaRef, Scope *S, SourceLocation ForLoc, Stmt *LoopVarDecl, SourceLocation ColonLoc, Expr *Range, SourceLocation RangeLoc, SourceLocation RParenLoc)
static bool hasDeducedReturnType (FunctionDecl *FD)
 Determine whether the declared return type of the specified function contains 'auto'.
static void buildCapturedStmtCaptureList (SmallVectorImpl< CapturedStmt::Capture > &Captures, SmallVectorImpl< Expr * > &CaptureInits, ArrayRef< CapturingScopeInfo::Capture > Candidates)

Function Documentation

static void AdjustAPSInt ( llvm::APSInt &  Val,
unsigned  BitWidth,
bool  IsSigned 
) [static]
static void buildCapturedStmtCaptureList ( SmallVectorImpl< CapturedStmt::Capture > &  Captures,
SmallVectorImpl< Expr * > &  CaptureInits,
ArrayRef< CapturingScopeInfo::Capture Candidates 
) [static]
static Sema::ForRangeStatus BuildNonArrayForRange ( Sema SemaRef,
Scope S,
Expr BeginRange,
Expr EndRange,
QualType  RangeType,
VarDecl BeginVar,
VarDecl EndVar,
SourceLocation  ColonLoc,
OverloadCandidateSet CandidateSet,
ExprResult BeginExpr,
ExprResult EndExpr,
Sema::BeginEndFunction BEF 
) [static]

Create the initialization, compare, and increment steps for the range-based for loop expression. This function does not handle array-based for loops, which are created in Sema::BuildCXXForRangeStmt.

Returns:
a ForRangeStatus indicating success or what kind of error occurred. BeginExpr and EndExpr are set and FRS_Success is returned on success; CandidateSet and BEF are set and some non-success value is returned on failure.

Definition at line 1959 of file SemaStmt.cpp.

References clang::Sema::BEF_begin, clang::Sema::BEF_end, clang::Sema::BuildForRangeBeginEndCall(), clang::Sema::Diag(), clang::LookupResult::empty(), FinishForRangeVarDecl(), clang::Sema::FRS_DiagnosticIssued, clang::Sema::FRS_Success, clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::IdentifierTable::get(), clang::Type::getAsCXXRecordDecl(), clang::Preprocessor::getIdentifierTable(), clang::Decl::getLocation(), clang::Expr::getType(), clang::Sema::LookupMemberName, clang::Sema::LookupQualifiedName(), and clang::Sema::PP.

Referenced by clang::Sema::BuildCXXForRangeStmt().

static void checkCaseValue ( Sema S,
SourceLocation  Loc,
const llvm::APSInt &  Val,
unsigned  UnpromotedWidth,
bool  UnpromotedSign 
) [static]

Check the specified case value is in range for the given unpromoted switch type.

Definition at line 650 of file SemaStmt.cpp.

References AdjustAPSInt(), and clang::Sema::Diag().

Referenced by clang::Sema::ActOnFinishSwitchStmt().

static bool CmpCaseVals ( const std::pair< llvm::APSInt, CaseStmt * > &  lhs,
const std::pair< llvm::APSInt, CaseStmt * > &  rhs 
) [static]

CmpCaseVals - Comparison predicate for sorting case values.

Definition at line 514 of file SemaStmt.cpp.

Referenced by clang::Sema::ActOnFinishSwitchStmt().

static bool CmpEnumVals ( const std::pair< llvm::APSInt, EnumConstantDecl * > &  lhs,
const std::pair< llvm::APSInt, EnumConstantDecl * > &  rhs 
) [static]

CmpEnumVals - Comparison predicate for sorting enumeration values.

Definition at line 528 of file SemaStmt.cpp.

Referenced by clang::Sema::ActOnFinishSwitchStmt(), and clang::Sema::DiagnoseAssignmentEnum().

static bool DiagnoseUnusedComparison ( Sema S,
const Expr E 
) [static]

Diagnose unused comparisons, both builtin and overloaded operators. For '==' and '!=', suggest fixits for '=' or '|='.

Adding a cast to void (or other expression wrappers) will prevent the warning from firing.

Definition at line 123 of file SemaStmt.cpp.

References clang::BO_NE, clang::FixItHint::CreateReplacement(), clang::Sema::Diag(), clang::Stmt::getSourceRange(), clang::SourceManager::isMacroBodyExpansion(), and clang::Sema::SourceMgr.

Referenced by clang::Sema::DiagnoseUnusedExprResult().

static bool EqEnumVals ( const std::pair< llvm::APSInt, EnumConstantDecl * > &  lhs,
const std::pair< llvm::APSInt, EnumConstantDecl * > &  rhs 
) [static]

EqEnumVals - Comparison preficate for uniqing enumeration values.

Definition at line 536 of file SemaStmt.cpp.

Referenced by clang::Sema::ActOnFinishSwitchStmt(), and clang::Sema::DiagnoseAssignmentEnum().

static bool FinishForRangeVarDecl ( Sema SemaRef,
VarDecl Decl,
Expr Init,
SourceLocation  Loc,
int  DiagID 
) [static]
static QualType GetTypeBeforeIntegralPromotion ( Expr *&  expr) [static]

GetTypeBeforeIntegralPromotion - Returns the pre-promotion type of potentially integral-promoted expression expr.

Definition at line 544 of file SemaStmt.cpp.

References clang::CK_IntegralCast, and clang::Expr::getType().

Referenced by clang::Sema::ActOnFinishSwitchStmt().

static bool hasDeducedReturnType ( FunctionDecl FD) [static]

Determine whether the declared return type of the specified function contains 'auto'.

Definition at line 2576 of file SemaStmt.cpp.

References clang::Type::castAs(), clang::FunctionType::getReturnType(), clang::TypeSourceInfo::getType(), clang::DeclaratorDecl::getTypeSourceInfo(), and clang::Type::isUndeducedType().

Referenced by clang::Sema::ActOnCapScopeReturnStmt().

static bool ObjCEnumerationCollection ( Expr Collection) [static]
static StmtResult RebuildForRangeWithDereference ( Sema SemaRef,
Scope S,
SourceLocation  ForLoc,
Stmt LoopVarDecl,
SourceLocation  ColonLoc,
Expr Range,
SourceLocation  RangeLoc,
SourceLocation  RParenLoc 
) [static]

Speculatively attempt to dereference an invalid range expression. If the attempt fails, this function will return a valid, null StmtResult and emit no diagnostics.

Definition at line 2037 of file SemaStmt.cpp.

References clang::Sema::ActOnCXXForRangeStmt(), clang::Sema::BFRK_Check, clang::Sema::BFRK_Rebuild, clang::Sema::BuildUnaryOp(), clang::FixItHint::CreateInsertion(), clang::Sema::Diag(), clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::Expr::getType(), clang::ActionResult< PtrTy, CompressInvalid >::isInvalid(), and clang::UO_Deref.

Referenced by clang::Sema::BuildCXXForRangeStmt().

static bool ShouldDiagnoseSwitchCaseNotInEnum ( const ASTContext Ctx,
const EnumDecl ED,
const Expr CaseExpr 
) [static]

Returns true if we should emit a diagnostic about this case expression not being a part of the enum used in the switch controlling expression.

Definition at line 670 of file SemaStmt.cpp.

References clang::ASTContext::getTypeDeclType(), clang::ASTContext::hasSameUnqualifiedType(), clang::Expr::IgnoreParenImpCasts(), and clang::QualType::isConstQualified().

Referenced by clang::Sema::ActOnFinishSwitchStmt().