File tree Expand file tree Collapse file tree 4 files changed +47
-3
lines changed Expand file tree Collapse file tree 4 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -440,12 +440,17 @@ class dyn_var<T *>
440440 return (cast)(this ->dyn_var_impl <T*>::operator *());
441441 }
442442 // Hack for creating a member that's live across return site
443- dyn_var<T> _p = as_member(this , " _p" );
443+
444+ std::unique_ptr<dyn_var<T>> _p = nullptr ;
445+
444446 dyn_var<T> *operator ->() {
445447 auto b = this ->operator [](0 );
446448 b.encompassing_expr ->template setMetadata <bool >(" deref_is_star" , true );
447- _p = (cast)b;
448- return _p.addr ();
449+ if (_p == nullptr ) {
450+ _p = std::unique_ptr<dyn_var<T>>(new dyn_var<T>(as_member (this , " _p" )));
451+ }
452+ *_p = (cast)b;
453+ return _p->addr ();
449454 }
450455};
451456
Original file line number Diff line number Diff line change 1+ void bar (void) {
2+ linked_list* x_0;
3+ ((x_0->next)->next)->next = 0;
4+ }
5+
Original file line number Diff line number Diff line change 1+ void bar (void) {
2+ linked_list* var0;
3+ ((var0->next)->next)->next = 0;
4+ }
5+
Original file line number Diff line number Diff line change 1+ // Include the headers
2+ #include " blocks/c_code_generator.h"
3+ #include " builder/static_var.h"
4+ #include " builder/dyn_var.h"
5+ #include " blocks/rce.h"
6+ #include < iostream>
7+
8+ // Include the BuildIt types
9+ using builder::dyn_var;
10+ using builder::static_var;
11+
12+ struct linked_list {
13+ static constexpr const char * type_name = " linked_list" ;
14+ dyn_var<linked_list*> next = builder::with_name(" next" );
15+ };
16+
17+ static void bar (void ) {
18+ dyn_var<struct linked_list *> x;
19+ x->next ->next ->next = 0 ;
20+ }
21+
22+ int main (int argc, char * argv[]) {
23+ builder::builder_context context;
24+ auto ast = context.extract_function_ast (bar, " bar" );
25+ block::c_code_generator::generate_code (ast, std::cout, 0 );
26+ return 0 ;
27+ }
28+
29+
You can’t perform that action at this time.
0 commit comments