clang 19.0.0git
Classes | Namespaces | Typedefs | Functions
SemaStmt.cpp File Reference
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTDiagnostic.h"
#include "clang/AST/ASTLambda.h"
#include "clang/AST/CXXInheritance.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/IgnoreExpr.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/StmtCXX.h"
#include "clang/AST/StmtObjC.h"
#include "clang/AST/TypeLoc.h"
#include "clang/AST/TypeOrdering.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/EnterExpressionEvaluationContext.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Ownership.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaCUDA.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/SemaOpenMP.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"

Go to the source code of this file.

Classes

struct  llvm::DenseMapInfo< CatchHandlerType >
 

Namespaces

namespace  llvm
 Diagnostic wrappers for TextAPI types for error reporting.
 

Typedefs

typedef SmallVector< std::pair< llvm::APSInt, EnumConstantDecl * >, 64 > EnumValsTy
 

Functions

static bool DiagnoseUnusedComparison (Sema &S, const Expr *E)
 Diagnose unused comparisons, both builtin and overloaded operators.
 
static bool DiagnoseNoDiscard (Sema &S, const WarnUnusedResultAttr *A, SourceLocation Loc, SourceRange R1, SourceRange R2, bool IsCtor)
 
static bool CmpCaseVals (const std::pair< llvm::APSInt, CaseStmt * > &lhs, const std::pair< llvm::APSInt, CaseStmt * > &rhs)
 CmpCaseVals - Comparison predicate for sorting case values.
 
static bool CmpEnumVals (const std::pair< llvm::APSInt, EnumConstantDecl * > &lhs, const std::pair< llvm::APSInt, EnumConstantDecl * > &rhs)
 CmpEnumVals - Comparison predicate for sorting enumeration values.
 
static bool EqEnumVals (const std::pair< llvm::APSInt, EnumConstantDecl * > &lhs, const std::pair< llvm::APSInt, EnumConstantDecl * > &rhs)
 EqEnumVals - Comparison preficate for uniqing enumeration values.
 
static QualType GetTypeBeforeIntegralPromotion (const Expr *&E)
 GetTypeBeforeIntegralPromotion - Returns the pre-promotion type of potentially integral-promoted expression 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)
 Check the specified case value is in range for the given unpromoted switch type.
 
static bool ShouldDiagnoseSwitchCaseNotInEnum (const Sema &S, const EnumDecl *ED, const Expr *CaseExpr, EnumValsTy::iterator &EI, EnumValsTy::iterator &EIEnd, const llvm::APSInt &Val)
 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.
 
static void checkEnumTypesInSwitchStmt (Sema &S, const Expr *Cond, const Expr *Case)
 
static bool FinishForRangeVarDecl (Sema &SemaRef, VarDecl *Decl, Expr *Init, SourceLocation Loc, int DiagID)
 Finish building a variable declaration for a for-range statement.
 
static bool ObjCEnumerationCollection (Expr *Collection)
 
static Sema::ForRangeStatus BuildNonArrayForRange (Sema &SemaRef, Expr *BeginRange, Expr *EndRange, QualType RangeType, VarDecl *BeginVar, VarDecl *EndVar, SourceLocation ColonLoc, SourceLocation CoawaitLoc, OverloadCandidateSet *CandidateSet, ExprResult *BeginExpr, ExprResult *EndExpr, BeginEndFunction *BEF)
 Create the initialization, compare, and increment steps for the range-based for loop expression.
 
static StmtResult RebuildForRangeWithDereference (Sema &SemaRef, Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, Stmt *LoopVarDecl, SourceLocation ColonLoc, Expr *Range, SourceLocation RangeLoc, SourceLocation RParenLoc)
 Speculatively attempt to dereference an invalid range expression.
 
static void DiagnoseForRangeReferenceVariableCopies (Sema &SemaRef, const VarDecl *VD, QualType RangeInitType)
 
static bool hasTrivialABIAttr (QualType VariableType)
 Determines whether the VariableType's declaration is a record with the clang::trivial_abi attribute.
 
static void DiagnoseForRangeConstVariableCopies (Sema &SemaRef, const VarDecl *VD)
 
static void DiagnoseForRangeVariableCopies (Sema &SemaRef, const CXXForRangeStmt *ForStmt)
 DiagnoseForRangeVariableCopies - Diagnose three cases and fixes for them.
 
static void CheckJumpOutOfSEHFinally (Sema &S, SourceLocation Loc, const Scope &DestScope)
 
static bool VerifyInitializationSequenceCXX98 (const Sema &S, const InitializationSequence &Seq)
 Verify that the initialization sequence that was picked for the first overload resolution is permissible under C++98.
 
static bool hasDeducedReturnType (FunctionDecl *FD)
 Determine whether the declared return type of the specified function contains 'auto'.
 
static bool CheckSimplerImplicitMovesMSVCWorkaround (const Sema &S, const Expr *E)
 
static bool buildCapturedStmtCaptureList (Sema &S, CapturedRegionScopeInfo *RSI, SmallVectorImpl< CapturedStmt::Capture > &Captures, SmallVectorImpl< Expr * > &CaptureInits)
 

Typedef Documentation

◆ EnumValsTy

Definition at line 1182 of file SemaStmt.cpp.

Function Documentation

◆ AdjustAPSInt()

static void AdjustAPSInt ( llvm::APSInt Val,
unsigned  BitWidth,
bool  IsSigned 
)
static

◆ buildCapturedStmtCaptureList()

static bool buildCapturedStmtCaptureList ( Sema S,
CapturedRegionScopeInfo RSI,
SmallVectorImpl< CapturedStmt::Capture > &  Captures,
SmallVectorImpl< Expr * > &  CaptureInits 
)
static

◆ BuildNonArrayForRange()

static Sema::ForRangeStatus BuildNonArrayForRange ( Sema SemaRef,
Expr BeginRange,
Expr EndRange,
QualType  RangeType,
VarDecl BeginVar,
VarDecl EndVar,
SourceLocation  ColonLoc,
SourceLocation  CoawaitLoc,
OverloadCandidateSet CandidateSet,
ExprResult BeginExpr,
ExprResult EndExpr,
BeginEndFunction *  BEF 
)
static

◆ checkCaseValue()

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 1160 of file SemaStmt.cpp.

References AdjustAPSInt(), clang::SemaBase::Diag(), clang::Sema::getLangOpts(), and toString().

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

◆ checkEnumTypesInSwitchStmt()

static void checkEnumTypesInSwitchStmt ( Sema S,
const Expr Cond,
const Expr Case 
)
static

◆ CheckJumpOutOfSEHFinally()

static void CheckJumpOutOfSEHFinally ( Sema S,
SourceLocation  Loc,
const Scope DestScope 
)
static

◆ CheckSimplerImplicitMovesMSVCWorkaround()

static bool CheckSimplerImplicitMovesMSVCWorkaround ( const Sema S,
const Expr E 
)
static

◆ CmpCaseVals()

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 1018 of file SemaStmt.cpp.

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

◆ CmpEnumVals()

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 1031 of file SemaStmt.cpp.

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

◆ DiagnoseForRangeConstVariableCopies()

static void DiagnoseForRangeConstVariableCopies ( Sema SemaRef,
const VarDecl VD 
)
static

◆ DiagnoseForRangeReferenceVariableCopies()

static void DiagnoseForRangeReferenceVariableCopies ( Sema SemaRef,
const VarDecl VD,
QualType  RangeInitType 
)
static

◆ DiagnoseForRangeVariableCopies()

static void DiagnoseForRangeVariableCopies ( Sema SemaRef,
const CXXForRangeStmt ForStmt 
)
static

DiagnoseForRangeVariableCopies - Diagnose three cases and fixes for them.

1) for (const foo &x : foos) where foos only returns a copy. Suggest using "const foo x" to show that a copy is made 2) for (const bar &x : foos) where bar is a temporary initialized by bar. Suggest either "const bar x" to keep the copying or "const foo& x" to prevent the copy. 3) for (const foo x : foos) where x is constructed from a reference foo. Suggest "const foo &x" to prevent the copy.

Definition at line 3262 of file SemaStmt.cpp.

References DiagnoseForRangeConstVariableCopies(), DiagnoseForRangeReferenceVariableCopies(), clang::Sema::Diags, clang::ForStmt::getBeginLoc(), clang::Expr::getExprLoc(), clang::VarDecl::getInit(), clang::ValueDecl::getType(), clang::Sema::inTemplateInstantiation(), clang::QualType::isConstQualified(), clang::DiagnosticsEngine::isIgnored(), clang::Type::isIncompleteType(), clang::SourceLocation::isMacroID(), and clang::Type::isReferenceType().

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

◆ DiagnoseNoDiscard()

static bool DiagnoseNoDiscard ( Sema S,
const WarnUnusedResultAttr *  A,
SourceLocation  Loc,
SourceRange  R1,
SourceRange  R2,
bool  IsCtor 
)
static

Definition at line 205 of file SemaStmt.cpp.

References clang::SemaBase::Diag().

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

◆ DiagnoseUnusedComparison()

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 134 of file SemaStmt.cpp.

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

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

◆ EqEnumVals()

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 1039 of file SemaStmt.cpp.

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

◆ FinishForRangeVarDecl()

static bool FinishForRangeVarDecl ( Sema SemaRef,
VarDecl Decl,
Expr Init,
SourceLocation  Loc,
int  DiagID 
)
static

◆ GetTypeBeforeIntegralPromotion()

static QualType GetTypeBeforeIntegralPromotion ( const Expr *&  E)
static

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

Definition at line 1047 of file SemaStmt.cpp.

References clang::Expr::getType().

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

◆ hasDeducedReturnType()

static bool hasDeducedReturnType ( FunctionDecl FD)
static

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

Definition at line 3640 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().

◆ hasTrivialABIAttr()

static bool hasTrivialABIAttr ( QualType  VariableType)
static

Determines whether the VariableType's declaration is a record with the clang::trivial_abi attribute.

Definition at line 3207 of file SemaStmt.cpp.

References clang::Type::getAsCXXRecordDecl().

Referenced by DiagnoseForRangeConstVariableCopies().

◆ ObjCEnumerationCollection()

static bool ObjCEnumerationCollection ( Expr Collection)
static

◆ RebuildForRangeWithDereference()

static StmtResult RebuildForRangeWithDereference ( Sema SemaRef,
Scope S,
SourceLocation  ForLoc,
SourceLocation  CoawaitLoc,
Stmt InitStmt,
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 2737 of file SemaStmt.cpp.

References clang::Sema::ActOnCXXForRangeStmt(), clang::Sema::BFRK_Check, clang::Sema::BFRK_Rebuild, clang::Sema::BuildUnaryOp(), clang::FixItHint::CreateInsertion(), clang::SemaBase::Diag(), clang::ActionResult< PtrTy, Compress >::get(), and clang::ActionResult< PtrTy, Compress >::isInvalid().

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

◆ ShouldDiagnoseSwitchCaseNotInEnum()

static bool ShouldDiagnoseSwitchCaseNotInEnum ( const Sema S,
const EnumDecl ED,
const Expr CaseExpr,
EnumValsTy::iterator &  EI,
EnumValsTy::iterator &  EIEnd,
const llvm::APSInt Val 
)
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 1186 of file SemaStmt.cpp.

References clang::Sema::Context, clang::ASTContext::getTypeDeclType(), clang::Decl::hasAttr(), clang::ASTContext::hasSameUnqualifiedType(), clang::Expr::IgnoreParenImpCasts(), clang::EnumDecl::isClosed(), clang::QualType::isConstQualified(), and clang::Sema::IsValueInFlagEnum().

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

◆ VerifyInitializationSequenceCXX98()

static bool VerifyInitializationSequenceCXX98 ( const Sema S,
const InitializationSequence Seq 
)
static

Verify that the initialization sequence that was picked for the first overload resolution is permissible under C++98.

Reject (possibly converting) constructors not taking an rvalue reference, or user conversion operators which are not ref-qualified.

Definition at line 3584 of file SemaStmt.cpp.

References clang::FunctionDecl::getParamDecl(), clang::ValueDecl::getType(), clang::Type::isRValueReferenceType(), clang::RQ_None, and clang::Seq.

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