Deleted Added
full compact
SemaStmt.cpp (207619) SemaStmt.cpp (208600)
1//===--- SemaStmt.cpp - Semantic Analysis for Statements ------------------===//
2//
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//===----------------------------------------------------------------------===//

--- 16 unchanged lines hidden (view full) ---

25#include "clang/Basic/TargetInfo.h"
26#include "llvm/ADT/STLExtras.h"
27#include "llvm/ADT/SmallVector.h"
28using namespace clang;
29
30Sema::OwningStmtResult Sema::ActOnExprStmt(FullExprArg expr) {
31 Expr *E = expr->takeAs<Expr>();
32 assert(E && "ActOnExprStmt(): missing expression");
1//===--- SemaStmt.cpp - Semantic Analysis for Statements ------------------===//
2//
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//===----------------------------------------------------------------------===//

--- 16 unchanged lines hidden (view full) ---

25#include "clang/Basic/TargetInfo.h"
26#include "llvm/ADT/STLExtras.h"
27#include "llvm/ADT/SmallVector.h"
28using namespace clang;
29
30Sema::OwningStmtResult Sema::ActOnExprStmt(FullExprArg expr) {
31 Expr *E = expr->takeAs<Expr>();
32 assert(E && "ActOnExprStmt(): missing expression");
33 if (E->getType()->isObjCInterfaceType()) {
33 if (E->getType()->isObjCObjectType()) {
34 if (LangOpts.ObjCNonFragileABI)
35 Diag(E->getLocEnd(), diag::err_indirection_requires_nonfragile_object)
36 << E->getType();
37 else
38 Diag(E->getLocEnd(), diag::err_direct_interface_unsupported)
39 << E->getType();
40 return StmtError();
41 }

--- 233 unchanged lines hidden (view full) ---

275Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, DeclPtrTy CondVar,
276 StmtArg ThenVal, SourceLocation ElseLoc,
277 StmtArg ElseVal) {
278 OwningExprResult CondResult(CondVal.release());
279
280 VarDecl *ConditionVar = 0;
281 if (CondVar.get()) {
282 ConditionVar = CondVar.getAs<VarDecl>();
34 if (LangOpts.ObjCNonFragileABI)
35 Diag(E->getLocEnd(), diag::err_indirection_requires_nonfragile_object)
36 << E->getType();
37 else
38 Diag(E->getLocEnd(), diag::err_direct_interface_unsupported)
39 << E->getType();
40 return StmtError();
41 }

--- 233 unchanged lines hidden (view full) ---

275Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, DeclPtrTy CondVar,
276 StmtArg ThenVal, SourceLocation ElseLoc,
277 StmtArg ElseVal) {
278 OwningExprResult CondResult(CondVal.release());
279
280 VarDecl *ConditionVar = 0;
281 if (CondVar.get()) {
282 ConditionVar = CondVar.getAs<VarDecl>();
283 CondResult = CheckConditionVariable(ConditionVar);
283 CondResult = CheckConditionVariable(ConditionVar, IfLoc, true);
284 if (CondResult.isInvalid())
285 return StmtError();
286 }
287 Expr *ConditionExpr = CondResult.takeAs<Expr>();
288 if (!ConditionExpr)
289 return StmtError();
290
284 if (CondResult.isInvalid())
285 return StmtError();
286 }
287 Expr *ConditionExpr = CondResult.takeAs<Expr>();
288 if (!ConditionExpr)
289 return StmtError();
290
291 if (CheckBooleanCondition(ConditionExpr, IfLoc)) {
292 CondResult = ConditionExpr;
293 return StmtError();
294 }
295
296 Stmt *thenStmt = ThenVal.takeAs<Stmt>();
297 DiagnoseUnusedExprResult(thenStmt);
298
299 // Warn if the if block has a null body without an else value.
300 // this helps prevent bugs due to typos, such as
301 // if (condition);
302 // do_stuff();
303 if (!ElseVal.get()) {

--- 4 unchanged lines hidden (view full) ---

308 Stmt *elseStmt = ElseVal.takeAs<Stmt>();
309 DiagnoseUnusedExprResult(elseStmt);
310
311 CondResult.release();
312 return Owned(new (Context) IfStmt(IfLoc, ConditionVar, ConditionExpr,
313 thenStmt, ElseLoc, elseStmt));
314}
315
291 Stmt *thenStmt = ThenVal.takeAs<Stmt>();
292 DiagnoseUnusedExprResult(thenStmt);
293
294 // Warn if the if block has a null body without an else value.
295 // this helps prevent bugs due to typos, such as
296 // if (condition);
297 // do_stuff();
298 if (!ElseVal.get()) {

--- 4 unchanged lines hidden (view full) ---

303 Stmt *elseStmt = ElseVal.takeAs<Stmt>();
304 DiagnoseUnusedExprResult(elseStmt);
305
306 CondResult.release();
307 return Owned(new (Context) IfStmt(IfLoc, ConditionVar, ConditionExpr,
308 thenStmt, ElseLoc, elseStmt));
309}
310
316Action::OwningStmtResult
317Sema::ActOnStartOfSwitchStmt(FullExprArg cond, DeclPtrTy CondVar) {
318 OwningExprResult CondResult(cond.release());
319
320 VarDecl *ConditionVar = 0;
321 if (CondVar.get()) {
322 ConditionVar = CondVar.getAs<VarDecl>();
323 CondResult = CheckConditionVariable(ConditionVar);
324 if (CondResult.isInvalid())
325 return StmtError();
326 }
327 SwitchStmt *SS = new (Context) SwitchStmt(ConditionVar,
328 CondResult.takeAs<Expr>());
329 getSwitchStack().push_back(SS);
330 return Owned(SS);
331}
332
333/// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
334/// the specified width and sign. If an overflow occurs, detect it and emit
335/// the specified diagnostic.
336void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val,
337 unsigned NewWidth, bool NewSign,
338 SourceLocation Loc,
339 unsigned DiagID) {
340 // Perform a conversion to the promoted condition type if needed.

--- 194 unchanged lines hidden (view full) ---

535 }
536 return true;
537 }
538 }
539
540 return false;
541}
542
311/// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
312/// the specified width and sign. If an overflow occurs, detect it and emit
313/// the specified diagnostic.
314void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val,
315 unsigned NewWidth, bool NewSign,
316 SourceLocation Loc,
317 unsigned DiagID) {
318 // Perform a conversion to the promoted condition type if needed.

--- 194 unchanged lines hidden (view full) ---

513 }
514 return true;
515 }
516 }
517
518 return false;
519}
520
543/// ActOnSwitchBodyError - This is called if there is an error parsing the
544/// body of the switch stmt instead of ActOnFinishSwitchStmt.
545void Sema::ActOnSwitchBodyError(SourceLocation SwitchLoc, StmtArg Switch,
546 StmtArg Body) {
547 // Keep the switch stack balanced.
548 assert(getSwitchStack().back() == (SwitchStmt*)Switch.get() &&
549 "switch stack missing push/pop!");
550 getSwitchStack().pop_back();
521Action::OwningStmtResult
522Sema::ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, ExprArg Cond,
523 DeclPtrTy CondVar) {
524 VarDecl *ConditionVar = 0;
525 if (CondVar.get()) {
526 ConditionVar = CondVar.getAs<VarDecl>();
527 OwningExprResult CondE = CheckConditionVariable(ConditionVar, SourceLocation(), false);
528 if (CondE.isInvalid())
529 return StmtError();
530
531 Cond = move(CondE);
532 }
533
534 Expr *CondExpr = Cond.takeAs<Expr>();
535 if (!CondExpr)
536 return StmtError();
537
538 if (getLangOptions().CPlusPlus &&
539 CheckCXXSwitchCondition(*this, SwitchLoc, CondExpr))
540 return StmtError();
541
542 if (!CondVar.get()) {
543 CondExpr = MaybeCreateCXXExprWithTemporaries(CondExpr);
544 if (!CondExpr)
545 return StmtError();
546 }
547
548 SwitchStmt *SS = new (Context) SwitchStmt(ConditionVar, CondExpr);
549 getSwitchStack().push_back(SS);
550 return Owned(SS);
551}
552
553Action::OwningStmtResult
554Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch,
555 StmtArg Body) {
556 Stmt *BodyStmt = Body.takeAs<Stmt>();
557
558 SwitchStmt *SS = getSwitchStack().back();
559 assert(SS == (SwitchStmt*)Switch.get() && "switch stack missing push/pop!");
560
561 SS->setBody(BodyStmt, SwitchLoc);
562 getSwitchStack().pop_back();
563
564 if (SS->getCond() == 0) {
565 SS->Destroy(Context);
566 return StmtError();
567 }
568
569 Expr *CondExpr = SS->getCond();
551}
552
553Action::OwningStmtResult
554Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch,
555 StmtArg Body) {
556 Stmt *BodyStmt = Body.takeAs<Stmt>();
557
558 SwitchStmt *SS = getSwitchStack().back();
559 assert(SS == (SwitchStmt*)Switch.get() && "switch stack missing push/pop!");
560
561 SS->setBody(BodyStmt, SwitchLoc);
562 getSwitchStack().pop_back();
563
564 if (SS->getCond() == 0) {
565 SS->Destroy(Context);
566 return StmtError();
567 }
568
569 Expr *CondExpr = SS->getCond();
570 Expr *CondExprBeforePromotion = CondExpr;
570 QualType CondTypeBeforePromotion =
571 GetTypeBeforeIntegralPromotion(CondExpr);
572
571 QualType CondTypeBeforePromotion =
572 GetTypeBeforeIntegralPromotion(CondExpr);
573
573 if (getLangOptions().CPlusPlus &&
574 CheckCXXSwitchCondition(*this, SwitchLoc, CondExpr))
575 return StmtError();
576
577 // C99 6.8.4.2p5 - Integer promotions are performed on the controlling expr.
578 UsualUnaryConversions(CondExpr);
579 QualType CondType = CondExpr->getType();
580 SS->setCond(CondExpr);
581
582 // C++ 6.4.2.p2:
583 // Integral promotions are performed (on the switch condition).
584 //

--- 89 unchanged lines hidden (view full) ---

674 }
675 CaseRanges.push_back(std::make_pair(LoVal, CS));
676 } else
677 CaseVals.push_back(std::make_pair(LoVal, CS));
678 }
679 }
680
681 if (!HasDependentValue) {
574 // C99 6.8.4.2p5 - Integer promotions are performed on the controlling expr.
575 UsualUnaryConversions(CondExpr);
576 QualType CondType = CondExpr->getType();
577 SS->setCond(CondExpr);
578
579 // C++ 6.4.2.p2:
580 // Integral promotions are performed (on the switch condition).
581 //

--- 89 unchanged lines hidden (view full) ---

671 }
672 CaseRanges.push_back(std::make_pair(LoVal, CS));
673 } else
674 CaseVals.push_back(std::make_pair(LoVal, CS));
675 }
676 }
677
678 if (!HasDependentValue) {
679 // If we don't have a default statement, check whether the
680 // condition is constant.
681 llvm::APSInt ConstantCondValue;
682 bool HasConstantCond = false;
683 bool ShouldCheckConstantCond = false;
684 if (!HasDependentValue && !TheDefaultStmt) {
685 Expr::EvalResult Result;
686 HasConstantCond = CondExprBeforePromotion->Evaluate(Result, Context);
687 if (HasConstantCond) {
688 assert(Result.Val.isInt() && "switch condition evaluated to non-int");
689 ConstantCondValue = Result.Val.getInt();
690 ShouldCheckConstantCond = true;
691
692 assert(ConstantCondValue.getBitWidth() == CondWidth &&
693 ConstantCondValue.isSigned() == CondIsSigned);
694 }
695 }
696
682 // Sort all the scalar case values so we can easily detect duplicates.
683 std::stable_sort(CaseVals.begin(), CaseVals.end(), CmpCaseVals);
684
685 if (!CaseVals.empty()) {
697 // Sort all the scalar case values so we can easily detect duplicates.
698 std::stable_sort(CaseVals.begin(), CaseVals.end(), CmpCaseVals);
699
700 if (!CaseVals.empty()) {
686 for (unsigned i = 0, e = CaseVals.size()-1; i != e; ++i) {
687 if (CaseVals[i].first == CaseVals[i+1].first) {
701 for (unsigned i = 0, e = CaseVals.size(); i != e; ++i) {
702 if (ShouldCheckConstantCond &&
703 CaseVals[i].first == ConstantCondValue)
704 ShouldCheckConstantCond = false;
705
706 if (i != 0 && CaseVals[i].first == CaseVals[i-1].first) {
688 // If we have a duplicate, report it.
707 // If we have a duplicate, report it.
689 Diag(CaseVals[i+1].second->getLHS()->getLocStart(),
690 diag::err_duplicate_case) << CaseVals[i].first.toString(10);
691 Diag(CaseVals[i].second->getLHS()->getLocStart(),
708 Diag(CaseVals[i].second->getLHS()->getLocStart(),
709 diag::err_duplicate_case) << CaseVals[i].first.toString(10);
710 Diag(CaseVals[i-1].second->getLHS()->getLocStart(),
692 diag::note_duplicate_case_prev);
693 // FIXME: We really want to remove the bogus case stmt from the
694 // substmt, but we have no way to do this right now.
695 CaseListIsErroneous = true;
696 }
697 }
698 }
699
700 // Detect duplicate case ranges, which usually don't exist at all in
701 // the first place.
702 if (!CaseRanges.empty()) {
703 // Sort all the case ranges by their low value so we can easily detect
704 // overlaps between ranges.
705 std::stable_sort(CaseRanges.begin(), CaseRanges.end());
706
707 // Scan the ranges, computing the high values and removing empty ranges.
708 std::vector<llvm::APSInt> HiVals;
709 for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
711 diag::note_duplicate_case_prev);
712 // FIXME: We really want to remove the bogus case stmt from the
713 // substmt, but we have no way to do this right now.
714 CaseListIsErroneous = true;
715 }
716 }
717 }
718
719 // Detect duplicate case ranges, which usually don't exist at all in
720 // the first place.
721 if (!CaseRanges.empty()) {
722 // Sort all the case ranges by their low value so we can easily detect
723 // overlaps between ranges.
724 std::stable_sort(CaseRanges.begin(), CaseRanges.end());
725
726 // Scan the ranges, computing the high values and removing empty ranges.
727 std::vector<llvm::APSInt> HiVals;
728 for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
729 llvm::APSInt &LoVal = CaseRanges[i].first;
710 CaseStmt *CR = CaseRanges[i].second;
711 Expr *Hi = CR->getRHS();
712 llvm::APSInt HiVal = Hi->EvaluateAsInt(Context);
713
714 // Convert the value to the same width/sign as the condition.
715 ConvertIntegerToTypeWarnOnOverflow(HiVal, CondWidth, CondIsSigned,
716 CR->getRHS()->getLocStart(),
717 diag::warn_case_value_overflow);
718
719 // If the LHS is not the same type as the condition, insert an implicit
720 // cast.
721 ImpCastExprToType(Hi, CondType, CastExpr::CK_IntegralCast);
722 CR->setRHS(Hi);
723
724 // If the low value is bigger than the high value, the case is empty.
730 CaseStmt *CR = CaseRanges[i].second;
731 Expr *Hi = CR->getRHS();
732 llvm::APSInt HiVal = Hi->EvaluateAsInt(Context);
733
734 // Convert the value to the same width/sign as the condition.
735 ConvertIntegerToTypeWarnOnOverflow(HiVal, CondWidth, CondIsSigned,
736 CR->getRHS()->getLocStart(),
737 diag::warn_case_value_overflow);
738
739 // If the LHS is not the same type as the condition, insert an implicit
740 // cast.
741 ImpCastExprToType(Hi, CondType, CastExpr::CK_IntegralCast);
742 CR->setRHS(Hi);
743
744 // If the low value is bigger than the high value, the case is empty.
725 if (CaseRanges[i].first > HiVal) {
745 if (LoVal > HiVal) {
726 Diag(CR->getLHS()->getLocStart(), diag::warn_case_empty_range)
727 << SourceRange(CR->getLHS()->getLocStart(),
728 CR->getRHS()->getLocEnd());
729 CaseRanges.erase(CaseRanges.begin()+i);
730 --i, --e;
731 continue;
732 }
746 Diag(CR->getLHS()->getLocStart(), diag::warn_case_empty_range)
747 << SourceRange(CR->getLHS()->getLocStart(),
748 CR->getRHS()->getLocEnd());
749 CaseRanges.erase(CaseRanges.begin()+i);
750 --i, --e;
751 continue;
752 }
753
754 if (ShouldCheckConstantCond &&
755 LoVal <= ConstantCondValue &&
756 ConstantCondValue <= HiVal)
757 ShouldCheckConstantCond = false;
758
733 HiVals.push_back(HiVal);
734 }
735
736 // Rescan the ranges, looking for overlap with singleton values and other
737 // ranges. Since the range list is sorted, we only need to compare case
738 // ranges with their neighbors.
739 for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
740 llvm::APSInt &CRLo = CaseRanges[i].first;

--- 37 unchanged lines hidden (view full) ---

778 diag::note_duplicate_case_prev);
779 // FIXME: We really want to remove the bogus case stmt from the
780 // substmt, but we have no way to do this right now.
781 CaseListIsErroneous = true;
782 }
783 }
784 }
785
759 HiVals.push_back(HiVal);
760 }
761
762 // Rescan the ranges, looking for overlap with singleton values and other
763 // ranges. Since the range list is sorted, we only need to compare case
764 // ranges with their neighbors.
765 for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
766 llvm::APSInt &CRLo = CaseRanges[i].first;

--- 37 unchanged lines hidden (view full) ---

804 diag::note_duplicate_case_prev);
805 // FIXME: We really want to remove the bogus case stmt from the
806 // substmt, but we have no way to do this right now.
807 CaseListIsErroneous = true;
808 }
809 }
810 }
811
786 // Check to see if switch is over an Enum and handles all of its
787 // values
812 // Complain if we have a constant condition and we didn't find a match.
813 if (!CaseListIsErroneous && ShouldCheckConstantCond) {
814 // TODO: it would be nice if we printed enums as enums, chars as
815 // chars, etc.
816 Diag(CondExpr->getExprLoc(), diag::warn_missing_case_for_condition)
817 << ConstantCondValue.toString(10)
818 << CondExpr->getSourceRange();
819 }
820
821 // Check to see if switch is over an Enum and handles all of its
822 // values. We don't need to do this if there's a default
823 // statement or if we have a constant condition.
824 //
825 // TODO: we might want to check whether case values are out of the
826 // enum even if we don't want to check whether all cases are handled.
788 const EnumType* ET = CondTypeBeforePromotion->getAs<EnumType>();
789 // If switch has default case, then ignore it.
827 const EnumType* ET = CondTypeBeforePromotion->getAs<EnumType>();
828 // If switch has default case, then ignore it.
790 if (!CaseListIsErroneous && !TheDefaultStmt && ET) {
829 if (!CaseListIsErroneous && !TheDefaultStmt && !HasConstantCond && ET) {
791 const EnumDecl *ED = ET->getDecl();
792 typedef llvm::SmallVector<std::pair<llvm::APSInt, EnumConstantDecl*>, 64> EnumValsTy;
793 EnumValsTy EnumVals;
794
830 const EnumDecl *ED = ET->getDecl();
831 typedef llvm::SmallVector<std::pair<llvm::APSInt, EnumConstantDecl*>, 64> EnumValsTy;
832 EnumValsTy EnumVals;
833
795 // Gather all enum values, set their type and sort them, allowing easier comparison
796 // with CaseVals.
797 for (EnumDecl::enumerator_iterator EDI = ED->enumerator_begin(); EDI != ED->enumerator_end(); EDI++) {
834 // Gather all enum values, set their type and sort them,
835 // allowing easier comparison with CaseVals.
836 for (EnumDecl::enumerator_iterator EDI = ED->enumerator_begin();
837 EDI != ED->enumerator_end(); EDI++) {
798 llvm::APSInt Val = (*EDI)->getInitVal();
799 if(Val.getBitWidth() < CondWidth)
800 Val.extend(CondWidth);
801 Val.setIsSigned(CondIsSigned);
802 EnumVals.push_back(std::make_pair(Val, (*EDI)));
803 }
804 std::stable_sort(EnumVals.begin(), EnumVals.end(), CmpEnumVals);
838 llvm::APSInt Val = (*EDI)->getInitVal();
839 if(Val.getBitWidth() < CondWidth)
840 Val.extend(CondWidth);
841 Val.setIsSigned(CondIsSigned);
842 EnumVals.push_back(std::make_pair(Val, (*EDI)));
843 }
844 std::stable_sort(EnumVals.begin(), EnumVals.end(), CmpEnumVals);
805 EnumValsTy::iterator EIend = std::unique(EnumVals.begin(), EnumVals.end(), EqEnumVals);
845 EnumValsTy::iterator EIend =
846 std::unique(EnumVals.begin(), EnumVals.end(), EqEnumVals);
806 // See which case values aren't in enum
807 EnumValsTy::const_iterator EI = EnumVals.begin();
847 // See which case values aren't in enum
848 EnumValsTy::const_iterator EI = EnumVals.begin();
808 for (CaseValsTy::const_iterator CI = CaseVals.begin(); CI != CaseVals.end(); CI++) {
849 for (CaseValsTy::const_iterator CI = CaseVals.begin();
850 CI != CaseVals.end(); CI++) {
809 while (EI != EIend && EI->first < CI->first)
810 EI++;
811 if (EI == EIend || EI->first > CI->first)
851 while (EI != EIend && EI->first < CI->first)
852 EI++;
853 if (EI == EIend || EI->first > CI->first)
812 Diag(CI->second->getLHS()->getExprLoc(), diag::not_in_enum) << ED->getDeclName();
854 Diag(CI->second->getLHS()->getExprLoc(), diag::warn_not_in_enum)
855 << ED->getDeclName();
813 }
814 // See which of case ranges aren't in enum
815 EI = EnumVals.begin();
856 }
857 // See which of case ranges aren't in enum
858 EI = EnumVals.begin();
816 for (CaseRangesTy::const_iterator RI = CaseRanges.begin(); RI != CaseRanges.end() && EI != EIend; RI++) {
859 for (CaseRangesTy::const_iterator RI = CaseRanges.begin();
860 RI != CaseRanges.end() && EI != EIend; RI++) {
817 while (EI != EIend && EI->first < RI->first)
818 EI++;
819
820 if (EI == EIend || EI->first != RI->first) {
861 while (EI != EIend && EI->first < RI->first)
862 EI++;
863
864 if (EI == EIend || EI->first != RI->first) {
821 Diag(RI->second->getLHS()->getExprLoc(), diag::not_in_enum) << ED->getDeclName();
865 Diag(RI->second->getLHS()->getExprLoc(), diag::warn_not_in_enum)
866 << ED->getDeclName();
822 }
823
824 llvm::APSInt Hi = RI->second->getRHS()->EvaluateAsInt(Context);
825 while (EI != EIend && EI->first < Hi)
826 EI++;
827 if (EI == EIend || EI->first != Hi)
867 }
868
869 llvm::APSInt Hi = RI->second->getRHS()->EvaluateAsInt(Context);
870 while (EI != EIend && EI->first < Hi)
871 EI++;
872 if (EI == EIend || EI->first != Hi)
828 Diag(RI->second->getRHS()->getExprLoc(), diag::not_in_enum) << ED->getDeclName();
873 Diag(RI->second->getRHS()->getExprLoc(), diag::warn_not_in_enum)
874 << ED->getDeclName();
829 }
830 //Check which enum vals aren't in switch
831 CaseValsTy::const_iterator CI = CaseVals.begin();
832 CaseRangesTy::const_iterator RI = CaseRanges.begin();
833 EI = EnumVals.begin();
834 for (; EI != EIend; EI++) {
835 //Drop unneeded case values
836 llvm::APSInt CIVal;

--- 6 unchanged lines hidden (view full) ---

843 //Drop unneeded case ranges
844 for (; RI != CaseRanges.end(); RI++) {
845 llvm::APSInt Hi = RI->second->getRHS()->EvaluateAsInt(Context);
846 if (EI->first <= Hi)
847 break;
848 }
849
850 if (RI == CaseRanges.end() || EI->first < RI->first)
875 }
876 //Check which enum vals aren't in switch
877 CaseValsTy::const_iterator CI = CaseVals.begin();
878 CaseRangesTy::const_iterator RI = CaseRanges.begin();
879 EI = EnumVals.begin();
880 for (; EI != EIend; EI++) {
881 //Drop unneeded case values
882 llvm::APSInt CIVal;

--- 6 unchanged lines hidden (view full) ---

889 //Drop unneeded case ranges
890 for (; RI != CaseRanges.end(); RI++) {
891 llvm::APSInt Hi = RI->second->getRHS()->EvaluateAsInt(Context);
892 if (EI->first <= Hi)
893 break;
894 }
895
896 if (RI == CaseRanges.end() || EI->first < RI->first)
851 Diag(CondExpr->getExprLoc(), diag::warn_missing_cases) << EI->second->getDeclName();
897 Diag(CondExpr->getExprLoc(), diag::warn_missing_cases)
898 << EI->second->getDeclName();
852 }
853 }
854 }
855
856 // FIXME: If the case list was broken is some way, we don't have a good system
857 // to patch it up. Instead, just return the whole substmt as broken.
858 if (CaseListIsErroneous)
859 return StmtError();

--- 5 unchanged lines hidden (view full) ---

865Action::OwningStmtResult
866Sema::ActOnWhileStmt(SourceLocation WhileLoc, FullExprArg Cond,
867 DeclPtrTy CondVar, StmtArg Body) {
868 OwningExprResult CondResult(Cond.release());
869
870 VarDecl *ConditionVar = 0;
871 if (CondVar.get()) {
872 ConditionVar = CondVar.getAs<VarDecl>();
899 }
900 }
901 }
902
903 // FIXME: If the case list was broken is some way, we don't have a good system
904 // to patch it up. Instead, just return the whole substmt as broken.
905 if (CaseListIsErroneous)
906 return StmtError();

--- 5 unchanged lines hidden (view full) ---

912Action::OwningStmtResult
913Sema::ActOnWhileStmt(SourceLocation WhileLoc, FullExprArg Cond,
914 DeclPtrTy CondVar, StmtArg Body) {
915 OwningExprResult CondResult(Cond.release());
916
917 VarDecl *ConditionVar = 0;
918 if (CondVar.get()) {
919 ConditionVar = CondVar.getAs<VarDecl>();
873 CondResult = CheckConditionVariable(ConditionVar);
920 CondResult = CheckConditionVariable(ConditionVar, WhileLoc, true);
874 if (CondResult.isInvalid())
875 return StmtError();
876 }
877 Expr *ConditionExpr = CondResult.takeAs<Expr>();
878 if (!ConditionExpr)
879 return StmtError();
880
921 if (CondResult.isInvalid())
922 return StmtError();
923 }
924 Expr *ConditionExpr = CondResult.takeAs<Expr>();
925 if (!ConditionExpr)
926 return StmtError();
927
881 if (CheckBooleanCondition(ConditionExpr, WhileLoc)) {
882 CondResult = ConditionExpr;
883 return StmtError();
884 }
885
886 Stmt *bodyStmt = Body.takeAs<Stmt>();
887 DiagnoseUnusedExprResult(bodyStmt);
888
889 CondResult.release();
890 return Owned(new (Context) WhileStmt(ConditionVar, ConditionExpr, bodyStmt,
891 WhileLoc));
892}
893

--- 4 unchanged lines hidden (view full) ---

898 Expr *condExpr = Cond.takeAs<Expr>();
899 assert(condExpr && "ActOnDoStmt(): missing expression");
900
901 if (CheckBooleanCondition(condExpr, DoLoc)) {
902 Cond = condExpr;
903 return StmtError();
904 }
905
928 Stmt *bodyStmt = Body.takeAs<Stmt>();
929 DiagnoseUnusedExprResult(bodyStmt);
930
931 CondResult.release();
932 return Owned(new (Context) WhileStmt(ConditionVar, ConditionExpr, bodyStmt,
933 WhileLoc));
934}
935

--- 4 unchanged lines hidden (view full) ---

940 Expr *condExpr = Cond.takeAs<Expr>();
941 assert(condExpr && "ActOnDoStmt(): missing expression");
942
943 if (CheckBooleanCondition(condExpr, DoLoc)) {
944 Cond = condExpr;
945 return StmtError();
946 }
947
948 condExpr = MaybeCreateCXXExprWithTemporaries(condExpr);
949 if (!condExpr)
950 return StmtError();
951
906 Stmt *bodyStmt = Body.takeAs<Stmt>();
907 DiagnoseUnusedExprResult(bodyStmt);
908
909 Cond.release();
910 return Owned(new (Context) DoStmt(bodyStmt, condExpr, DoLoc,
911 WhileLoc, CondRParen));
912}
913

--- 20 unchanged lines hidden (view full) ---

934 }
935 }
936 }
937
938 OwningExprResult SecondResult(second.release());
939 VarDecl *ConditionVar = 0;
940 if (secondVar.get()) {
941 ConditionVar = secondVar.getAs<VarDecl>();
952 Stmt *bodyStmt = Body.takeAs<Stmt>();
953 DiagnoseUnusedExprResult(bodyStmt);
954
955 Cond.release();
956 return Owned(new (Context) DoStmt(bodyStmt, condExpr, DoLoc,
957 WhileLoc, CondRParen));
958}
959

--- 20 unchanged lines hidden (view full) ---

980 }
981 }
982 }
983
984 OwningExprResult SecondResult(second.release());
985 VarDecl *ConditionVar = 0;
986 if (secondVar.get()) {
987 ConditionVar = secondVar.getAs<VarDecl>();
942 SecondResult = CheckConditionVariable(ConditionVar);
988 SecondResult = CheckConditionVariable(ConditionVar, ForLoc, true);
943 if (SecondResult.isInvalid())
944 return StmtError();
945 }
946
989 if (SecondResult.isInvalid())
990 return StmtError();
991 }
992
947 Expr *Second = SecondResult.takeAs<Expr>();
948 if (Second && CheckBooleanCondition(Second, ForLoc)) {
949 SecondResult = Second;
950 return StmtError();
951 }
952
953 Expr *Third = third.release().takeAs<Expr>();
954 Stmt *Body = static_cast<Stmt*>(body.get());
955
956 DiagnoseUnusedExprResult(First);
957 DiagnoseUnusedExprResult(Third);
958 DiagnoseUnusedExprResult(Body);
959
960 first.release();
961 body.release();
993 Expr *Third = third.release().takeAs<Expr>();
994 Stmt *Body = static_cast<Stmt*>(body.get());
995
996 DiagnoseUnusedExprResult(First);
997 DiagnoseUnusedExprResult(Third);
998 DiagnoseUnusedExprResult(Body);
999
1000 first.release();
1001 body.release();
962 return Owned(new (Context) ForStmt(First, Second, ConditionVar, Third, Body,
1002 return Owned(new (Context) ForStmt(First, SecondResult.takeAs<Expr>(),
1003 ConditionVar, Third, Body,
963 ForLoc, LParenLoc, RParenLoc));
964}
965
966Action::OwningStmtResult
967Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
968 SourceLocation LParenLoc,
969 StmtArg first, ExprArg second,
970 SourceLocation RParenLoc, StmtArg body) {

--- 92 unchanged lines hidden (view full) ---

1063 if (!S) {
1064 // C99 6.8.6.3p1: A break shall appear only in or as a switch/loop body.
1065 return StmtError(Diag(BreakLoc, diag::err_break_not_in_loop_or_switch));
1066 }
1067
1068 return Owned(new (Context) BreakStmt(BreakLoc));
1069}
1070
1004 ForLoc, LParenLoc, RParenLoc));
1005}
1006
1007Action::OwningStmtResult
1008Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
1009 SourceLocation LParenLoc,
1010 StmtArg first, ExprArg second,
1011 SourceLocation RParenLoc, StmtArg body) {

--- 92 unchanged lines hidden (view full) ---

1104 if (!S) {
1105 // C99 6.8.6.3p1: A break shall appear only in or as a switch/loop body.
1106 return StmtError(Diag(BreakLoc, diag::err_break_not_in_loop_or_switch));
1107 }
1108
1109 return Owned(new (Context) BreakStmt(BreakLoc));
1110}
1111
1112/// \brief Determine whether a return statement is a candidate for the named
1113/// return value optimization (C++0x 12.8p34, bullet 1).
1114///
1115/// \param Ctx The context in which the return expression and type occur.
1116///
1117/// \param RetType The return type of the function or block.
1118///
1119/// \param RetExpr The expression being returned from the function or block.
1120///
1121/// \returns The NRVO candidate variable, if the return statement may use the
1122/// NRVO, or NULL if there is no such candidate.
1123static const VarDecl *getNRVOCandidate(ASTContext &Ctx, QualType RetType,
1124 Expr *RetExpr) {
1125 QualType ExprType = RetExpr->getType();
1126 // - in a return statement in a function with ...
1127 // ... a class return type ...
1128 if (!RetType->isRecordType())
1129 return 0;
1130 // ... the same cv-unqualified type as the function return type ...
1131 if (!Ctx.hasSameUnqualifiedType(RetType, ExprType))
1132 return 0;
1133 // ... the expression is the name of a non-volatile automatic object ...
1134 // We ignore parentheses here.
1135 // FIXME: Is this compliant? (Everyone else does it)
1136 const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(RetExpr->IgnoreParens());
1137 if (!DR)
1138 return 0;
1139 const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl());
1140 if (!VD)
1141 return 0;
1142
1143 if (VD->getKind() == Decl::Var && VD->hasLocalStorage() &&
1144 !VD->getType()->isReferenceType() && !VD->hasAttr<BlocksAttr>() &&
1145 !VD->getType().isVolatileQualified())
1146 return VD;
1147
1148 return 0;
1149}
1150
1071/// ActOnBlockReturnStmt - Utility routine to figure out block's return type.
1072///
1073Action::OwningStmtResult
1074Sema::ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) {
1075 // If this is the first return we've seen in the block, infer the type of
1076 // the block from it.
1077 BlockScopeInfo *CurBlock = getCurBlock();
1078 if (CurBlock->ReturnType.isNull()) {

--- 18 unchanged lines hidden (view full) ---

1097 Diag(ReturnLoc, diag::err_noreturn_block_has_return_expr)
1098 << getCurFunctionOrMethodDecl()->getDeclName();
1099 return StmtError();
1100 }
1101
1102 // Otherwise, verify that this result type matches the previous one. We are
1103 // pickier with blocks than for normal functions because we don't have GCC
1104 // compatibility to worry about here.
1151/// ActOnBlockReturnStmt - Utility routine to figure out block's return type.
1152///
1153Action::OwningStmtResult
1154Sema::ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) {
1155 // If this is the first return we've seen in the block, infer the type of
1156 // the block from it.
1157 BlockScopeInfo *CurBlock = getCurBlock();
1158 if (CurBlock->ReturnType.isNull()) {

--- 18 unchanged lines hidden (view full) ---

1177 Diag(ReturnLoc, diag::err_noreturn_block_has_return_expr)
1178 << getCurFunctionOrMethodDecl()->getDeclName();
1179 return StmtError();
1180 }
1181
1182 // Otherwise, verify that this result type matches the previous one. We are
1183 // pickier with blocks than for normal functions because we don't have GCC
1184 // compatibility to worry about here.
1185 ReturnStmt *Result = 0;
1105 if (CurBlock->ReturnType->isVoidType()) {
1106 if (RetValExp) {
1107 Diag(ReturnLoc, diag::err_return_block_has_expr);
1108 RetValExp->Destroy(Context);
1109 RetValExp = 0;
1110 }
1186 if (CurBlock->ReturnType->isVoidType()) {
1187 if (RetValExp) {
1188 Diag(ReturnLoc, diag::err_return_block_has_expr);
1189 RetValExp->Destroy(Context);
1190 RetValExp = 0;
1191 }
1111 return Owned(new (Context) ReturnStmt(ReturnLoc, RetValExp));
1112 }
1113
1114 if (!RetValExp)
1192 Result = new (Context) ReturnStmt(ReturnLoc, RetValExp, 0);
1193 } else if (!RetValExp) {
1115 return StmtError(Diag(ReturnLoc, diag::err_block_return_missing_expr));
1194 return StmtError(Diag(ReturnLoc, diag::err_block_return_missing_expr));
1195 } else {
1196 const VarDecl *NRVOCandidate = 0;
1197
1198 if (!FnRetType->isDependentType() && !RetValExp->isTypeDependent()) {
1199 // we have a non-void block with an expression, continue checking
1116
1200
1117 if (!FnRetType->isDependentType() && !RetValExp->isTypeDependent()) {
1118 // we have a non-void block with an expression, continue checking
1201 // C99 6.8.6.4p3(136): The return statement is not an assignment. The
1202 // overlap restriction of subclause 6.5.16.1 does not apply to the case of
1203 // function return.
1119
1204
1120 // C99 6.8.6.4p3(136): The return statement is not an assignment. The
1121 // overlap restriction of subclause 6.5.16.1 does not apply to the case of
1122 // function return.
1205 // In C++ the return statement is handled via a copy initialization.
1206 // the C version of which boils down to CheckSingleAssignmentConstraints.
1207 NRVOCandidate = getNRVOCandidate(Context, FnRetType, RetValExp);
1208 OwningExprResult Res = PerformCopyInitialization(
1209 InitializedEntity::InitializeResult(ReturnLoc,
1210 FnRetType,
1211 NRVOCandidate != 0),
1212 SourceLocation(),
1213 Owned(RetValExp));
1214 if (Res.isInvalid()) {
1215 // FIXME: Cleanup temporaries here, anyway?
1216 return StmtError();
1217 }
1218
1219 if (RetValExp)
1220 RetValExp = MaybeCreateCXXExprWithTemporaries(RetValExp);
1123
1221
1124 // In C++ the return statement is handled via a copy initialization.
1125 // the C version of which boils down to CheckSingleAssignmentConstraints.
1126 OwningExprResult Res = PerformCopyInitialization(
1127 InitializedEntity::InitializeResult(ReturnLoc,
1128 FnRetType),
1129 SourceLocation(),
1130 Owned(RetValExp));
1131 if (Res.isInvalid()) {
1132 // FIXME: Cleanup temporaries here, anyway?
1133 return StmtError();
1222 RetValExp = Res.takeAs<Expr>();
1223 if (RetValExp)
1224 CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc);
1134 }
1135
1225 }
1226
1136 RetValExp = Res.takeAs<Expr>();
1137 if (RetValExp)
1138 CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc);
1227 Result = new (Context) ReturnStmt(ReturnLoc, RetValExp, NRVOCandidate);
1139 }
1140
1228 }
1229
1141 return Owned(new (Context) ReturnStmt(ReturnLoc, RetValExp));
1230 // If we need to check for the named return value optimization, save the
1231 // return statement in our scope for later processing.
1232 if (getLangOptions().CPlusPlus && FnRetType->isRecordType() &&
1233 !CurContext->isDependentContext())
1234 FunctionScopes.back()->Returns.push_back(Result);
1235
1236 return Owned(Result);
1142}
1143
1237}
1238
1144/// IsReturnCopyElidable - Whether returning @p RetExpr from a function that
1145/// returns a @p RetType fulfills the criteria for copy elision (C++0x 12.8p15).
1146static bool IsReturnCopyElidable(ASTContext &Ctx, QualType RetType,
1147 Expr *RetExpr) {
1148 QualType ExprType = RetExpr->getType();
1149 // - in a return statement in a function with ...
1150 // ... a class return type ...
1151 if (!RetType->isRecordType())
1152 return false;
1153 // ... the same cv-unqualified type as the function return type ...
1154 if (!Ctx.hasSameUnqualifiedType(RetType, ExprType))
1155 return false;
1156 // ... the expression is the name of a non-volatile automatic object ...
1157 // We ignore parentheses here.
1158 // FIXME: Is this compliant?
1159 const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(RetExpr->IgnoreParens());
1160 if (!DR)
1161 return false;
1162 const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl());
1163 if (!VD)
1164 return false;
1165 return VD->hasLocalStorage() && !VD->getType()->isReferenceType()
1166 && !VD->getType().isVolatileQualified();
1167}
1168
1169Action::OwningStmtResult
1170Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) {
1171 Expr *RetValExp = rex.takeAs<Expr>();
1172 if (getCurBlock())
1173 return ActOnBlockReturnStmt(ReturnLoc, RetValExp);
1174
1175 QualType FnRetType;
1176 if (const FunctionDecl *FD = getCurFunctionDecl()) {
1177 FnRetType = FD->getResultType();
1178 if (FD->hasAttr<NoReturnAttr>() ||
1179 FD->getType()->getAs<FunctionType>()->getNoReturnAttr())
1180 Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr)
1181 << getCurFunctionOrMethodDecl()->getDeclName();
1182 } else if (ObjCMethodDecl *MD = getCurMethodDecl())
1183 FnRetType = MD->getResultType();
1184 else // If we don't have a function/method context, bail.
1185 return StmtError();
1186
1239Action::OwningStmtResult
1240Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) {
1241 Expr *RetValExp = rex.takeAs<Expr>();
1242 if (getCurBlock())
1243 return ActOnBlockReturnStmt(ReturnLoc, RetValExp);
1244
1245 QualType FnRetType;
1246 if (const FunctionDecl *FD = getCurFunctionDecl()) {
1247 FnRetType = FD->getResultType();
1248 if (FD->hasAttr<NoReturnAttr>() ||
1249 FD->getType()->getAs<FunctionType>()->getNoReturnAttr())
1250 Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr)
1251 << getCurFunctionOrMethodDecl()->getDeclName();
1252 } else if (ObjCMethodDecl *MD = getCurMethodDecl())
1253 FnRetType = MD->getResultType();
1254 else // If we don't have a function/method context, bail.
1255 return StmtError();
1256
1257 ReturnStmt *Result = 0;
1187 if (FnRetType->isVoidType()) {
1188 if (RetValExp && !RetValExp->isTypeDependent()) {
1189 // C99 6.8.6.4p1 (ext_ since GCC warns)
1190 unsigned D = diag::ext_return_has_expr;
1191 if (RetValExp->getType()->isVoidType())
1192 D = diag::ext_return_has_void_expr;
1193
1194 // return (some void expression); is legal in C++.
1195 if (D != diag::ext_return_has_void_expr ||
1196 !getLangOptions().CPlusPlus) {
1197 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
1198 Diag(ReturnLoc, D)
1199 << CurDecl->getDeclName() << isa<ObjCMethodDecl>(CurDecl)
1200 << RetValExp->getSourceRange();
1201 }
1202
1203 RetValExp = MaybeCreateCXXExprWithTemporaries(RetValExp);
1204 }
1258 if (FnRetType->isVoidType()) {
1259 if (RetValExp && !RetValExp->isTypeDependent()) {
1260 // C99 6.8.6.4p1 (ext_ since GCC warns)
1261 unsigned D = diag::ext_return_has_expr;
1262 if (RetValExp->getType()->isVoidType())
1263 D = diag::ext_return_has_void_expr;
1264
1265 // return (some void expression); is legal in C++.
1266 if (D != diag::ext_return_has_void_expr ||
1267 !getLangOptions().CPlusPlus) {
1268 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
1269 Diag(ReturnLoc, D)
1270 << CurDecl->getDeclName() << isa<ObjCMethodDecl>(CurDecl)
1271 << RetValExp->getSourceRange();
1272 }
1273
1274 RetValExp = MaybeCreateCXXExprWithTemporaries(RetValExp);
1275 }
1205 return Owned(new (Context) ReturnStmt(ReturnLoc, RetValExp));
1206 }
1207
1208 if (!RetValExp && !FnRetType->isDependentType()) {
1276
1277 Result = new (Context) ReturnStmt(ReturnLoc, RetValExp, 0);
1278 } else if (!RetValExp && !FnRetType->isDependentType()) {
1209 unsigned DiagID = diag::warn_return_missing_expr; // C90 6.6.6.4p4
1210 // C99 6.8.6.4p1 (ext_ since GCC warns)
1211 if (getLangOptions().C99) DiagID = diag::ext_return_missing_expr;
1212
1213 if (FunctionDecl *FD = getCurFunctionDecl())
1214 Diag(ReturnLoc, DiagID) << FD->getIdentifier() << 0/*fn*/;
1215 else
1216 Diag(ReturnLoc, DiagID) << getCurMethodDecl()->getDeclName() << 1/*meth*/;
1279 unsigned DiagID = diag::warn_return_missing_expr; // C90 6.6.6.4p4
1280 // C99 6.8.6.4p1 (ext_ since GCC warns)
1281 if (getLangOptions().C99) DiagID = diag::ext_return_missing_expr;
1282
1283 if (FunctionDecl *FD = getCurFunctionDecl())
1284 Diag(ReturnLoc, DiagID) << FD->getIdentifier() << 0/*fn*/;
1285 else
1286 Diag(ReturnLoc, DiagID) << getCurMethodDecl()->getDeclName() << 1/*meth*/;
1217 return Owned(new (Context) ReturnStmt(ReturnLoc, (Expr*)0));
1218 }
1287 Result = new (Context) ReturnStmt(ReturnLoc);
1288 } else {
1289 const VarDecl *NRVOCandidate = 0;
1290 if (!FnRetType->isDependentType() && !RetValExp->isTypeDependent()) {
1291 // we have a non-void function with an expression, continue checking
1219
1292
1220 if (!FnRetType->isDependentType() && !RetValExp->isTypeDependent()) {
1221 // we have a non-void function with an expression, continue checking
1293 // C99 6.8.6.4p3(136): The return statement is not an assignment. The
1294 // overlap restriction of subclause 6.5.16.1 does not apply to the case of
1295 // function return.
1222
1296
1223 // C99 6.8.6.4p3(136): The return statement is not an assignment. The
1224 // overlap restriction of subclause 6.5.16.1 does not apply to the case of
1225 // function return.
1297 // In C++ the return statement is handled via a copy initialization.
1298 // the C version of which boils down to CheckSingleAssignmentConstraints.
1299 NRVOCandidate = getNRVOCandidate(Context, FnRetType, RetValExp);
1300 OwningExprResult Res = PerformCopyInitialization(
1301 InitializedEntity::InitializeResult(ReturnLoc,
1302 FnRetType,
1303 NRVOCandidate != 0),
1304 SourceLocation(),
1305 Owned(RetValExp));
1306 if (Res.isInvalid()) {
1307 // FIXME: Cleanup temporaries here, anyway?
1308 return StmtError();
1309 }
1226
1310
1227 // C++0x 12.8p15: When certain criteria are met, an implementation is
1228 // allowed to omit the copy construction of a class object, [...]
1229 // - in a return statement in a function with a class return type, when
1230 // the expression is the name of a non-volatile automatic object with
1231 // the same cv-unqualified type as the function return type, the copy
1232 // operation can be omitted [...]
1233 // C++0x 12.8p16: When the criteria for elision of a copy operation are met
1234 // and the object to be copied is designated by an lvalue, overload
1235 // resolution to select the constructor for the copy is first performed
1236 // as if the object were designated by an rvalue.
1237 // Note that we only compute Elidable if we're in C++0x, since we don't
1238 // care otherwise.
1239 bool Elidable = getLangOptions().CPlusPlus0x ?
1240 IsReturnCopyElidable(Context, FnRetType, RetValExp) :
1241 false;
1242 // FIXME: Elidable
1243 (void)Elidable;
1244
1245 // In C++ the return statement is handled via a copy initialization.
1246 // the C version of which boils down to CheckSingleAssignmentConstraints.
1247 OwningExprResult Res = PerformCopyInitialization(
1248 InitializedEntity::InitializeResult(ReturnLoc,
1249 FnRetType),
1250 SourceLocation(),
1251 Owned(RetValExp));
1252 if (Res.isInvalid()) {
1253 // FIXME: Cleanup temporaries here, anyway?
1254 return StmtError();
1311 RetValExp = Res.takeAs<Expr>();
1312 if (RetValExp)
1313 CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc);
1255 }
1314 }
1256
1257 RetValExp = Res.takeAs<Expr>();
1258 if (RetValExp)
1259 CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc);
1315
1316 if (RetValExp)
1317 RetValExp = MaybeCreateCXXExprWithTemporaries(RetValExp);
1318 Result = new (Context) ReturnStmt(ReturnLoc, RetValExp, NRVOCandidate);
1260 }
1319 }
1261
1262 if (RetValExp)
1263 RetValExp = MaybeCreateCXXExprWithTemporaries(RetValExp);
1264 return Owned(new (Context) ReturnStmt(ReturnLoc, RetValExp));
1320
1321 // If we need to check for the named return value optimization, save the
1322 // return statement in our scope for later processing.
1323 if (getLangOptions().CPlusPlus && FnRetType->isRecordType() &&
1324 !CurContext->isDependentContext())
1325 FunctionScopes.back()->Returns.push_back(Result);
1326
1327 return Owned(Result);
1265}
1266
1267/// CheckAsmLValue - GNU C has an extremely ugly extension whereby they silently
1268/// ignore "noop" casts in places where an lvalue is required by an inline asm.
1269/// We emulate this behavior when -fheinous-gnu-extensions is specified, but
1270/// provide a strong guidance to not use it.
1271///
1272/// This method checks to see if the argument is an acceptable l-value and

--- 436 unchanged lines hidden ---
1328}
1329
1330/// CheckAsmLValue - GNU C has an extremely ugly extension whereby they silently
1331/// ignore "noop" casts in places where an lvalue is required by an inline asm.
1332/// We emulate this behavior when -fheinous-gnu-extensions is specified, but
1333/// provide a strong guidance to not use it.
1334///
1335/// This method checks to see if the argument is an acceptable l-value and

--- 436 unchanged lines hidden ---