modernc.org/ccgo/v3@v3.16.14/lib/testdata/bug/sqlite2.c (about) 1 typedef struct Expr Expr; 2 typedef struct Table Table; 3 typedef struct Column Column; 4 5 struct Column { 6 char *zName; /* Name of this column, \000, then the type */ 7 Expr *pDflt; /* Default value of this column */ 8 char *zColl; /* Collating sequence. If NULL, use the default */ 9 unsigned char notNull; /* An OE_ code for handling a NOT NULL constraint */ 10 char affinity; /* One of the SQLITE_AFF_... values */ 11 unsigned char szEst; /* Estimated size of value in this column. sizeof(INT)==1 */ 12 unsigned char colFlags; /* Boolean properties. See COLFLAG_ defines below */ 13 }; 14 15 struct Table { 16 char *zName; /* Name of the table or view */ 17 Column *aCol; /* Information about each column */ 18 void /*Index*/ *pIndex; /* List of SQL indexes on this table. */ 19 void /*Select*/ *pSelect; /* NULL for tables. Points to definition if a view. */ 20 void /*FKey*/ *pFKey; /* Linked list of all foreign keys in this table */ 21 char *zColAff; /* String defining the affinity of each column */ 22 void /*ExprList*/ *pCheck; /* All CHECK constraints */ 23 /* ... also used as column name list in a VIEW */ 24 int tnum; /* Root BTree page for this table */ 25 unsigned nTabRef; /* Number of pointers to this Table */ 26 unsigned tabFlags; /* Mask of TF_* values */ 27 short iPKey; /* If not negative, use aCol[iPKey] as the rowid */ 28 short nCol; /* Number of columns in this table */ 29 int /*LogEst*/ nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */ 30 int /*LogEst*/ szTabRow; /* Estimated size of each table row in bytes */ 31 #ifdef SQLITE_ENABLE_COSTMULT 32 int /*LogEst*/ costMult; /* Cost multiplier for using this table */ 33 #endif 34 unsigned char keyConf; /* What to do in case of uniqueness conflict on iPKey */ 35 #ifndef SQLITE_OMIT_ALTERTABLE 36 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */ 37 #endif 38 #ifndef SQLITE_OMIT_VIRTUALTABLE 39 int nModuleArg; /* Number of arguments to the module */ 40 char **azModuleArg; /* 0: module 1: schema 2: vtab name 3...: args */ 41 void /*VTable*/ *pVTable; /* List of VTable objects. */ 42 #endif 43 void /*Trigger*/ *pTrigger; /* List of triggers stored in pSchema */ 44 void /*Schema*/ *pSchema; /* Schema that contains this table */ 45 Table *pNextZombie; /* Next on the Parse.pZombieTab list */ 46 }; 47 48 struct Expr { 49 unsigned char op; /* Operation performed by this node */ 50 char affExpr; /* affinity, or RAISE type */ 51 unsigned flags; /* Various flags. EP_* See below */ 52 union { 53 char *zToken; /* Token value. Zero terminated and dequoted */ 54 int iValue; /* Non-negative integer value if EP_IntValue */ 55 } u; 56 57 /* If the EP_TokenOnly flag is set in the Expr.flags mask, then no 58 ** space is allocated for the fields below this point. An attempt to 59 ** access them will result in a segfault or malfunction. 60 *********************************************************************/ 61 62 Expr *pLeft; /* Left subnode */ 63 Expr *pRight; /* Right subnode */ 64 union { 65 void /*ExprList*/ *pList; /* op = IN, EXISTS, SELECT, CASE, FUNCTION, BETWEEN */ 66 void /*Select*/ *pSelect; /* EP_xIsSelect and op = IN, EXISTS, SELECT */ 67 } x; 68 69 /* If the EP_Reduced flag is set in the Expr.flags mask, then no 70 ** space is allocated for the fields below this point. An attempt to 71 ** access them will result in a segfault or malfunction. 72 *********************************************************************/ 73 74 #if SQLITE_MAX_EXPR_DEPTH>0 75 int nHeight; /* Height of the tree headed by this node */ 76 #endif 77 int iTable; /* TK_COLUMN: cursor number of table holding column 78 ** TK_REGISTER: register number 79 ** TK_TRIGGER: 1 -> new, 0 -> old 80 ** EP_Unlikely: 134217728 times likelihood 81 ** TK_IN: ephemerial table holding RHS 82 ** TK_SELECT_COLUMN: Number of columns on the LHS 83 ** TK_SELECT: 1st register of result vector */ 84 int /*ynVar*/ iColumn; /* TK_COLUMN: column index. -1 for rowid. 85 ** TK_VARIABLE: variable number (always >= 1). 86 ** TK_SELECT_COLUMN: column of the result vector */ 87 short iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ 88 short iRightJoinTable; /* If EP_FromJoin, the right table of the join */ 89 unsigned char op2; /* TK_REGISTER/TK_TRUTH: original value of Expr.op 90 ** TK_COLUMN: the value of p5 for OP_Column 91 ** TK_AGG_FUNCTION: nesting depth */ 92 void /*AggInfo*/ *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ 93 union { 94 Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL 95 ** for a column of an index on an expression */ 96 void /*Window*/ *pWin; /* EP_WinFunc: Window/Filter defn for a function */ 97 struct { /* TK_IN, TK_SELECT, and TK_EXISTS */ 98 int iAddr; /* Subroutine entry address */ 99 int regReturn; /* Register used to hold return address */ 100 } sub; 101 } y; 102 }; 103 104 void f1(Column c) { 105 __builtin_printf("%i: c.zColl %s\n", __LINE__, c.zColl); 106 } 107 108 void f2(Column *cols) { 109 __builtin_printf("%i: cols[1].zColl %s\n", __LINE__, cols[1].zColl); 110 } 111 112 Table table; 113 114 Table *pTab = &table; 115 116 void f3(Table *pTab) { 117 __builtin_printf("%i: pTab->aCol[1].zColl %s\n", __LINE__, pTab->aCol[1].zColl); 118 } 119 120 Expr expr; 121 122 void f4(Expr *p) { 123 __builtin_printf("%i: p->y.pTab->aCol[1].zColl %s\n", __LINE__, p->y.pTab->aCol[1].zColl); 124 } 125 126 // const char *zColl = p->y.pTab->aCol[j].zColl; 127 128 int main() { 129 Column c; 130 c.zColl = "foo"; 131 f1(c); 132 Column *cols = __builtin_malloc(3*sizeof(Column)); 133 cols[1] = c; 134 f2(cols); 135 table.aCol = cols; 136 f3(pTab); 137 expr.y.pTab = pTab; 138 f4(&expr); 139 }