Paul Muntean via llvm-dev
2016-Dec-21 10:47 UTC
[llvm-dev] *********How to get during compile time the base class of casted C++ object inside static_cast<> and dynamic_cast<> and the pointer of the casted object
I want to detect bad casts in C++ code by using the Clang compiler. The approach is similar to what Caver and TypeSan do but without using the compiler-rt. Caver and TypeSan: https://www.usenix.org/system/files/conference/usenixsecurity15/sec15-paper-lee.pdf https://nebelwelt.net/publications/files/16CCS2.pdf For example if I have the following C++ code snippet where I want to cast object b into object D. D* obj = static_cast<D*>(b); from where (inside Clang, LTO, thinLTO, etc.) can I get the base class of D and the base class ob b. Is this available in the Clang compiler or LTO? Also, if b is an object of a virtual Class (class with inherited or its own virtual functions) can I get its virtual pointer at compile time by using the LTO? I found out that in CodeGen/CGExpr.cpp the explicit case "BaseToDerived" is handled and you can retrieve TypeSourceInfo using the function getTypeInfoAsWritten(). It seems that this information is enough to get the exact type of this cast at compile-time and should also work for Template programming, as my, understanding is that Clang should have abstracted the code into, specific types at this point. Am I wrong here? Is there any case where the type of the objects used inside the cast not known at compile time? Can the, 'real' type be hidden behind a pointer?
Mehdi Amini via llvm-dev
2016-Dec-21 16:31 UTC
[llvm-dev] *********How to get during compile time the base class of casted C++ object inside static_cast<> and dynamic_cast<> and the pointer of the casted object
Hi Paul, It is the 4th time in two weeks that you repost the exact same two emails, that’s a bit high repost rate for the mailing-list, especially considering that you already got answers that you ignored previously: - http://lists.llvm.org/pipermail/llvm-dev/2016-December/108060.html - http://lists.llvm.org/pipermail/llvm-dev/2016-December/108051.html Adding an alternate email in case you didn’t receive previous emails. Best, — Mehdi> On Dec 21, 2016, at 2:47 AM, Paul Muntean via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > I want to detect bad casts in C++ code by using the Clang > compiler. The approach is similar to what Caver and TypeSan do but > without using the compiler-rt. > > Caver and TypeSan: > https://www.usenix.org/system/files/conference/usenixsecurity15/sec15-paper-lee.pdf > https://nebelwelt.net/publications/files/16CCS2.pdf > > For example if I have the following C++ code snippet where I want to > cast object b into > object D. > > D* obj = static_cast<D*>(b); > > from where (inside Clang, LTO, thinLTO, etc.) can I get the base class > of D and the base class ob b. Is this > available in the Clang compiler or LTO? > > Also, if b is an object of a virtual Class (class with inherited or its > own virtual functions) can I get its virtual pointer at compile time > by using the LTO? > > I found out that in CodeGen/CGExpr.cpp the explicit case "BaseToDerived" is > handled and you can retrieve TypeSourceInfo using the function > getTypeInfoAsWritten(). It seems that this information is enough to get > the exact type of this cast at compile-time and should also work for > Template programming, as my, understanding is that Clang should have > abstracted the code into, specific types at this point. > > Am I wrong here? > > Is there any case where the type of the objects used inside the cast > not known at compile time? Can the, > 'real' type be hidden behind a pointer? > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161221/fda56cbe/attachment.html>
Paul via llvm-dev
2016-Dec-21 16:38 UTC
[llvm-dev] *********How to get during compile time the base class of casted C++ object inside static_cast<> and dynamic_cast<> and the pointer of the casted object
Hi Mehdi, thanks a lot for your email. Actually I was disappointed by the fact that I was not able to get a useful answer to my two questions. As I observed that the questions move down along the list with time passing I decided to re-post them in the hope that the questions will have a better visibility. Could you help me with the two questions? Finding an expert in this area would be of great help. Do you think the questions are not well stated. Regards Paul On 12/21/2016 05:31 PM, Mehdi Amini wrote:> Hi Paul, > > It is the 4th time in two weeks that you repost the exact same two > emails, that’s a bit high repost rate for the mailing-list, especially > considering that you already got answers that you ignored previously: > > - http://lists.llvm.org/pipermail/llvm-dev/2016-December/108060.html > - http://lists.llvm.org/pipermail/llvm-dev/2016-December/108051.html > > Adding an alternate email in case you didn’t receive previous emails. > Best, > > > — > Mehdi > > > > >> On Dec 21, 2016, at 2:47 AM, Paul Muntean via llvm-dev >> <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote: >> >> I want to detect bad casts in C++ code by using the Clang >> compiler. The approach is similar to what Caver and TypeSan do but >> without using the compiler-rt. >> >> Caver and TypeSan: >> https://www.usenix.org/system/files/conference/usenixsecurity15/sec15-paper-lee.pdf >> https://nebelwelt.net/publications/files/16CCS2.pdf >> >> For example if I have the following C++ code snippet where I want to >> cast object b into >> object D. >> >> D* obj = static_cast<D*>(b); >> >> from where (inside Clang, LTO, thinLTO, etc.) can I get the base class >> of D and the base class ob b. Is this >> available in the Clang compiler or LTO? >> >> Also, if b is an object of a virtual Class (class with inherited or its >> own virtual functions) can I get its virtual pointer at compile time >> by using the LTO? >> >> I found out that in CodeGen/CGExpr.cpp the explicit case >> "BaseToDerived" is >> handled and you can retrieve TypeSourceInfo using the function >> getTypeInfoAsWritten(). It seems that this information is enough to get >> the exact type of this cast at compile-time and should also work for >> Template programming, as my, understanding is that Clang should have >> abstracted the code into, specific types at this point. >> >> Am I wrong here? >> >> Is there any case where the type of the objects used inside the cast >> not known at compile time? Can the, >> 'real' type be hidden behind a pointer? >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-- Paul Muntean Lehrstuhl für Sicherheit in der Informatik, I20 Prof. Dr. Claudia Eckert Institut für Informatik TU-München Boltzmannstr. 3, 85748 Garching, Germany Tel.: ++49 (89) 289 - 18566 Fax : ++49 (89) 289 - 18579 Room: 01.08.055 E-Mail: paul at sec.in.tum.de https://www.sec.in.tum.de -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161221/c247a059/attachment.html>
Seemingly Similar Threads
- help needed: How to get during compile time the base class of casted C++ object inside static_cast<> and dynamic_cast<> and the pointer of the casted object
- *********How to get during compile time the base class of casted C++ object inside static_cast<> and dynamic_cast<> and the pointer of the casted object
- *********How to get during compile time the base class of casted C++ object inside static_cast<> and dynamic_cast<> and the pointer of the casted object
- Help needed: How to get during compile time the base class of casted C++ object inside static_cast<> and dynamic_cast<> and the pointer of the casted object
- *********How to get during compile time the base class of casted C++ object inside static_cast<> and dynamic_cast<> and the pointer of the casted object