MicrosoftCXXABI.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //===--- MicrosoftCXXABI.cpp - Emit LLVM Code from ASTs for a Module ------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This provides C++ code generation targeting the Microsoft Visual C++ ABI.
  11. // The class in this file generates structures that follow the Microsoft
  12. // Visual C++ ABI, which is actually not very well documented at all outside
  13. // of Microsoft.
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #include "CGCXXABI.h"
  17. #include "CodeGenModule.h"
  18. #include "clang/AST/Decl.h"
  19. #include "clang/AST/DeclCXX.h"
  20. using namespace clang;
  21. using namespace CodeGen;
  22. namespace {
  23. class MicrosoftCXXABI : public CGCXXABI {
  24. public:
  25. MicrosoftCXXABI(CodeGenModule &CGM) : CGCXXABI(CGM) {}
  26. void BuildConstructorSignature(const CXXConstructorDecl *Ctor,
  27. CXXCtorType Type,
  28. CanQualType &ResTy,
  29. SmallVectorImpl<CanQualType> &ArgTys) {
  30. // 'this' is already in place
  31. // TODO: 'for base' flag
  32. }
  33. void BuildDestructorSignature(const CXXDestructorDecl *Ctor,
  34. CXXDtorType Type,
  35. CanQualType &ResTy,
  36. SmallVectorImpl<CanQualType> &ArgTys) {
  37. // 'this' is already in place
  38. // TODO: 'for base' flag
  39. }
  40. void BuildInstanceFunctionParams(CodeGenFunction &CGF,
  41. QualType &ResTy,
  42. FunctionArgList &Params) {
  43. BuildThisParam(CGF, Params);
  44. // TODO: 'for base' flag
  45. }
  46. void EmitInstanceFunctionProlog(CodeGenFunction &CGF) {
  47. EmitThisParam(CGF);
  48. // TODO: 'for base' flag
  49. }
  50. // ==== Notes on array cookies =========
  51. //
  52. // MSVC seems to only use cookies when the class has a destructor; a
  53. // two-argument usual array deallocation function isn't sufficient.
  54. //
  55. // For example, this code prints "100" and "1":
  56. // struct A {
  57. // char x;
  58. // void *operator new[](size_t sz) {
  59. // printf("%u\n", sz);
  60. // return malloc(sz);
  61. // }
  62. // void operator delete[](void *p, size_t sz) {
  63. // printf("%u\n", sz);
  64. // free(p);
  65. // }
  66. // };
  67. // int main() {
  68. // A *p = new A[100];
  69. // delete[] p;
  70. // }
  71. // Whereas it prints "104" and "104" if you give A a destructor.
  72. };
  73. }
  74. CGCXXABI *clang::CodeGen::CreateMicrosoftCXXABI(CodeGenModule &CGM) {
  75. return new MicrosoftCXXABI(CGM);
  76. }