c++: robustify testcase [PR109752]
[official-gcc.git] / gcc / testsuite / g++.dg / tree-prof / devirt.C
blob1121f4871573d4c6402e13f6f9f3c293e007349d
1 /* PR ipa/88561 */
2 /* { dg-options "-O3 -fdump-tree-tracer-details -fdump-tree-dom3-details -fno-profile-values" } */
4 struct nsISupports
6   virtual int QueryInterface (const int &aIID, void **aInstancePtr) = 0;
7   virtual __attribute__((noinline, noclone)) unsigned AddRef (void) = 0;
8   virtual unsigned Release (void) = 0;
9 };
11 struct nsIObserver : public nsISupports
13   virtual int Observe (nsISupports * aSubject, const char *aTopic, const unsigned short *aData) = 0;
16 struct nsISupportsWeakReference : public nsISupports
18   virtual int GetWeakReference (void **_retval) = 0;
21 struct nsSupportsWeakReference : public nsISupportsWeakReference
23   nsSupportsWeakReference () : mProxy (0) {}
24   virtual int GetWeakReference (void **_retval) override { return 0; }
25   ~nsSupportsWeakReference () {}
26   void NoticeProxyDestruction () { mProxy = nullptr; }
27   void *mProxy;
28   void ClearWeakReferences ();
29   bool HasWeakReferences () const { return !!mProxy; }
32 struct mozIPersonalDictionary : public nsISupports
34   virtual int Load (void) = 0;
35   virtual int Save (void) = 0;
36   virtual int GetWordList (void **aWordList) = 0;
37   virtual int Check (const int &word, bool * _retval) = 0;
38   virtual int AddWord (const int &word) = 0;
39   virtual int RemoveWord (const int &word) = 0;
40   virtual int IgnoreWord (const int &word) = 0;
41   virtual int EndSession (void) = 0;
44 struct mozPersonalDictionary final
45   : public mozIPersonalDictionary, public nsIObserver, public nsSupportsWeakReference
47   virtual int QueryInterface (const int &aIID, void **aInstancePtr) override;
48   virtual __attribute__((noinline, noclone)) unsigned AddRef (void) override;
49   virtual unsigned Release (void) override;
50   unsigned long mRefCnt;
51   virtual int Load (void) override { return 0; }
52   virtual int Save (void) override { return 0; }
53   virtual int GetWordList (void **aWordList) override { return 0; }
54   virtual int Check (const int &word, bool * _retval) override { return 0; }
55   virtual int AddWord (const int &word) override { return 0; }
56   virtual int RemoveWord (const int &word) override { return 0; }
57   virtual int IgnoreWord (const int &word) override { return 0; }
58   virtual int EndSession (void) override { return 0; }
59   virtual int Observe (nsISupports * aSubject, const char *aTopic, const unsigned short *aData) override { return 0; }
60   mozPersonalDictionary () : mRefCnt(0) {}
61   int Init () { return 0; }
62   virtual ~mozPersonalDictionary () {}
63   bool mIsLoaded;
64   bool mSavePending;
65   void *mFile;
66   char mMonitor[96];
67   char mMonitorSave[96];
68   char mDictionaryTable[32];
69   char mIgnoreTable[32];
72 unsigned
73 mozPersonalDictionary::AddRef (void)
75   unsigned count = ++mRefCnt;
76   return count;
79 unsigned
80 mozPersonalDictionary::Release (void)
82   unsigned count = --mRefCnt;
83   if (count == 0)
84     {
85       mRefCnt = 1;
86       delete (this);
87       return 0;
88     }
89   return count;
92 int
93 mozPersonalDictionary::QueryInterface (const int &aIID, void **aInstancePtr)
95   nsISupports *foundInterface;
96   if (aIID == 122)
97     foundInterface = static_cast <mozIPersonalDictionary *>(this);
98   else
99     foundInterface = static_cast <nsISupportsWeakReference *>(this);
100   int status;
101   foundInterface->AddRef ();
102   *aInstancePtr = foundInterface;
103   return status;
106 __attribute__((noipa)) int
107 foo (nsISupports *p, const int &i)
109   void *q;
110   return p->QueryInterface (i, &q);
114 main ()
116   mozPersonalDictionary m;
117   int j = 123;
118   for (int i = 0; i < 100000; i++)
119     foo (static_cast <nsISupportsWeakReference *>(&m), j);
120   if (m.mRefCnt != 100000)
121     __builtin_abort ();
124 /* { dg-final-use-not-autofdo { scan-tree-dump-times "folding virtual function call to virtual unsigned int mozPersonalDictionary::_ZThn16" 1 "tracer" { target { lp64 || llp64 } } } } */
125 /* { dg-final-use-not-autofdo { scan-tree-dump-times "folding virtual function call to virtual unsigned int mozPersonalDictionary::_ZThn8" 1 "tracer" { target ilp32 } } } */
126 /* { dg-final-use-not-autofdo { scan-tree-dump-times "folding virtual function call to virtual unsigned int mozPersonalDictionary::AddRef" 1 "tracer" } } */