xref: /llvm-project/cross-project-tests/debuginfo-tests/dexter-tests/nrvo.cpp (revision 45a40c163932d12b72b33bd1d8a84519392b5d39)
1 // This ensures that DW_OP_deref is inserted when necessary, such as when NRVO
2 // of a string object occurs in C++.
3 //
4 // REQUIRES: system-windows
5 //
6 // RUN: %clang_cl /Z7 /Zi %s -o %t
7 // RUN: %dexter --fail-lt 1.0 -w --binary %t --debugger 'dbgeng' -- %s
8 
9 struct string {
stringstring10   string() {}
stringstring11   string(int i) : i(i) {}
~stringstring12   ~string() {}
13   int i = 0;
14 };
get_string()15 string get_string() {
16   string unused;
17   string result = 3;
18   return result; // DexLabel('readresult1')
19 }
some_function(int)20 void some_function(int) {}
21 struct string2 {
22   string2() = default;
string2string223   string2(string2 &&other) { i = other.i; }
24   int i;
25 };
get_string2()26 string2 get_string2() {
27   string2 result;
28   result.i = 5;
29   some_function(result.i);
30   // Test that the debugger can get the value of result after another
31   // function is called.
32   return result; // DexLabel('readresult2')
33 }
main()34 int main() {
35   get_string();
36   get_string2();
37 }
38 
39 // DexExpectWatchValue('result.i', 3, on_line=ref('readresult1'))
40 // DexExpectWatchValue('result.i', 5, on_line=ref('readresult2'))
41