mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-08 00:35:49 +02:00
Support for __builtinOffsetof, bug 265001.
This commit is contained in:
parent
9c8ddfd6ba
commit
4db2416905
4 changed files with 36 additions and 4 deletions
|
@ -381,4 +381,31 @@ public class GCCCompleteParseExtensionsTest extends AST2BaseTest {
|
|||
parseGPP( writer.toString() );
|
||||
}
|
||||
|
||||
// typedef int size_t; // will be defined in <stddef.h>
|
||||
// struct S {int m;};
|
||||
// void test() {
|
||||
// int a= __builtin_offsetof(struct S, m);
|
||||
// };
|
||||
public void test__builtinOffsetof_Bug265001() throws Exception {
|
||||
// gcc with __GNUC__ >= 4 defines:
|
||||
// #define offsetof(type, field) __builtin_offsetof(type, field)
|
||||
|
||||
String code= getAboveComment();
|
||||
parseGCC(code);
|
||||
parseGPP(code);
|
||||
}
|
||||
|
||||
// typedef struct S {int m;} T;
|
||||
// void test() {
|
||||
// int a= __offsetof__(1);
|
||||
// };
|
||||
public void test__offsetof__Bug265001() throws Exception {
|
||||
// gcc with __GNUC__ < 4 defines:
|
||||
// #define offsetof(type, field) \
|
||||
// (__offsetof__ (reinterpret_cast <__size_t> \
|
||||
// (& reinterpret_cast <const volatile char &> \
|
||||
// (static_cast<type *> (0)->field))))
|
||||
String code= getAboveComment();
|
||||
parseGPP(code);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,8 @@ public abstract class GNUScannerExtensionConfiguration extends AbstractScannerEx
|
|||
addMacro("__builtin_va_arg(ap,type)", "*(type *)ap");
|
||||
addMacro("__builtin_constant_p(exp)", "0");
|
||||
addMacro("__builtin_types_compatible_p(x,y)", "__builtin_types_compatible_p(sizeof(x),sizeof(y))");
|
||||
|
||||
addMacro("__offsetof__(x)", "(x)");
|
||||
|
||||
addPreprocessorKeyword(Keywords.cINCLUDE_NEXT, IPreprocessorDirective.ppInclude_next);
|
||||
addPreprocessorKeyword(Keywords.cIMPORT, IPreprocessorDirective.ppImport);
|
||||
addPreprocessorKeyword(Keywords.cWARNING, IPreprocessorDirective.ppWarning);
|
||||
|
|
|
@ -28,9 +28,11 @@ public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfigu
|
|||
return sInstance;
|
||||
}
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public GCCScannerExtensionConfiguration() {
|
||||
addMacro("__null", "(void *)0"); //$NON-NLS-1$//$NON-NLS-2$
|
||||
addMacro("_Pragma(arg)", ""); //$NON-NLS-1$//$NON-NLS-2$
|
||||
addMacro("__null", "(void *)0");
|
||||
addMacro("_Pragma(arg)", "");
|
||||
addMacro("__builtin_offsetof(T,m)", "((size_t) &((T *)0)->m)");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -31,8 +31,10 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
|
|||
return sInstance;
|
||||
}
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public GPPScannerExtensionConfiguration() {
|
||||
addMacro("__null", "0"); //$NON-NLS-1$//$NON-NLS-2$
|
||||
addMacro("__null", "0");
|
||||
addMacro("__builtin_offsetof(T,m)", "(reinterpret_cast <size_t>(&reinterpret_cast <const volatile char &>(static_cast<T*> (0)->m)))");
|
||||
addKeyword(Keywords.c_COMPLEX, IToken.t__Complex);
|
||||
addKeyword(Keywords.c_IMAGINARY, IToken.t__Imaginary);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue