@@ -942,15 +942,29 @@ static bool interp__builtin_atomic_lock_free(InterpState &S, CodePtr OpPC,
942942 if (Ptr.isZero ())
943943 return returnBool (true );
944944
945- QualType PointeeType = Call->getArg (1 )
946- ->IgnoreImpCasts ()
947- ->getType ()
948- ->castAs <PointerType>()
949- ->getPointeeType ();
950- // OK, we will inline operations on this object.
951- if (!PointeeType->isIncompleteType () &&
952- S.getCtx ().getTypeAlignInChars (PointeeType) >= Size)
953- return returnBool (true );
945+ if (Ptr.isIntegralPointer ()) {
946+ uint64_t IntVal = Ptr.getIntegerRepresentation ();
947+ if (APSInt (APInt (64 , IntVal, false ), true ).isAligned (Size.getAsAlign ()))
948+ return returnBool (true );
949+ }
950+
951+ const Expr *PtrArg = Call->getArg (1 );
952+ // Otherwise, check if the type's alignment against Size.
953+ if (const auto *ICE = dyn_cast<ImplicitCastExpr>(PtrArg)) {
954+ // Drop the potential implicit-cast to 'const volatile void*', getting
955+ // the underlying type.
956+ if (ICE->getCastKind () == CK_BitCast)
957+ PtrArg = ICE->getSubExpr ();
958+ }
959+
960+ if (auto PtrTy = PtrArg->getType ()->getAs <PointerType>()) {
961+ QualType PointeeType = PtrTy->getPointeeType ();
962+ if (!PointeeType->isIncompleteType () &&
963+ S.getCtx ().getTypeAlignInChars (PointeeType) >= Size) {
964+ // OK, we will inline operations on this object.
965+ return returnBool (true );
966+ }
967+ }
954968 }
955969 }
956970
0 commit comments