line_debug_info_test.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright (c) 2016 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "test/opt/pass_fixture.h"
  15. #include "test/opt/pass_utils.h"
  16. namespace spvtools {
  17. namespace opt {
  18. namespace {
  19. // A pass turning all none debug line instructions into Nop.
  20. class NopifyPass : public Pass {
  21. public:
  22. const char* name() const override { return "NopifyPass"; }
  23. Status Process() override {
  24. bool modified = false;
  25. context()->module()->ForEachInst(
  26. [&modified](Instruction* inst) {
  27. inst->ToNop();
  28. modified = true;
  29. },
  30. /* run_on_debug_line_insts = */ false);
  31. return modified ? Status::SuccessWithChange : Status::SuccessWithoutChange;
  32. }
  33. };
  34. using PassTestForLineDebugInfo = PassTest<::testing::Test>;
  35. // This test's purpose to show our implementation choice: line debug info is
  36. // preserved even if the following instruction is killed. It serves as a guard
  37. // of potential behavior changes.
  38. TEST_F(PassTestForLineDebugInfo, KeepLineDebugInfo) {
  39. // clang-format off
  40. const char* text =
  41. "OpCapability Shader "
  42. "%1 = OpExtInstImport \"GLSL.std.450\" "
  43. "OpMemoryModel Logical GLSL450 "
  44. "OpEntryPoint Vertex %2 \"main\" "
  45. "%3 = OpString \"minimal.vert\" "
  46. "OpNoLine "
  47. "OpLine %3 10 10 "
  48. "%void = OpTypeVoid "
  49. "OpLine %3 100 100 "
  50. "%5 = OpTypeFunction %void "
  51. "%2 = OpFunction %void None %5 "
  52. "OpLine %3 1 1 "
  53. "OpNoLine "
  54. "OpLine %3 2 2 "
  55. "OpLine %3 3 3 "
  56. "%6 = OpLabel "
  57. "OpLine %3 4 4 "
  58. "OpNoLine "
  59. "OpReturn "
  60. "OpLine %3 4 4 "
  61. "OpNoLine "
  62. "OpFunctionEnd ";
  63. // clang-format on
  64. const char* result_keep_nop =
  65. "OpNop\n"
  66. "OpNop\n"
  67. "OpNop\n"
  68. "OpNop\n"
  69. "OpNop\n"
  70. "OpNoLine\n"
  71. "OpLine %3 10 10\n"
  72. "OpNop\n"
  73. "OpLine %3 100 100\n"
  74. "OpNop\n"
  75. "OpNop\n"
  76. "OpLine %3 1 1\n"
  77. "OpNoLine\n"
  78. "OpLine %3 2 2\n"
  79. "OpLine %3 3 3\n"
  80. "OpNop\n"
  81. "OpLine %3 4 4\n"
  82. "OpNoLine\n"
  83. "OpNop\n"
  84. "OpLine %3 4 4\n"
  85. "OpNoLine\n"
  86. "OpNop\n";
  87. SinglePassRunAndCheck<NopifyPass>(text, result_keep_nop,
  88. /* skip_nop = */ false);
  89. const char* result_skip_nop =
  90. "OpNoLine\n"
  91. "OpLine %3 10 10\n"
  92. "OpLine %3 100 100\n"
  93. "OpLine %3 1 1\n"
  94. "OpNoLine\n"
  95. "OpLine %3 2 2\n"
  96. "OpLine %3 3 3\n"
  97. "OpLine %3 4 4\n"
  98. "OpNoLine\n"
  99. "OpLine %3 4 4\n"
  100. "OpNoLine\n";
  101. SinglePassRunAndCheck<NopifyPass>(text, result_skip_nop,
  102. /* skip_nop = */ true);
  103. }
  104. } // namespace
  105. } // namespace opt
  106. } // namespace spvtools