Clang AST区分隐式int和无效类型

时间:2017-03-10 11:28:14

标签: c++ abstract-syntax-tree clang++ llvm-clang libtooling

我正在使用clang和前端以及RecursiveASTVisitor处理clang lib-tooling项目。

以下代码(来自llvm-clang测试)

// RUN: %clang_cc1 -fsyntax-only %s -verify -pedantic

foo() { // expected-warning {{type specifier missing, defaults to 'int'}}
  return 0;
}

y;  // expected-warning {{type specifier missing, defaults to 'int'}}

Sample sam;

// rdar://6131634
void f((x));  // expected-warning {{type specifier missing, defaults to 'int'}}


// PR3702
#define PAD(ms10) { \
    register i;     \
}

#define ILPAD() PAD((NROW - tt.tt_row) * 10) /* 1 ms per char */

void
h19_insline(n)  // expected-warning {{parameter 'n' was not declared, defaulting to type 'int'}}
{
  ILPAD();  // expected-warning {{type specifier missing, defaults to 'int'}}
}

struct foo {
 __extension__ __attribute__((packed)) x : 4; // expected-warning {{type specifier missing, defaults to 'int'}}
};

以上代码的AST是

enter image description here

如您所见,AST变量 sam 被标记为无效,而变量 y 则不是两个变量都默认为int。当我使用RecursiveASTVisitor遍历声明时,我将两个声明都视为无效。

现在的问题是如何区分这两个声明,因为y是隐式int 而sam是 unresolved

有没有人遇到过这样的问题?

0 个答案:

没有答案