title: Can I force Rust to not optimize a single function?
body: <p>I have a function where Rust's/LLVM's optimization fails and leads to a panic (in the release version), while the unoptimized code (debug version) just works fine. If I compare the generated assembly code, I can not even grasp an idea what the optimizer tries to accomplish.
  (A reason might be that this very function uses inline assembler.)</p>
  
  <p>Is there any way to tell Rust to leave certain functions alone during the optimisation, or do I have to switch off all optimizations?</p>
  
  <p>Here is the specific function:</p>
  
  <pre><code>#[naked]
  pub extern "C" fn dispatch_svc(){
      Cpu::save_context();
      let mut nr: u32 = 0;
      unsafe {
          asm!("ldr r0, [lr, #-4]
                bic $0, r0, #0xff000000":"=r"(nr)::"r0":"volatile")
      };
      swi_service_routine(nr);
      Cpu::restore_context_and_return();
  }
  </code></pre>