11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include "src/execution/isolate.h"
61cb0ef41Sopenharmony_ci#include "src/handles/handles-inl.h"
71cb0ef41Sopenharmony_ci#include "src/handles/handles.h"
81cb0ef41Sopenharmony_ci#include "src/heap/local-heap.h"
91cb0ef41Sopenharmony_ci#include "src/objects/foreign-inl.h"
101cb0ef41Sopenharmony_ci#include "src/objects/managed.h"
111cb0ef41Sopenharmony_ci#include "src/objects/maybe-object.h"
121cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h"
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_cinamespace v8 {
151cb0ef41Sopenharmony_cinamespace internal {
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci// ------- Test simple argument evaluation order problems ---------
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_civoid Safepoint() { LocalHeap::Current()->Safepoint(); }
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciHandle<Object> CauseGC(Handle<Object> obj, Isolate* isolate) {
221cb0ef41Sopenharmony_ci  isolate->heap()->CollectGarbage(OLD_SPACE, GarbageCollectionReason::kTesting);
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  return obj;
251cb0ef41Sopenharmony_ci}
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ciObject CauseGCRaw(Object obj, Isolate* isolate) {
281cb0ef41Sopenharmony_ci  isolate->heap()->CollectGarbage(OLD_SPACE, GarbageCollectionReason::kTesting);
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci  return obj;
311cb0ef41Sopenharmony_ci}
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ciManaged<Smi> CauseGCManaged(int i, Isolate* isolate) {
341cb0ef41Sopenharmony_ci  isolate->heap()->CollectGarbage(OLD_SPACE, GarbageCollectionReason::kTesting);
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  return Managed<Smi>::cast(Smi::FromInt(i));
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_civoid TwoArgumentsFunction(Object a, Object b) {
401cb0ef41Sopenharmony_ci  a.Print();
411cb0ef41Sopenharmony_ci  b.Print();
421cb0ef41Sopenharmony_ci}
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_civoid TestTwoArguments(Isolate* isolate) {
451cb0ef41Sopenharmony_ci  Handle<JSObject> obj1 = isolate->factory()->NewJSObjectWithNullProto();
461cb0ef41Sopenharmony_ci  Handle<JSObject> obj2 = isolate->factory()->NewJSObjectWithNullProto();
471cb0ef41Sopenharmony_ci  // Should cause warning.
481cb0ef41Sopenharmony_ci  TwoArgumentsFunction(*CauseGC(obj1, isolate), *CauseGC(obj2, isolate));
491cb0ef41Sopenharmony_ci}
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_civoid TwoSizeTArgumentsFunction(size_t a, size_t b) {
521cb0ef41Sopenharmony_ci  USE(a);
531cb0ef41Sopenharmony_ci  USE(b);
541cb0ef41Sopenharmony_ci}
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_civoid TestTwoSizeTArguments(Isolate* isolate) {
571cb0ef41Sopenharmony_ci  Handle<JSObject> obj1 = isolate->factory()->NewJSObjectWithNullProto();
581cb0ef41Sopenharmony_ci  Handle<JSObject> obj2 = isolate->factory()->NewJSObjectWithNullProto();
591cb0ef41Sopenharmony_ci  // Should cause warning.
601cb0ef41Sopenharmony_ci  TwoSizeTArgumentsFunction(sizeof(*CauseGC(obj1, isolate)),
611cb0ef41Sopenharmony_ci                            sizeof(*CauseGC(obj2, isolate)));
621cb0ef41Sopenharmony_ci}
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ci// --------- Test problems with method arguments ----------
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ciclass SomeObject : public Object {
671cb0ef41Sopenharmony_ci public:
681cb0ef41Sopenharmony_ci  void Method(Object a) { a.Print(); }
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ci  SomeObject& operator=(const Object& b) {
711cb0ef41Sopenharmony_ci    this->Print();
721cb0ef41Sopenharmony_ci    return *this;
731cb0ef41Sopenharmony_ci  }
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci  DECL_CAST(SomeObject)
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci  OBJECT_CONSTRUCTORS(SomeObject, Object);
781cb0ef41Sopenharmony_ci};
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_civoid TestMethodCall(Isolate* isolate) {
811cb0ef41Sopenharmony_ci  SomeObject obj;
821cb0ef41Sopenharmony_ci  Handle<SomeObject> so = handle(obj, isolate);
831cb0ef41Sopenharmony_ci  Handle<JSObject> obj1 = isolate->factory()->NewJSObjectWithNullProto();
841cb0ef41Sopenharmony_ci  // Should cause warning.
851cb0ef41Sopenharmony_ci  so->Method(*CauseGC(obj1, isolate));
861cb0ef41Sopenharmony_ci  // Should cause warning.
871cb0ef41Sopenharmony_ci  so->Method(CauseGCRaw(*obj1, isolate));
881cb0ef41Sopenharmony_ci}
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_civoid TestOperatorCall(Isolate* isolate) {
911cb0ef41Sopenharmony_ci  SomeObject obj;
921cb0ef41Sopenharmony_ci  Handle<JSObject> obj1 = isolate->factory()->NewJSObjectWithNullProto();
931cb0ef41Sopenharmony_ci  // Should not cause warning.
941cb0ef41Sopenharmony_ci  obj = *CauseGC(obj1, isolate);
951cb0ef41Sopenharmony_ci}
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ci// --------- Test for templated sub-classes of Object ----------
981cb0ef41Sopenharmony_ci
991cb0ef41Sopenharmony_civoid TestFollowingTemplates(Isolate* isolate) {
1001cb0ef41Sopenharmony_ci  // Should cause warning.
1011cb0ef41Sopenharmony_ci  CauseGCManaged(42, isolate);
1021cb0ef41Sopenharmony_ci}
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ci// --------- Test for correctly resolving virtual methods ----------
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ciclass BaseObject {
1071cb0ef41Sopenharmony_ci public:
1081cb0ef41Sopenharmony_ci  virtual Handle<Object> VirtualCauseGC(Handle<Object> obj, Isolate* isolate) {
1091cb0ef41Sopenharmony_ci    return obj;
1101cb0ef41Sopenharmony_ci  }
1111cb0ef41Sopenharmony_ci};
1121cb0ef41Sopenharmony_ci
1131cb0ef41Sopenharmony_ciclass DerivedObject : public BaseObject {
1141cb0ef41Sopenharmony_ci public:
1151cb0ef41Sopenharmony_ci  Handle<Object> VirtualCauseGC(Handle<Object> obj, Isolate* isolate) override {
1161cb0ef41Sopenharmony_ci    isolate->heap()->CollectGarbage(OLD_SPACE,
1171cb0ef41Sopenharmony_ci                                    GarbageCollectionReason::kTesting);
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_ci    return obj;
1201cb0ef41Sopenharmony_ci  }
1211cb0ef41Sopenharmony_ci};
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_civoid TestFollowingVirtualFunctions(Isolate* isolate) {
1241cb0ef41Sopenharmony_ci  DerivedObject derived;
1251cb0ef41Sopenharmony_ci  BaseObject* base = &derived;
1261cb0ef41Sopenharmony_ci  Handle<JSObject> obj1 = isolate->factory()->NewJSObjectWithNullProto();
1271cb0ef41Sopenharmony_ci
1281cb0ef41Sopenharmony_ci  SomeObject so;
1291cb0ef41Sopenharmony_ci  Handle<SomeObject> so_handle = handle(so, isolate);
1301cb0ef41Sopenharmony_ci  // Should cause warning.
1311cb0ef41Sopenharmony_ci  so_handle->Method(*derived.VirtualCauseGC(obj1, isolate));
1321cb0ef41Sopenharmony_ci  // Should cause warning.
1331cb0ef41Sopenharmony_ci  so_handle->Method(*base->VirtualCauseGC(obj1, isolate));
1341cb0ef41Sopenharmony_ci}
1351cb0ef41Sopenharmony_ci
1361cb0ef41Sopenharmony_ci// --------- Test for correctly resolving static methods ----------
1371cb0ef41Sopenharmony_ci
1381cb0ef41Sopenharmony_ciclass SomeClass {
1391cb0ef41Sopenharmony_ci public:
1401cb0ef41Sopenharmony_ci  static Handle<Object> StaticCauseGC(Handle<Object> obj, Isolate* isolate) {
1411cb0ef41Sopenharmony_ci    isolate->heap()->CollectGarbage(OLD_SPACE,
1421cb0ef41Sopenharmony_ci                                    GarbageCollectionReason::kTesting);
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ci    return obj;
1451cb0ef41Sopenharmony_ci  }
1461cb0ef41Sopenharmony_ci};
1471cb0ef41Sopenharmony_ci
1481cb0ef41Sopenharmony_civoid TestFollowingStaticFunctions(Isolate* isolate) {
1491cb0ef41Sopenharmony_ci  SomeObject so;
1501cb0ef41Sopenharmony_ci  Handle<SomeObject> so_handle = handle(so, isolate);
1511cb0ef41Sopenharmony_ci
1521cb0ef41Sopenharmony_ci  Handle<JSObject> obj1 = isolate->factory()->NewJSObjectWithNullProto();
1531cb0ef41Sopenharmony_ci  // Should cause warning.
1541cb0ef41Sopenharmony_ci  so_handle->Method(*SomeClass::StaticCauseGC(obj1, isolate));
1551cb0ef41Sopenharmony_ci}
1561cb0ef41Sopenharmony_ci
1571cb0ef41Sopenharmony_ci// --------- Test basic dead variable analysis ----------
1581cb0ef41Sopenharmony_ci
1591cb0ef41Sopenharmony_civoid TestDeadVarAnalysis(Isolate* isolate) {
1601cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
1611cb0ef41Sopenharmony_ci  CauseGCRaw(raw_obj, isolate);
1621cb0ef41Sopenharmony_ci
1631cb0ef41Sopenharmony_ci  // Should cause warning.
1641cb0ef41Sopenharmony_ci  raw_obj.Print();
1651cb0ef41Sopenharmony_ci}
1661cb0ef41Sopenharmony_ci
1671cb0ef41Sopenharmony_civoid TestDeadVarBecauseOfSafepointAnalysis(Isolate* isolate) {
1681cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
1691cb0ef41Sopenharmony_ci  Safepoint();
1701cb0ef41Sopenharmony_ci
1711cb0ef41Sopenharmony_ci  // Should cause warning.
1721cb0ef41Sopenharmony_ci  raw_obj.Print();
1731cb0ef41Sopenharmony_ci}
1741cb0ef41Sopenharmony_ci
1751cb0ef41Sopenharmony_civoid TestGuardedDeadVarAnalysis(Isolate* isolate) {
1761cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
1771cb0ef41Sopenharmony_ci
1781cb0ef41Sopenharmony_ci  // Note: having DisableGCMole with the same function as CauseGC
1791cb0ef41Sopenharmony_ci  // normally doesn't make sense, but we want to test whether the guards
1801cb0ef41Sopenharmony_ci  // are recognized by GCMole.
1811cb0ef41Sopenharmony_ci  DisableGCMole no_gc_mole;
1821cb0ef41Sopenharmony_ci  CauseGCRaw(raw_obj, isolate);
1831cb0ef41Sopenharmony_ci
1841cb0ef41Sopenharmony_ci  // Shouldn't cause warning.
1851cb0ef41Sopenharmony_ci  raw_obj.Print();
1861cb0ef41Sopenharmony_ci}
1871cb0ef41Sopenharmony_ci
1881cb0ef41Sopenharmony_civoid TestGuardedDeadVarAnalysis2(Isolate* isolate) {
1891cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
1901cb0ef41Sopenharmony_ci
1911cb0ef41Sopenharmony_ci  // Note: having DisallowGarbageCollection with the same function as CauseGC
1921cb0ef41Sopenharmony_ci  // normally doesn't make sense, but we want to test whether the guards
1931cb0ef41Sopenharmony_ci  // are recognized by GCMole.
1941cb0ef41Sopenharmony_ci  DisallowGarbageCollection no_gc;
1951cb0ef41Sopenharmony_ci  CauseGCRaw(raw_obj, isolate);
1961cb0ef41Sopenharmony_ci
1971cb0ef41Sopenharmony_ci  // Should cause warning.
1981cb0ef41Sopenharmony_ci  raw_obj.Print();
1991cb0ef41Sopenharmony_ci}
2001cb0ef41Sopenharmony_ci
2011cb0ef41Sopenharmony_civoid TestGuardedAgainstSafepointDeadVarAnalysis(Isolate* isolate) {
2021cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
2031cb0ef41Sopenharmony_ci
2041cb0ef41Sopenharmony_ci  // Note: having DisableGCMole with the same function as CauseGC
2051cb0ef41Sopenharmony_ci  // normally doesn't make sense, but we want to test whether the guards
2061cb0ef41Sopenharmony_ci  // are recognized by GCMole.
2071cb0ef41Sopenharmony_ci  DisableGCMole no_gc_mole;
2081cb0ef41Sopenharmony_ci  Safepoint();
2091cb0ef41Sopenharmony_ci
2101cb0ef41Sopenharmony_ci  // Shouldn't cause warning.
2111cb0ef41Sopenharmony_ci  raw_obj.Print();
2121cb0ef41Sopenharmony_ci}
2131cb0ef41Sopenharmony_ci
2141cb0ef41Sopenharmony_civoid TestGuardedAgainstSafepointDeadVarAnalysis2(Isolate* isolate) {
2151cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
2161cb0ef41Sopenharmony_ci
2171cb0ef41Sopenharmony_ci  // Note: having DisallowGarbageCollection with the same function as CauseGC
2181cb0ef41Sopenharmony_ci  // normally doesn't make sense, but we want to test whether the guards
2191cb0ef41Sopenharmony_ci  // are recognized by GCMole.
2201cb0ef41Sopenharmony_ci  DisallowGarbageCollection no_gc;
2211cb0ef41Sopenharmony_ci  Safepoint();
2221cb0ef41Sopenharmony_ci
2231cb0ef41Sopenharmony_ci  // Should cause warning.
2241cb0ef41Sopenharmony_ci  raw_obj.Print();
2251cb0ef41Sopenharmony_ci}
2261cb0ef41Sopenharmony_ci
2271cb0ef41Sopenharmony_civoid TestGuardedAgainstSafepointDeadVarAnalysis3(Isolate* isolate) {
2281cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
2291cb0ef41Sopenharmony_ci  // Note: having DisallowGarbageCollection with the same function as CauseGC
2301cb0ef41Sopenharmony_ci  // normally doesn't make sense, but we want to test whether the guards
2311cb0ef41Sopenharmony_ci  // are recognized by GCMole.
2321cb0ef41Sopenharmony_ci  DisallowGarbageCollection no_gc;
2331cb0ef41Sopenharmony_ci  Safepoint();
2341cb0ef41Sopenharmony_ci  // Should cause warning.
2351cb0ef41Sopenharmony_ci  raw_obj.Print();
2361cb0ef41Sopenharmony_ci  {
2371cb0ef41Sopenharmony_ci    DisableGCMole no_gc_mole;
2381cb0ef41Sopenharmony_ci    // Shouldn't cause warning.
2391cb0ef41Sopenharmony_ci    raw_obj.Print();
2401cb0ef41Sopenharmony_ci  }
2411cb0ef41Sopenharmony_ci  // Should cause warning.
2421cb0ef41Sopenharmony_ci  raw_obj.Print();
2431cb0ef41Sopenharmony_ci}
2441cb0ef41Sopenharmony_ci
2451cb0ef41Sopenharmony_civoid TestOnlyHeapGuardedDeadVarAnalysisInCompound(Isolate* isolate) {
2461cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
2471cb0ef41Sopenharmony_ci  // {DisallowHeapAccess} has a {DisallowHeapAllocation}, but no
2481cb0ef41Sopenharmony_ci  // {DisallowSafepoints}, so it could see objects move due to safepoints.
2491cb0ef41Sopenharmony_ci  DisallowHeapAccess no_gc;
2501cb0ef41Sopenharmony_ci  CauseGCRaw(raw_obj, isolate);
2511cb0ef41Sopenharmony_ci  // Should cause warning.
2521cb0ef41Sopenharmony_ci  raw_obj.Print();
2531cb0ef41Sopenharmony_ci}
2541cb0ef41Sopenharmony_ci
2551cb0ef41Sopenharmony_civoid TestOnlyHeapGuardedDeadVarAnalysisInCompound2(Isolate* isolate) {
2561cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
2571cb0ef41Sopenharmony_ci  // {DisallowHeapAccess} has a {DisallowHeapAllocation}, but no
2581cb0ef41Sopenharmony_ci  // {DisallowSafepoints}, so it could see objects move due to safepoints.
2591cb0ef41Sopenharmony_ci  DisallowHeapAccess no_gc;
2601cb0ef41Sopenharmony_ci  CauseGCRaw(raw_obj, isolate);
2611cb0ef41Sopenharmony_ci  // Should cause warning.
2621cb0ef41Sopenharmony_ci  raw_obj.Print();
2631cb0ef41Sopenharmony_ci  DisableGCMole no_gc_mole;
2641cb0ef41Sopenharmony_ci  // Should cause warning.
2651cb0ef41Sopenharmony_ci  raw_obj.Print();
2661cb0ef41Sopenharmony_ci}
2671cb0ef41Sopenharmony_ci
2681cb0ef41Sopenharmony_civoid TestGuardedDeadVarAnalysisNested(JSObject raw_obj, Isolate* isolate) {
2691cb0ef41Sopenharmony_ci  CauseGCRaw(raw_obj, isolate);
2701cb0ef41Sopenharmony_ci  // Should cause warning.
2711cb0ef41Sopenharmony_ci  raw_obj.Print();
2721cb0ef41Sopenharmony_ci}
2731cb0ef41Sopenharmony_ci
2741cb0ef41Sopenharmony_civoid TestGuardedDeadVarAnalysisCaller(Isolate* isolate) {
2751cb0ef41Sopenharmony_ci  DisableGCMole no_gc_mole;
2761cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
2771cb0ef41Sopenharmony_ci  TestGuardedDeadVarAnalysisNested(raw_obj, isolate);
2781cb0ef41Sopenharmony_ci  // Shouldn't cause warning.
2791cb0ef41Sopenharmony_ci  raw_obj.Print();
2801cb0ef41Sopenharmony_ci}
2811cb0ef41Sopenharmony_ci
2821cb0ef41Sopenharmony_civoid TestGuardedDeadVarAnalysisCaller2(Isolate* isolate) {
2831cb0ef41Sopenharmony_ci  DisallowGarbageCollection no_gc;
2841cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
2851cb0ef41Sopenharmony_ci  TestGuardedDeadVarAnalysisNested(raw_obj, isolate);
2861cb0ef41Sopenharmony_ci  // Should cause warning.
2871cb0ef41Sopenharmony_ci  raw_obj.Print();
2881cb0ef41Sopenharmony_ci}
2891cb0ef41Sopenharmony_ci
2901cb0ef41Sopenharmony_civoid TestGuardedDeadVarAnalysisCaller3(Isolate* isolate) {
2911cb0ef41Sopenharmony_ci  DisallowHeapAccess no_gc;
2921cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
2931cb0ef41Sopenharmony_ci  TestGuardedDeadVarAnalysisNested(raw_obj, isolate);
2941cb0ef41Sopenharmony_ci  // Should cause warning.
2951cb0ef41Sopenharmony_ci  raw_obj.Print();
2961cb0ef41Sopenharmony_ci}
2971cb0ef41Sopenharmony_ci
2981cb0ef41Sopenharmony_civoid TestGuardedDeadVarAnalysisCaller4(Isolate* isolate) {
2991cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
3001cb0ef41Sopenharmony_ci  TestGuardedDeadVarAnalysisNested(raw_obj, isolate);
3011cb0ef41Sopenharmony_ci  // Should cause warning.
3021cb0ef41Sopenharmony_ci  raw_obj.Print();
3031cb0ef41Sopenharmony_ci}
3041cb0ef41Sopenharmony_ci
3051cb0ef41Sopenharmony_ciJSObject GuardedAllocation(Isolate* isolate) {
3061cb0ef41Sopenharmony_ci  DisallowGarbageCollection no_gc;
3071cb0ef41Sopenharmony_ci  return *isolate->factory()->NewJSObjectWithNullProto();
3081cb0ef41Sopenharmony_ci}
3091cb0ef41Sopenharmony_ci
3101cb0ef41Sopenharmony_ciJSObject GuardedAllocation2(Isolate* isolate) {
3111cb0ef41Sopenharmony_ci  DisableGCMole no_gc_mole;
3121cb0ef41Sopenharmony_ci  return *isolate->factory()->NewJSObjectWithNullProto();
3131cb0ef41Sopenharmony_ci}
3141cb0ef41Sopenharmony_ci
3151cb0ef41Sopenharmony_civoid TestNestedDeadVarAnalysis(Isolate* isolate) {
3161cb0ef41Sopenharmony_ci  JSObject raw_obj = GuardedAllocation(isolate);
3171cb0ef41Sopenharmony_ci  CauseGCRaw(raw_obj, isolate);
3181cb0ef41Sopenharmony_ci  // Should cause warning.
3191cb0ef41Sopenharmony_ci  raw_obj.Print();
3201cb0ef41Sopenharmony_ci}
3211cb0ef41Sopenharmony_ci
3221cb0ef41Sopenharmony_civoid TestNestedDeadVarAnalysis2(Isolate* isolate) {
3231cb0ef41Sopenharmony_ci  DisableGCMole no_gc_mole;
3241cb0ef41Sopenharmony_ci  JSObject raw_obj = GuardedAllocation(isolate);
3251cb0ef41Sopenharmony_ci  CauseGCRaw(raw_obj, isolate);
3261cb0ef41Sopenharmony_ci  // Shouldn't cause warning.
3271cb0ef41Sopenharmony_ci  raw_obj.Print();
3281cb0ef41Sopenharmony_ci}
3291cb0ef41Sopenharmony_ci
3301cb0ef41Sopenharmony_ci// Test that putting a guard in the middle of the function doesn't
3311cb0ef41Sopenharmony_ci// mistakenly cover the whole scope of the raw variable.
3321cb0ef41Sopenharmony_civoid TestGuardedDeadVarAnalysisMidFunction(Isolate* isolate) {
3331cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
3341cb0ef41Sopenharmony_ci  CauseGCRaw(raw_obj, isolate);
3351cb0ef41Sopenharmony_ci  // Guarding the rest of the function from triggering a GC.
3361cb0ef41Sopenharmony_ci  DisallowGarbageCollection no_gc;
3371cb0ef41Sopenharmony_ci  // Should cause warning.
3381cb0ef41Sopenharmony_ci  raw_obj.Print();
3391cb0ef41Sopenharmony_ci}
3401cb0ef41Sopenharmony_ci
3411cb0ef41Sopenharmony_ci// Test that putting a guard in the middle of the function doesn't
3421cb0ef41Sopenharmony_ci// mistakenly cover the whole scope of the raw variable.
3431cb0ef41Sopenharmony_civoid TestGuardedDeadVarAnalysisMidFunction2(Isolate* isolate) {
3441cb0ef41Sopenharmony_ci  JSObject raw_obj = *isolate->factory()->NewJSObjectWithNullProto();
3451cb0ef41Sopenharmony_ci  CauseGCRaw(raw_obj, isolate);
3461cb0ef41Sopenharmony_ci  // Guarding the rest of the function from triggering a GC.
3471cb0ef41Sopenharmony_ci  DisableGCMole no_gc_mole;
3481cb0ef41Sopenharmony_ci  // Should cause warning.
3491cb0ef41Sopenharmony_ci  raw_obj.Print();
3501cb0ef41Sopenharmony_ci}
3511cb0ef41Sopenharmony_ci
3521cb0ef41Sopenharmony_ci}  // namespace internal
3531cb0ef41Sopenharmony_ci}  // namespace v8
354