brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 17bfe17 Raw
68 lines · cpp
1//=== unittests/CodeGen/DemangleTrapReasonInDebugInfo.cpp -----------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "clang/CodeGen/ModuleBuilder.h"10#include "llvm/ADT/StringRef.h"11#include "gtest/gtest.h"12 13using namespace clang::CodeGen;14 15void CheckValidCommon(llvm::StringRef FuncName, const char *ExpectedCategory,16                      const char *ExpectedMessage) {17  auto MaybeTrapReason = DemangleTrapReasonInDebugInfo(FuncName);18  ASSERT_TRUE(MaybeTrapReason.has_value());19  auto [Category, Message] = MaybeTrapReason.value();20  ASSERT_STREQ(Category.str().c_str(), ExpectedCategory);21  ASSERT_STREQ(Message.str().c_str(), ExpectedMessage);22}23 24void CheckInvalidCommon(llvm::StringRef FuncName) {25  auto MaybeTrapReason = DemangleTrapReasonInDebugInfo(FuncName);26  ASSERT_TRUE(!MaybeTrapReason.has_value());27}28 29TEST(DemangleTrapReasonInDebugInfo, Valid) {30  std::string FuncName(ClangTrapPrefix);31  FuncName += "$trap category$trap message";32  CheckValidCommon(FuncName, "trap category", "trap message");33}34 35TEST(DemangleTrapReasonInDebugInfo, ValidEmptyCategory) {36  std::string FuncName(ClangTrapPrefix);37  FuncName += "$$trap message";38  CheckValidCommon(FuncName, "", "trap message");39}40 41TEST(DemangleTrapReasonInDebugInfo, ValidEmptyMessage) {42  std::string FuncName(ClangTrapPrefix);43  FuncName += "$trap category$";44  CheckValidCommon(FuncName, "trap category", "");45}46 47TEST(DemangleTrapReasonInDebugInfo, ValidAllEmpty) {48  //  `__builtin_verbose_trap` actually allows this49  // currently. However, we should probably disallow this in Sema because having50  // an empty category and message completely defeats the point of using the51  // builtin (#165981).52  std::string FuncName(ClangTrapPrefix);53  FuncName += "$$";54  CheckValidCommon(FuncName, "", "");55}56 57TEST(DemangleTrapReasonInDebugInfo, InvalidOnlyPrefix) {58  std::string FuncName(ClangTrapPrefix);59  CheckInvalidCommon(FuncName);60}61 62TEST(DemangleTrapReasonInDebugInfo, Invalid) {63  std::string FuncName("foo");64  CheckInvalidCommon(FuncName);65}66 67TEST(DemangleTrapReasonInDebugInfo, InvalidEmpty) { CheckInvalidCommon(""); }68