Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFile::close() leads to SIGILL
Qt 6.11 is out! See what's new in the release blog

QFile::close() leads to SIGILL

Scheduled Pinned Locked Moved Solved General and Desktop
31 Posts 5 Posters 4.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Christian EhrlicherC Online
    Christian EhrlicherC Online
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #19

    Again: it's undefined - anything can happen, in this case it crashed.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    JonBJ 1 Reply Last reply
    2
    • Christian EhrlicherC Christian Ehrlicher

      Again: it's undefined - anything can happen, in this case it crashed.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #20

      @Christian-Ehrlicher
      For the record, I have read what I can from various stackoverflow posts, etc. I do accept (now) that non-void no-return => UB => "anything may happen including crash". I was not aware of this, interesting, and thank you. Note however that there was no mention of damage to nearby kittens, either in C++ standard or in posts, so I am calming mine down about this (apart from, I have assured her this is one error I have never made)!

      1 Reply Last reply
      1
      • JonBJ JonB

        @Christian-Ehrlicher
        Yes, but you know that is not the issue we are discussing! You know we are not talking about what the return result number is, we are talking about "crashing" on the } of foo() (or at the caller) because foo() does not have a return statement.

        The following also has "undefined behaviour" (in what it prints), but I don't expect it to "crash":

        int z;
        printf("%d\n", z);
        
        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #21

        Hi,

        @JonB said in QFile::close() leads to SIGILL:

        The following also has "undefined behaviour" (in what it prints), but I don't expect it to "crash":
        int z;
        printf("%d\n", z);

        Strictly speaking it's not undefined behaviour. You will print a random value from an uninitialized int variable.

        As @Christian-Ehrlicher already wrote undefined behaviour can be anything from funky values to a crash.

        I had once to debug a strange crash that in the end was due to a missing return statement for a QString and the return value wasn't even used. For the fun of experimenting, I changed the return type to int and no crash anymore. That's what undefined behaviour is. That took me quite a while to find because the original warning was swamped in a tons of other warnings (words of the original developer: don't care these are just warnings), the return value being ignored, I did not take notice immediately that the return statement was missing and the code was so involved that tracing the crash correctly was pretty hard as is also required external hardware (

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        JonBJ 1 Reply Last reply
        2
        • SGaistS SGaist

          Hi,

          @JonB said in QFile::close() leads to SIGILL:

          The following also has "undefined behaviour" (in what it prints), but I don't expect it to "crash":
          int z;
          printf("%d\n", z);

          Strictly speaking it's not undefined behaviour. You will print a random value from an uninitialized int variable.

          As @Christian-Ehrlicher already wrote undefined behaviour can be anything from funky values to a crash.

          I had once to debug a strange crash that in the end was due to a missing return statement for a QString and the return value wasn't even used. For the fun of experimenting, I changed the return type to int and no crash anymore. That's what undefined behaviour is. That took me quite a while to find because the original warning was swamped in a tons of other warnings (words of the original developer: don't care these are just warnings), the return value being ignored, I did not take notice immediately that the return statement was missing and the code was so involved that tracing the crash correctly was pretty hard as is also required external hardware (

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #22

          @SGaist said in QFile::close() leads to SIGILL:

          Strictly speaking it's not undefined behaviour. You will print a random value from an uninitialized int variable.

          "No", that's what I was saying, but I think you are "incorrect" here! [Hesitant, you usually shoot me down, fools rush in where... :) ]

          The best "official" I can find is https://en.cppreference.com/w/cpp/language/ub. Note the difference between

          • unspecified behavior: Each unspecified behavior results in one of a set of valid results.

          • undefined behavior: there are no restrictions on the behavior of the program

          Then note that (confusingly) it uses the abbreviation UB, which if you read carefully is the undefined rather than the unspecified behaviour. I take this from:

          Because correct C++ programs are free of undefined behavior, compilers may produce unexpected results when a program that actually has UB

          Hence I understand UB == undefined behaviour. Then proceed to the examples.

              std::size_t a;
              if(x) // either x nonzero or UB
                  a = 42;
          

          and

          bool p; // uninitialized local variable
          if(p) // UB access to uninitialized scalar
              std::puts("p is true");
          if(!p) // UB access to uninitialized scalar
              std::puts("p is false");
          

          So if UB == undefined behaviour, they are saying these could "crash". Otherwise you have to show that this UB == unspecified behaviour, which I do not see from the text I quoted. That's my reading, don't you think?

          1 Reply Last reply
          1
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #23

            @JonB said in QFile::close() leads to SIGILL:

            they are saying these could "crash".

            Correct, since x is not defined the compiler may decided to e.g. throw an exception, quit the program or simply use the value which it finds at the specified address.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            JonBJ 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              @JonB said in QFile::close() leads to SIGILL:

              they are saying these could "crash".

              Correct, since x is not defined the compiler may decided to e.g. throw an exception, quit the program or simply use the value which it finds at the specified address.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #24

              @Christian-Ehrlicher
              Going all the way back to the @Sedi's original

              Qt 5.15.0 for Android, working on a Win10 machine

              Purely OOI, what compiler does this mean he will be using? It would be interesting to see from one of those "web public compilers" what code it generates that leads to SIGILL....

              1 Reply Last reply
              1
              • Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by Christian Ehrlicher
                #25

                I would guess it's clang: https://godbolt.org/z/qGaKeM
                /edit: msvc doesn't even compile it

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                JonBJ SeDiS 2 Replies Last reply
                3
                • Christian EhrlicherC Christian Ehrlicher

                  I would guess it's clang: https://godbolt.org/z/qGaKeM
                  /edit: msvc doesn't even compile it

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #26

                  @Christian-Ehrlicher
                  Thanks Christian. That "Compiler Explorer" site doesn't seem to be one which has an option of running code? Do you know of one which offers the necessary compiler but also runs code? I'd like to see that SIGILL actually happen, as per the OP :)

                  Or, failing that, can you explain what instruction in the generated code would actually cause it? Remember, the OP doesn't actually use the returned result from the function (which doesn't return a result), his case is just supposed to be:

                  bool func()
                  {
                  }
                  
                  void main()
                  {
                    func();
                  }
                  
                  1 Reply Last reply
                  1
                  • Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by Christian Ehrlicher
                    #27

                    @JonB said in QFile::close() leads to SIGILL:

                    Or, failing that, can you explain what instruction in the generated code would actually cause it?

                    Simply take a look at the godbolt assembler output and read the tooltip :)

                    doSomething():                       # @doSomething()
                            push    rbp
                            mov     rbp, rsp
                            ud2
                    

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    JonBJ 1 Reply Last reply
                    2
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #28

                      @JonB said in QFile::close() leads to SIGILL:

                      "No", that's what I was saying, but I think you are "incorrect" here! [Hesitant, you usually shoot me down, fools rush in where... :) ]

                      I see your point now. Semantic is quite complex and your analysis is correct :-)
                      Undefined VS Unspecified and then using an abreviation that fits both is not really a good idea when documenting something.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      JonBJ 1 Reply Last reply
                      2
                      • SGaistS SGaist

                        @JonB said in QFile::close() leads to SIGILL:

                        "No", that's what I was saying, but I think you are "incorrect" here! [Hesitant, you usually shoot me down, fools rush in where... :) ]

                        I see your point now. Semantic is quite complex and your analysis is correct :-)
                        Undefined VS Unspecified and then using an abreviation that fits both is not really a good idea when documenting something.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #29

                        @SGaist said in QFile::close() leads to SIGILL:

                        Undefined VS Unspecified and then using an abreviation that fits both is not really a good idea when documenting something.

                        100% !

                        1 Reply Last reply
                        1
                        • Christian EhrlicherC Christian Ehrlicher

                          @JonB said in QFile::close() leads to SIGILL:

                          Or, failing that, can you explain what instruction in the generated code would actually cause it?

                          Simply take a look at the godbolt assembler output and read the tooltip :)

                          doSomething():                       # @doSomething()
                                  push    rbp
                                  mov     rbp, rsp
                                  ud2
                          
                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #30

                          @Christian-Ehrlicher said in QFile::close() leads to SIGILL:

                          Simply take a look at the godbolt assembler output and read the tooltip :)

                          Wow! Just wow! Well, I certainly do see how the compiler has gone out of its way to let me drop into a SIGILL when I fail to return something :)

                          1 Reply Last reply
                          1
                          • Christian EhrlicherC Christian Ehrlicher

                            I would guess it's clang: https://godbolt.org/z/qGaKeM
                            /edit: msvc doesn't even compile it

                            SeDiS Offline
                            SeDiS Offline
                            SeDi
                            wrote on last edited by
                            #31

                            @Christian-Ehrlicher said in QFile::close() leads to SIGILL:

                            I would guess it's clang: https://godbolt.org/z/qGaKeM

                            You are right. Sorry for the delay, after setting the thread to "solved" I didn't ever look into it until I just now noticed this little red warning about unread messages :-)

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved