Issue 71411
Summary Clang 15 is not triggering a dangling reference indicating stack use after return with -fsanitize=address and optimization
Labels clang
Assignees
Reporter mohamed-ai-selim
    In scenario A:
The following code doesn't trigger warning -Wreturn-stack-address as expected, indicating a dangling reference to stack after return. Yet upon running the sanitizer, it triggers the **runtime error stack-use-after-return**. So it might has something to do with dangling reference from outer types e.g. std::reference_wrapper

Scenario B:
Clang triggers the warning as expected, as well as the sanitizer

N.B. in gcc the warning is triggered as expected.
```

#include <iostream>
#include <functional>

// scenario A
const int& foo()
{
    int x = 234;
    std::reference_wrapper<int> s{x};
   
    return s.get();
}

// scenario B
/*
const int& foo()
{
    int s = 234;   
    return s;
}*/

// clang: clang++-15 -o test main.cpp -std=c++14 -Wdangling-field -Wdangling-initializer-list -Wdangling -Wdangling-gsl -Wreturn-stack-address -fsanitize=address
// gcc: g++-10 -o test main.cpp -std=c++14 -Wframe-address -Wreturn-local-addr -O3
int main()
{
    const auto& f_res = foo();
    std::cout << "result: " << f_res << "\n";
    
    return 0;
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to