当前位置: 首页 > news >正文

llvm向用户抛出warning、error信息

1、抛出error信息并终止程序

使用DiagnosticInfoUnsupported可以向用户抛出error信息并且终止程序,效果如同report_fatal_error、Error。后端用法如下:

void xxxx::reportErrorMsg(const MachineFunction &MF)const {const Function &F = MF.getFunction();// Diagnostic information for unsupported feature in backend.F.getContext().diagnose(DiagnosticInfoUnsupported{F, "report msg."});
}

2、优化pass中抛出警告信息之OptimizationRemark

使用时clang得加上-Rpass=name,llc得加上–pass-remarks=name才行,后端用法如下:

#include "llvm/Analysis/OptimizationRemarkEmitter.h"void getAnalysisUsage(AnalysisUsage &AU) const override {AU.addRequired<OptimizationRemarkEmitterWrapperPass>();MachineFunctionPass::getAnalysisUsage(AU);}
void xxx::reportWarningMsg(const MachineFunction &MF)const {auto *ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();const Function &F = MF.getFunction();// Diagnostic information for applied optimization remarksOptimizationRemark R(DEBUG_TYPE, "replace-spill-register", &F);R << "report msg";ORE->emit(R);
}

3、machine ir抛信息之DiagnosticInfoMIRParser

该接口同样支持DS_Error,DS_Warning,DS_Remark和DS_Note 4种方式,后端用法如下:

#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/Support/SourceMgr.h"
void xxx::reportWarningMsg(const MachineFunction &MF)const {const Function &F = MF.getFunction();// Diagnostic information for machine IR parser.F.getContext().diagnose(DiagnosticInfoMIRParser(DS_Warning,SMDiagnostic(DEBUG_TYPE, SourceMgr::DK_Warning, "report msg")));
}

4、AsmParser之Warning

基本用法如下:

XXXAsmParser &Parser;
void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }

5、MCContext之reportWarning

基本用法如下:

MCContext &Context;
void MCContext::reportWarning(SMLoc Loc, const Twine &Msg)
Context.reportWarning(MCxxx.getLoc(), Msg);

6、其它类型的信息

包括DiagnosticInfoInlineAsm,DiagnosticInfoResourceLimit,DiagnosticInfoStackSize,DiagnosticInfoOptimizationBase,DiagnosticInfoIROptimization以及debug,Profileing,remarks等。

  1. 其中llvm_unreachable为开发者使用,发布时用户不可见,所看到的信息为segment fatal。
  2. assert由于存在判断开销,一般也不在发布中开启。

7、用例如何检查report_fatal_error

  1. RUN命令需要使用not,用法如下:
// RUN: not %clang --target=xx -mcpu=xxx -O3 -c %s -o - 2>&1 | FileCheck %s --check-prefix=expected-error
....
// expected-error: xxxx
  1. 使用-fsyntax-only -verify,用法如下:
// RUN: %clang_cc1 -triple xxx  -target-feature xx -fsyntax-only -verify %s
// expected-warning{{xxxxxxxx}} expected-error{{xxxxxxxxxxxxxxx}}
http://www.lryc.cn/news/96910.html

相关文章:

  • 微服务学习笔记-----Nacos安装教程(Windows和Linux版本)
  • 程序员面试系列,docker常见面试题
  • Linux centos7.x系统将/home磁盘分配给/
  • 根据数组元素为对象,对元素对象的某一属性进行排序
  • mysql(三)用户权限管理
  • 字节JAVA岗位面试总结汇总
  • 29-使用RocketMQ做削峰处理
  • ELK 使用kibana查询和分析nginx日志
  • mybatisplus自定义xml的sql语句进行自动分页
  • ChatGPT:人工智能开启智能交流新篇章
  • 关于anki的一些思考
  • 【动态规划刷题 1 】 第N个泰波那契数 三步问题
  • 【踩坑】三种方式解决 Homebrew failing to install - fatal: not in a git directory
  • 零信任安全解决方案
  • 如何创建高级 CSS 下拉菜单
  • java中判断list是否为空
  • 龙芯3A5000板卡在高性能工作站的应用方案-迅为电子
  • WebSocket心跳机制
  • Form Generator 扩展子表单组件之表单校验(超详细)
  • HTTPS安全套接字层超文本传输协议
  • Jenkins发送的邮箱中没有带配置的压缩附件
  • VU3-02
  • Linux新手小程序——进度条
  • 会点C++还需要再学Python吗?
  • Ceph入门到精通- Linux 磁盘管理(block 与 inode)
  • 安全DNS,状态码,编码笔记整理
  • 【业务功能篇53】Springboot 数据封装对象
  • 将Spring Session存储到Redis中实现持久化
  • Git工作中常用命令
  • 【电路效应】信号处理和通信系统模型中的模拟电路效应研究(SimulinkMatlab代码实现)