Skip to content

Commit 17d8a84

Browse files
committed
[clang][Interp] Fix handling PointerToIntegral casts
We need to always emit the diagnostic, but still do the cast. This is also what the current interpreter does.
1 parent 0dacba3 commit 17d8a84

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

clang/lib/AST/Interp/Interp.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -533,17 +533,6 @@ bool CheckPure(InterpState &S, CodePtr OpPC, const CXXMethodDecl *MD) {
533533
return false;
534534
}
535535

536-
bool CheckPotentialReinterpretCast(InterpState &S, CodePtr OpPC,
537-
const Pointer &Ptr) {
538-
if (!S.inConstantContext())
539-
return true;
540-
541-
const SourceInfo &E = S.Current->getSource(OpPC);
542-
S.CCEDiag(E, diag::note_constexpr_invalid_cast)
543-
<< 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
544-
return false;
545-
}
546-
547536
bool CheckFloatResult(InterpState &S, CodePtr OpPC, const Floating &Result,
548537
APFloat::opStatus Status) {
549538
const SourceInfo &E = S.Current->getSource(OpPC);

clang/lib/AST/Interp/Interp.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ bool CheckThis(InterpState &S, CodePtr OpPC, const Pointer &This);
113113
/// Checks if a method is pure virtual.
114114
bool CheckPure(InterpState &S, CodePtr OpPC, const CXXMethodDecl *MD);
115115

116-
/// Checks if reinterpret casts are legal in the current context.
117-
bool CheckPotentialReinterpretCast(InterpState &S, CodePtr OpPC,
118-
const Pointer &Ptr);
119-
120116
/// Sets the given integral value to the pointer, which is of
121117
/// a std::{weak,partial,strong}_ordering type.
122118
bool SetThreeWayComparisonField(InterpState &S, CodePtr OpPC,
@@ -1722,8 +1718,9 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
17221718
bool CastPointerIntegral(InterpState &S, CodePtr OpPC) {
17231719
const Pointer &Ptr = S.Stk.pop<Pointer>();
17241720

1725-
if (!CheckPotentialReinterpretCast(S, OpPC, Ptr))
1726-
return false;
1721+
const SourceInfo &E = S.Current->getSource(OpPC);
1722+
S.CCEDiag(E, diag::note_constexpr_invalid_cast)
1723+
<< 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
17271724

17281725
S.Stk.push<T>(T::from(Ptr.getIntegerRepresentation()));
17291726
return true;

0 commit comments

Comments
 (0)