Changeset bdd516a for driver/cc1.cc
- Timestamp:
- Apr 28, 2015, 4:21:36 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 42e2ad7
- Parents:
- ad17ba6a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
driver/cc1.cc
rad17ba6a rbdd516a 8 8 // Created On : Fri Aug 26 14:23:51 2005 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Sat Jan 10 14:16:06201511 // Update Count : 1510 // Last Modified On : Mon Apr 27 23:11:52 2015 11 // Update Count : 39 12 12 // 13 13 … … 34 34 string D__CFA_FLAGPREFIX__( "-D__CFA_FLAG__=" ); 35 35 36 char tmpname[] = P_tmpdir "/CFAXXXXXX"; 37 int tmpfilefd = -1; 38 36 39 37 40 bool prefix( string arg, string pre ) { … … 69 72 } // if 70 73 } // checkEnv 74 75 76 void rmtmpfile() { 77 if ( unlink( tmpname ) == -1 ) { // remove tmpname 78 perror ( "CFA Translator error: cpp failed" ); 79 exit( EXIT_FAILURE ); 80 } // if 81 tmpfilefd = -1; // mark closed 82 } // rmtmpfile 83 84 85 void sigTermHandler( int signal ) { 86 if ( tmpfilefd != -1 ) { // RACE, file created ? 87 rmtmpfile(); // remove 88 exit( EXIT_FAILURE ); // terminate 89 } // if 90 } // sigTermHandler 71 91 72 92 … … 89 109 const char *uargs[20]; // leave space for 20 additional cfa-cpp command line values 90 110 int nuargs = 1; // 0 => command name 111 112 signal( SIGINT, sigTermHandler ); 113 signal( SIGTERM, sigTermHandler ); 91 114 92 115 // process all the arguments … … 116 139 i += 1; // and the argument 117 140 118 // strip cfa flags controlling cpp step 119 141 // strip flags controlling cpp step 142 143 } else if ( arg == "-D__CPP__" ) { 144 cpp_flag = true; 145 } else if ( arg == "-D" && string( argv[i + 1] ) == "__CPP__" ) { 146 i += 1; // and the argument 147 cpp_flag = true; 120 148 } else if ( arg == "-D__CFA__" ) { 121 149 CFA_flag = true; … … 123 151 i += 1; // and the argument 124 152 CFA_flag = true; 125 } else if ( arg == "-D__CPP__" ) {126 cpp_flag = true;127 } else if ( arg == "-D" && string( argv[i + 1] ) == "__CPP__" ) {128 i += 1; // and the argument129 cpp_flag = true;130 153 } else if ( prefix( arg, D__CFA_FLAGPREFIX__ ) ) { 131 154 uargs[nuargs] = ( *new string( arg.substr( D__CFA_FLAGPREFIX__.size() ) ) ).c_str(); … … 233 256 // Create a temporary file to store output of the C preprocessor. 234 257 235 char tmpname[] = P_tmpdir "/CFAXXXXXX"; 236 int tmpfile = mkstemp( tmpname ); 237 if ( tmpfile == -1 ) { 258 tmpfilefd = mkstemp( tmpname ); 259 if ( tmpfilefd == -1 ) { 238 260 perror( "CFA Translator error: cpp level, mkstemp" ); 239 261 exit( EXIT_FAILURE ); … … 241 263 242 264 #ifdef __DEBUG_H__ 243 cerr << "tmpname:" << tmpname << " tmpfile :" << tmpfile<< endl;265 cerr << "tmpname:" << tmpname << " tmpfilefd:" << tmpfilefd << endl; 244 266 #endif // __DEBUG_H__ 245 267 … … 280 302 281 303 if ( WIFSIGNALED(code) != 0 ) { // child failed ? 282 unlink( tmpname );// remove tmpname304 rmtmpfile(); // remove tmpname 283 305 cerr << "CFA Translator error: cpp failed with signal " << WTERMSIG(code) << endl; 284 306 exit( EXIT_FAILURE ); … … 286 308 287 309 if ( WEXITSTATUS(code) != 0 ) { // child error ? 288 unlink( tmpname );// remove tmpname310 rmtmpfile(); // remove tmpname 289 311 exit( WEXITSTATUS( code ) ); // do not continue 290 312 } // if … … 293 315 // output. Otherwise, run the cfa-cpp preprocessor on the temporary file and save the result into the output file. 294 316 295 if ( CFA_flag || fork() == 0 ) { // conditional fork ?317 if ( fork() == 0 ) { // child runs CFA 296 318 uargs[0] = ( *new string( bprefix + "/cfa-cpp" ) ).c_str(); 297 319 … … 330 352 331 353 // Must unlink here because file must exist across execvp. 332 if ( unlink( tmpname ) == -1 ) { 333 perror( "CFA Translator error: cpp level, unlink" ); 334 exit( EXIT_FAILURE ); 335 } // if 354 rmtmpfile(); // remove tmpname 336 355 337 356 if ( WIFSIGNALED(code) ) { // child failed ?
Note: See TracChangeset
for help on using the changeset viewer.