Issue 53090
Summary False positive with -fsanitizer=memory and fstream
Labels new issue
Assignees
Reporter Username404-59
    Clang shows a "use-of-unitialized-value" warning when a fstream is used; [here](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:6,endLineNumber:38,positionColumn:6,positionLineNumber:38,selectionStartColumn:6,selectionStartLineNumber:38,startColumn:6,startLineNumber:38),source:'%23include+%3Cfstream%3E%0A%23include+%3Ciostream%3E%0A%23include+%3Cstring%3E%0A%23include+%3Cstring_view%3E%0A%23include+%3Cexception%3E%0A%23include+%3Csystem_error%3E%0Ausing+namespace+std%3B%0A%0Aclass+Exception:+public+exception+%7B%0A++++string+exceptionCause%3B%0Apublic:%0A++++%5B%5Bnodiscard%5D%5D+const+char*+what()+const+noexcept+final+%7B%0A++++++++return+exceptionCause.data()%3B%0A++++%7D%0A++++explicit+Exception(const+string_view%26+cause):+exceptionCause(cause)+%7B%0A++++++++if+(!!cause.ends_with(!'%5Cn!'))+exceptionCause+%2B%3D+!'%5Cn!'%3B%0A++++%7D%0A%7D%3B%0A%0Astring+getFileContent(const+string%26+file)%0A%7B%0A++++ifstream+fileStream(file,+ios::in)%3B%0A++++if+(fileStream)+%7B+//+%3C--+Warning+here%0A++++++++string+lineinput,+fullinput%3B%0A++++++++while+(getline(fileStream,+lineinput))+%7B%0A++++++++++++fullinput.append(lineinput+%2B%3D+!'%5Cn!')%3B%0A++++++++%7D%0A++++++++fileStream.close()%3B%0A++++++++return+fullinput%3B%0A++++%7D+else+throw+Exception(%22Could+not+open+%5C%22%22+%2B+file+%2B+%22%5C%22+:+%22+%2B+generic_category().message(errno))%3B%0A%7D%0A%0Aint+main(int+argc,+char*+argv%5B%5D)+%7B%0A++++try+%7B%0A++++++++getFileContent(%22something%22)%3B%0A++++%7D+catch+(const+Exception%26+e)+%7B%0A++++++++cerr+%3C%3C+e.what()%3B%0A++++%7D%0A++++return+EXIT_SUCCESS%3B%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:26.161879895561356,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((g:!((h:compiler,i:(compiler:clang1300,filters:(b:'0',binary:'0',commentOnly:'0',demangle:'0',directives:'0',execute:'0',intel:'1',libraryCode:'0',trim:'1'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'-std%3Dc%2B%2B20+-fsanitize%3Dmemory+-fsanitize-memory-track-origins++-g+-fno-omit-frame-pointer+-fno-optimize-sibling-calls',selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1,tree:'1'),l:'5',n:'0',o:'x86-64+clang+13.0.0+(C%2B%2B,+Editor+%231,+Compiler+%231)',t:'0')),k:58.581375108790255,l:'4',m:48.34008097165994,n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compiler:1,editor:1,fontScale:14,fontUsePx:'0',wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+clang+13.0.0+(Compiler+%231)',t:'0')),header:(),l:'4',m:51.6599190283401,n:'0',o:'',s:0,t:'0')),k:73.83812010443864,l:'3',n:'0',o:'',t:'0')),l:'2',n:'0',o:'',t:'0')),version:4
)'s a godbolt link showcasing it.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to